From: Michael Tremer Date: Thu, 26 Jun 2025 14:23:43 +0000 (+0000) Subject: job: Write the log file in the parent process X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1e4fe660f6eeb9a24f22c84bb18b8ac5ce8e924;p=pakfire.git job: Write the log file in the parent process This should put some more things more where they belong which is in the main process. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/job.c b/src/pakfire/job.c index 9f4e541d..df3be8ff 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -245,6 +245,8 @@ static void pakfire_job_free(struct pakfire_job* job) { pakfire_log_stream_unref(job->log.stderr); if (job->log.stream) sd_event_source_unref(job->log.stream); + if (job->log.file) + pakfire_log_file_unref(job->log.file); if (job->client) pakfire_client_unref(job->client); @@ -307,6 +309,13 @@ static int pakfire_job_finished(struct pakfire_job* job, int status) { DEBUG(job->ctx, "Job %s has finished with status %d\n", job->id, status); + // Close the log file + r = pakfire_log_file_close(job->log.file); + if (r < 0) { + ERROR(job->ctx, "Could not close the log file: %s\n", strerror(-r)); + goto ERROR; + } + // Fetch the filename of the log file filename = pakfire_log_file_filename(job->log.file); if (!filename) { @@ -489,6 +498,11 @@ static int pakfire_job_exited(sd_event_source* s, const siginfo_t* si, void* dat static int pakfire_job_send_log(struct pakfire_job* job, int priority, const char* line, size_t length) { int r; + // Write everything to the log file + r = pakfire_log_file_write(job->log.file, priority, line, length); + if (r < 0) + return r; + // Enqueue the line into the buffer r = pakfire_log_buffer_enqueue(job->log.buffer, priority, line, length); if (r < 0) @@ -572,10 +586,6 @@ static void pakfire_job_log(void* data, int priority, const char* file, break; } - // Send everything but debug messages to the log file - if (likely(job->log.file)) - pakfire_log_file_write(job->log.file, priority, buffer, length); - // Pass everything to the upstream logger pakfire_ctx_log_condition(job->ctx, priority, "%s", buffer); } @@ -623,13 +633,6 @@ static int pakfire_job_child(struct pakfire_job* job) { // Setup logging pakfire_ctx_set_log_callback(ctx, pakfire_job_log, job); - // Open a new log file - r = pakfire_log_file_create(&job->log.file, ctx, NULL, job->id, PAKFIRE_LOG_FILE_COMPRESS); - if (r < 0) { - ERROR(ctx, "Could not open log file: %s\n", strerror(-r)); - goto ERROR; - } - // Disable the ccache if (!pakfire_job_has_flag(job, PAKFIRE_JOB_CCACHE)) build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE; @@ -658,21 +661,12 @@ static int pakfire_job_child(struct pakfire_job* job) { // Run the build status = pakfire_build_exec(build, job->pkg, pakfire_job_result, job); - // Close the log file - r = pakfire_log_file_close(job->log.file); - if (r < 0) { - ERROR(ctx, "Could not close the log file: %s\n", strerror(-r)); - goto ERROR; - } - // Signal that the job has finished r = pakfire_job_finished(job, status); if (r < 0) goto ERROR; ERROR: - if (job->log.file) - pakfire_log_file_unref(job->log.file); if (build) pakfire_build_unref(build); if (ctx) @@ -887,6 +881,13 @@ int pakfire_job_create(struct pakfire_job** job, struct pakfire_ctx* ctx, if (r < 0) goto ERROR; + // Open a new log file + r = pakfire_log_file_create(&j->log.file, j->ctx, NULL, j->id, PAKFIRE_LOG_FILE_COMPRESS); + if (r < 0) { + ERROR(j->ctx, "Could not open log file: %s\n", strerror(-r)); + goto ERROR; + } + // Parse the job r = pakfire_parse_job(j, data); if (r)