diff options
author | Michal Toman <mtoman@redhat.com> | 2010-08-18 11:18:39 +0200 |
---|---|---|
committer | Michal Toman <mtoman@redhat.com> | 2010-08-18 11:18:39 +0200 |
commit | 4ef4bc1ba11d9c185db584ed97ce520a6306b462 (patch) | |
tree | 5b37f6ca52fd5911b7e65157b4246cc99d7f3fab /src/hooks | |
parent | e0b0da307a78b038045e2cb86934d60befd74339 (diff) | |
download | abrt-4ef4bc1ba11d9c185db584ed97ce520a6306b462.tar.gz abrt-4ef4bc1ba11d9c185db584ed97ce520a6306b462.tar.xz abrt-4ef4bc1ba11d9c185db584ed97ce520a6306b462.zip |
get rid of exceptions in CDebugDump class
Diffstat (limited to 'src/hooks')
-rw-r--r-- | src/hooks/abrt-hook-ccpp.cpp | 178 | ||||
-rw-r--r-- | src/hooks/dumpoops.cpp | 11 |
2 files changed, 94 insertions, 95 deletions
diff --git a/src/hooks/abrt-hook-ccpp.cpp b/src/hooks/abrt-hook-ccpp.cpp index e53007a4..1e469890 100644 --- a/src/hooks/abrt-hook-ccpp.cpp +++ b/src/hooks/abrt-hook-ccpp.cpp @@ -416,112 +416,112 @@ int main(int argc, char** argv) return 1; CDebugDump dd; - char *cmdline = get_cmdline(pid); /* never NULL */ - char *reason = xasprintf("Process %s was killed by signal %s (SIG%s)", executable, signal_str, signame ? signame : signal_str); - dd.Create(path, uid); - dd.SaveText(FILENAME_ANALYZER, "CCpp"); - dd.SaveText(FILENAME_EXECUTABLE, executable); - dd.SaveText(FILENAME_CMDLINE, cmdline); - dd.SaveText(FILENAME_REASON, reason); - free(cmdline); - free(reason); - - if (src_fd_binary > 0) + if (dd.Create(path, uid)) { - strcpy(path + path_len, "/"FILENAME_BINARY); - int dst_fd_binary = xopen3(path, O_WRONLY | O_CREAT | O_TRUNC, 0600); - off_t sz = copyfd_eof(src_fd_binary, dst_fd_binary, COPYFD_SPARSE); - if (sz < 0 || fsync(dst_fd_binary) != 0) + char *cmdline = get_cmdline(pid); /* never NULL */ + char *reason = xasprintf("Process %s was killed by signal %s (SIG%s)", executable, signal_str, signame ? signame : signal_str); + dd.SaveText(FILENAME_ANALYZER, "CCpp"); + dd.SaveText(FILENAME_EXECUTABLE, executable); + dd.SaveText(FILENAME_CMDLINE, cmdline); + dd.SaveText(FILENAME_REASON, reason); + free(cmdline); + free(reason); + + if (src_fd_binary > 0) { - unlink(path); - error_msg_and_die("error saving binary image to %s", path); + strcpy(path + path_len, "/"FILENAME_BINARY); + int dst_fd_binary = xopen3(path, O_WRONLY | O_CREAT | O_TRUNC, 0600); + off_t sz = copyfd_eof(src_fd_binary, dst_fd_binary, COPYFD_SPARSE); + if (sz < 0 || fsync(dst_fd_binary) != 0) + { + unlink(path); + error_msg_and_die("error saving binary image to %s", path); + } + close(dst_fd_binary); + close(src_fd_binary); } - close(dst_fd_binary); - close(src_fd_binary); - } - /* We need coredumps to be readable by all, because - * when abrt daemon processes coredump, - * process producing backtrace is run under the same UID - * as the crashed process. - * Thus 644, not 600 */ - strcpy(path + path_len, "/"FILENAME_COREDUMP); - int abrt_core_fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644); - if (abrt_core_fd < 0) - { - int sv_errno = errno; - dd.Delete(); - dd.Close(); - if (user_core_fd >= 0) + /* We need coredumps to be readable by all, because + * when abrt daemon processes coredump, + * process producing backtrace is run under the same UID + * as the crashed process. + * Thus 644, not 600 */ + strcpy(path + path_len, "/"FILENAME_COREDUMP); + int abrt_core_fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644); + if (abrt_core_fd < 0) { - xchdir(user_pwd); - unlink(core_basename); + int sv_errno = errno; + dd.Delete(); + dd.Close(); + if (user_core_fd >= 0) + { + xchdir(user_pwd); + unlink(core_basename); + } + errno = sv_errno; + perror_msg_and_die("can't open '%s'", path); } - errno = sv_errno; - perror_msg_and_die("can't open '%s'", path); - } - /* We write both coredumps at once. - * We can't write user coredump first, since it might be truncated - * and thus can't be copied and used as abrt coredump; - * and if we write abrt coredump first and then copy it as user one, - * then we have a race when process exits but coredump does not exist yet: - * $ echo -e '#include<signal.h>\nmain(){raise(SIGSEGV);}' | gcc -o test -x c - - * $ rm -f core*; ulimit -c unlimited; ./test; ls -l core* - * 21631 Segmentation fault (core dumped) ./test - * ls: cannot access core*: No such file or directory <=== BAD - */ + /* We write both coredumps at once. + * We can't write user coredump first, since it might be truncated + * and thus can't be copied and used as abrt coredump; + * and if we write abrt coredump first and then copy it as user one, + * then we have a race when process exits but coredump does not exist yet: + * $ echo -e '#include<signal.h>\nmain(){raise(SIGSEGV);}' | gcc -o test -x c - + * $ rm -f core*; ulimit -c unlimited; ./test; ls -l core* + * 21631 Segmentation fault (core dumped) ./test + * ls: cannot access core*: No such file or directory <=== BAD + */ //TODO: fchown abrt_core_fd to uid:abrt? //Currently it is owned by 0:0 but is readable by anyone, so the owner //of the crashed binary still can access it, as he has //r-x access to the dump dir. - off_t core_size = copyfd_sparse(STDIN_FILENO, abrt_core_fd, user_core_fd, ulimit_c); - if (core_size < 0 || fsync(abrt_core_fd) != 0) - { - unlink(path); - dd.Delete(); - dd.Close(); - if (user_core_fd >= 0) + off_t core_size = copyfd_sparse(STDIN_FILENO, abrt_core_fd, user_core_fd, ulimit_c); + if (core_size < 0 || fsync(abrt_core_fd) != 0) + { + unlink(path); + dd.Delete(); + dd.Close(); + if (user_core_fd >= 0) + { + xchdir(user_pwd); + unlink(core_basename); + } + /* copyfd_sparse logs the error including errno string, + * but it does not log file name */ + error_msg_and_die("error writing %s", path); + } + log("saved core dump of pid %lu (%s) to %s (%llu bytes)", (long)pid, executable, path, (long long)core_size); + if (user_core_fd >= 0 && core_size >= ulimit_c) { + /* user coredump is too big, nuke it */ xchdir(user_pwd); unlink(core_basename); } - /* copyfd_sparse logs the error including errno string, - * but it does not log file name */ - error_msg_and_die("error writing %s", path); - } - log("saved core dump of pid %lu (%s) to %s (%llu bytes)", (long)pid, executable, path, (long long)core_size); - if (user_core_fd >= 0 && core_size >= ulimit_c) - { - /* user coredump is too big, nuke it */ - xchdir(user_pwd); - unlink(core_basename); - } - /* We close dumpdir before we start catering for crash storm case. - * Otherwise, delete_debug_dump_dir's from other concurrent - * CCpp's won't be able to delete our dump (their delete_debug_dump_dir - * will wait for us), and we won't be able to delete their dumps. - * Classic deadlock. - */ - dd.Close(); - path[path_len] = '\0'; /* path now contains only directory name */ - char *newpath = xstrndup(path, path_len - (sizeof(".new")-1)); - if (rename(path, newpath) == 0) - strcpy(path, newpath); - free(newpath); - - /* rhbz#539551: "abrt going crazy when crashing process is respawned" */ - if (setting_MaxCrashReportsSize > 0) - { - trim_debug_dumps(setting_MaxCrashReportsSize, path); - } + /* We close dumpdir before we start catering for crash storm case. + * Otherwise, delete_debug_dump_dir's from other concurrent + * CCpp's won't be able to delete our dump (their delete_debug_dump_dir + * will wait for us), and we won't be able to delete their dumps. + * Classic deadlock. + */ + dd.Close(); + path[path_len] = '\0'; /* path now contains only directory name */ + char *newpath = xstrndup(path, path_len - (sizeof(".new")-1)); + if (rename(path, newpath) == 0) + strcpy(path, newpath); + free(newpath); + + /* rhbz#539551: "abrt going crazy when crashing process is respawned" */ + if (setting_MaxCrashReportsSize > 0) + { + trim_debug_dumps(setting_MaxCrashReportsSize, path); + } - return 0; - } - catch (CABRTException& e) - { - error_msg_and_die("%s", e.what()); + return 0; + } + else + xfunc_die(); } catch (std::exception& e) { diff --git a/src/hooks/dumpoops.cpp b/src/hooks/dumpoops.cpp index a2d2353a..a14fb65b 100644 --- a/src/hooks/dumpoops.cpp +++ b/src/hooks/dumpoops.cpp @@ -77,7 +77,7 @@ int main(int argc, char **argv) // const plugin_info_t *plugin_info; CPlugin* (*plugin_newf)(void); int (*scan_syslog_file)(vector_string_t& oopsList, const char *filename, time_t *last_changed_p); - void (*save_oops_to_debug_dump)(const vector_string_t& oopsList); + int (*save_oops_to_debug_dump)(const vector_string_t& oopsList); void *handle; errno = 0; @@ -110,11 +110,10 @@ int main(int argc, char **argv) } if (opt_d) { log("dumping oopses"); - try { - save_oops_to_debug_dump(oopsList); - } - catch (CABRTException& e) { - fprintf(stderr, "Error: %s\n", e.what()); + int errors = save_oops_to_debug_dump(oopsList); + if (errors > 0) + { + log("%d errors while dumping oopses", errors); return 1; } } |