summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/problem_data.c28
-rw-r--r--src/lib/report.c60
2 files changed, 41 insertions, 47 deletions
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
index 22c06ff2..87821afd 100644
--- a/src/lib/problem_data.c
+++ b/src/lib/problem_data.c
@@ -70,10 +70,9 @@ void add_basics_to_problem_data(problem_data_t *pd)
if (get_problem_item_content_or_NULL(pd, FILENAME_DUPHASH) == NULL)
{
/* start hash */
- static sha1_ctx_t sha1ctx;
- unsigned char hash_bytes[SHA1_RESULT_LEN];
- char hash_str[SHA1_RESULT_LEN*2 + 1];
+ sha1_ctx_t sha1ctx;
sha1_begin(&sha1ctx);
+
/*
* To avoid spurious hash differences, sort keys so that elements are
* always processed in the same order:
@@ -94,20 +93,13 @@ void add_basics_to_problem_data(problem_data_t *pd)
continue;
sha1_hash(&sha1ctx, item->content, strlen(item->content));
}
+ g_list_free(list);
+
/* end hash */
+ char hash_bytes[SHA1_RESULT_LEN];
sha1_end(&sha1ctx, hash_bytes);
-
- unsigned len = SHA1_RESULT_LEN;
- unsigned char *s = hash_bytes;
- char *d = hash_str;
- while (len)
- {
- *d++ = "0123456789abcdef"[*s >> 4];
- *d++ = "0123456789abcdef"[*s & 0xf];
- s++;
- len--;
- }
- *d = '\0';
+ char hash_str[SHA1_RESULT_LEN*2 + 1];
+ bin2hex(hash_str, hash_bytes, SHA1_RESULT_LEN)[0] = '\0';
add_to_problem_data(pd, FILENAME_DUPHASH, hash_str);
}
@@ -121,7 +113,7 @@ void add_basics_to_problem_data(problem_data_t *pd)
if (read > 0)
{
buf[read] = 0;
- VERB2 log("reporting initiated from: %s\n", buf);
+ VERB2 log("reporting initiated from: %s", buf);
add_to_problem_data(pd, FILENAME_EXECUTABLE, buf);
}
free(exe);
@@ -130,11 +122,11 @@ void add_basics_to_problem_data(problem_data_t *pd)
/* FIXME: component should be taken from rpm using librpm
* which means we need to link against it :(
* or run rpm -qf executable ??
- */
+ */
/* Fedora/RHEL rpm specific piece of code */
const char *component = get_problem_item_content_or_NULL(pd, FILENAME_COMPONENT);
//FIXME: this REALLY needs to go away, or every report will be assigned to abrt
- if(component == NULL) // application didn't specify component
+ if (component == NULL) // application didn't specify component
add_to_problem_data(pd, FILENAME_COMPONENT, "abrt");
//#endif
}
diff --git a/src/lib/report.c b/src/lib/report.c
index d6b45fcf..99a3f919 100644
--- a/src/lib/report.c
+++ b/src/lib/report.c
@@ -30,7 +30,13 @@ static int run_reporter_ui(char **args, int flags)
*/
pid_t pid = vfork();
- if (pid == 0)
+ if (pid < 0) /* error */
+ {
+ perror_msg("vfork");
+ return -1;
+ }
+
+ if (pid == 0) /* child */
{
/* Some callers set SIGCHLD to SIG_IGN.
* However, reporting spawns child processes.
@@ -47,31 +53,29 @@ static int run_reporter_ui(char **args, int flags)
*/
path = "bug-reporting-wizard";
execvp(path, args);
- perror_msg_and_die("Can't execute %s", "bug-reporting-wizard");
+ perror_msg_and_die("Can't execute %s", path);
}
- else if(pid > 0)
+
+ /* parent */
+ if (flags & LIBREPORT_WAIT)
{
- if (flags & WAIT)
+ int status;
+ pid_t p = waitpid(pid, &status, 0);
+ if (p <= 0)
{
- int status;
- pid_t p = waitpid(pid, &status, 0);
- if(p <= 0)
- {
- perror_msg("can't waitpid");
- return EXIT_FAILURE;
- }
- if (WIFEXITED(status))
- {
- VERB2 log("reporting finished with exitcode: status=%d\n", WEXITSTATUS(status));
- return WEXITSTATUS(status);
- }
- else // (WIFSIGNALED(status))
- {
- VERB2 log("reporting killed by signal %d\n", WTERMSIG(status));
- return WTERMSIG(status) + 128;
- }
+ perror_msg("can't waitpid");
+ return -1;
}
+ if (WIFEXITED(status))
+ {
+ VERB2 log("reporting finished with exitcode %d", WEXITSTATUS(status));
+ return WEXITSTATUS(status);
+ }
+ /* child died from a signal: WIFSIGNALED(status) should be true */
+ VERB2 log("reporting killed by signal %d", WTERMSIG(status));
+ return WTERMSIG(status) + 128;
}
+
return 0;
}
@@ -84,8 +88,7 @@ int analyze_and_report_dir(const char* dirname, int flags)
args[2] = (char *)dirname;
args[3] = NULL;
- run_reporter_ui(args, flags);
- return 0;
+ return run_reporter_ui(args, flags);
}
/* analyzes AND reports a problem saved on disk
@@ -99,14 +102,14 @@ int analyze_and_report(problem_data_t *pd, int flags)
return -1;
char *dir_name = xstrdup(dd->dd_dirname);
dd_close(dd);
- VERB2 log("Temp problem dir: '%s'\n", dir_name);
+ VERB2 log("Temp problem dir: '%s'", dir_name);
result = analyze_and_report_dir(dir_name, flags);
/* if we wait for reporter to finish, we can clean the tmp dir
* and we should reload the problem data, so caller doesn't see the stalled
* data
*/
- if (flags & WAIT)
+ if (flags & LIBREPORT_WAIT)
{
g_hash_table_remove_all(pd);
dd = dd_opendir(dir_name, 0);
@@ -138,9 +141,8 @@ int report_dir(const char* dirname)
args[3] = (char *)dirname;
args[4] = NULL;
- int flags = WAIT;
- int status;
- status = run_reporter_ui(args, flags);
+ int flags = LIBREPORT_WAIT;
+ int status = run_reporter_ui(args, flags);
return status;
}
@@ -158,7 +160,7 @@ int report(problem_data_t *pd)
dd_create_basic_files(dd, getuid());
char *dir_name = xstrdup(dd->dd_dirname);
dd_close(dd);
- VERB2 log("Temp problem dir: '%s'\n", dir_name);
+ VERB2 log("Temp problem dir: '%s'", dir_name);
int result = report_dir(dir_name);
/* here we always wait for reporter to finish, we can clean the tmp dir