coredump: use a cleanup handler for destroying iovw objects

This commit is contained in:
Lennart Poettering
2023-08-10 12:10:47 +02:00
parent 85ec1b6efa
commit 6257e2fb1a
2 changed files with 8 additions and 9 deletions
+3
View File
@@ -93,6 +93,9 @@ struct iovec_wrapper {
struct iovec_wrapper *iovw_new(void);
struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw);
struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free_free);
void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
+5 -9
View File
@@ -1363,8 +1363,8 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
}
static int process_kernel(int argc, char* argv[]) {
_cleanup_(iovw_free_freep) struct iovec_wrapper *iovw = NULL;
Context context = {};
struct iovec_wrapper *iovw;
int r;
/* When we're invoked by the kernel, stdout/stderr are closed which is dangerous because the fds
@@ -1386,12 +1386,12 @@ static int process_kernel(int argc, char* argv[]) {
/* Collect all process metadata passed by the kernel through argv[] */
r = gather_pid_metadata_from_argv(iovw, &context, argc - 1, argv + 1);
if (r < 0)
goto finish;
return r;
/* Collect the rest of the process metadata retrieved from the runtime */
r = gather_pid_metadata(iovw, &context);
if (r < 0)
goto finish;
return r;
if (!context.is_journald)
/* OK, now we know it's not the journal, hence we can make use of it now. */
@@ -1409,13 +1409,9 @@ static int process_kernel(int argc, char* argv[]) {
}
if (context.is_journald || context.is_pid1)
r = submit_coredump(&context, iovw, STDIN_FILENO);
else
r = send_iovec(iovw, STDIN_FILENO);
return submit_coredump(&context, iovw, STDIN_FILENO);
finish:
iovw = iovw_free_free(iovw);
return r;
return send_iovec(iovw, STDIN_FILENO);
}
static int process_backtrace(int argc, char *argv[]) {