From: Michael Tremer Date: Thu, 30 Jan 2025 08:36:00 +0000 (+0000) Subject: job: Remove the braindead UUID parsing/unparsing X-Git-Tag: 0.9.30~286 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91ef79bfe3724995dc5f740d595a5d56c1444cf5;p=pakfire.git job: Remove the braindead UUID parsing/unparsing Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/job.c b/src/pakfire/job.c index 64caecfb..b280232e 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -59,7 +59,8 @@ struct pakfire_job { // Event Loop sd_event* loop; - uuid_t job_id; + // The ID of this job (should not be longer than a UUID) + char id[UUID_STR_LEN]; char name[NAME_MAX]; char arch[ARCH_MAX]; @@ -120,25 +121,22 @@ struct pakfire_job { static int pakfire_parse_job(struct pakfire_job* job, json_object* data) { json_object* ccache = NULL; json_object* o = NULL; - const char* s = NULL; int r; - char job_id[UUID_STR_LEN]; - // Fetch the Job ID if (!json_object_object_get_ex(data, "id", &o)) { ERROR(job->ctx, "Job does not have an ID\n"); - return -EINVAL; } - s = json_object_get_string(o); - - // Parse the Job ID - r = uuid_parse(s, job->job_id); - if (r) { - ERROR(job->ctx, "Could not parse the Job ID (%s)\n", s); + // Store the job ID + r = pakfire_string_set(job->id, json_object_get_string(o)); + if (r < 0) + return r; + // Check if we have a valid UUID + if (!pakfire_uuid_is_valid(job->id)) { + ERROR(job->ctx, "The job ID is not a valid UUID\n"); return -EINVAL; } @@ -230,11 +228,8 @@ static int pakfire_parse_job(struct pakfire_job* job, json_object* data) { DEBUG(job->ctx, "Job parsing completed\n"); - // Format the Job ID as string - uuid_unparse_lower(job->job_id, job_id); - INFO(job->ctx, "Received a new job:\n"); - INFO(job->ctx, " ID : %s\n", job_id); + INFO(job->ctx, " ID : %s\n", job->id); INFO(job->ctx, " Name : %s\n", job->name); INFO(job->ctx, " Arch : %s\n", job->arch); @@ -304,16 +299,12 @@ ERROR: */ static int pakfire_job_finished(struct pakfire_job* job, int status) { struct pakfire_xfer* xfer = NULL; - char job_id[UUID_STR_LEN]; const char* filename = NULL; const char* path = NULL; char* logfile = NULL; int r; - // Format the job ID as string - uuid_unparse(job->job_id, job_id); - - DEBUG(job->ctx, "Job %s has finished with status %d\n", job_id, status); + DEBUG(job->ctx, "Job %s has finished with status %d\n", job->id, status); // Check if we have any uploads - except for test builds if (!(job->flags & PAKFIRE_JOB_TEST)) { @@ -348,7 +339,7 @@ static int pakfire_job_finished(struct pakfire_job* job, int status) { } // Create a new xfer - r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/finished", job_id); + r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/finished", job->id); if (r < 0) goto ERROR; @@ -390,7 +381,6 @@ ERROR: static int pakfire_job_crashed(struct pakfire_job* job, const siginfo_t* si) { struct pakfire_xfer* xfer = NULL; - char job_id[UUID_STR_LEN]; int r; struct pakfire_job_log { @@ -398,9 +388,6 @@ static int pakfire_job_crashed(struct pakfire_job* job, const siginfo_t* si) { size_t length; } log = {}; - // Format the job ID as string - uuid_unparse(job->job_id, job_id); - DEBUG(job->ctx, "Sending crash report...\n"); // Dump the log @@ -409,7 +396,7 @@ static int pakfire_job_crashed(struct pakfire_job* job, const siginfo_t* si) { goto ERROR; // Create a new transfer - r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/crashed", job_id); + r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/crashed", job->id); if (r < 0) goto ERROR; @@ -505,16 +492,12 @@ ERROR: */ static int pakfire_job_exited(sd_event_source* s, const siginfo_t* si, void* data) { struct pakfire_job* job = data; - char job_id[UUID_STR_LEN]; int r; - // Format the job ID as string - uuid_unparse(job->job_id, job_id); - switch (si->si_code) { case CLD_EXITED: DEBUG(job->ctx, "Job %s has exited with status code %d\n", - job_id, si->si_status); + job->id, si->si_status); // Update state job->state = PAKFIRE_JOB_STATE_EXITED; @@ -522,7 +505,7 @@ static int pakfire_job_exited(sd_event_source* s, const siginfo_t* si, void* dat case CLD_KILLED: ERROR(job->ctx, "Job %s has been killed by signal %d\n", - job_id, si->si_signo); + job->id, si->si_signo); // Update state job->state = PAKFIRE_JOB_STATE_KILLED; @@ -636,7 +619,6 @@ static void pakfire_job_log(void* data, int priority, const char* file, static int pakfire_job_child(struct pakfire_job* job) { struct pakfire_ctx* ctx = NULL; struct pakfire_build* build = NULL; - char job_id[UUID_STR_LEN]; int build_flags = 0; int r; @@ -645,9 +627,6 @@ static int pakfire_job_child(struct pakfire_job* job) { DEBUG(job->ctx, "Launched job child as PID %d\n", pid); - // Format the job ID as string - uuid_unparse(job->job_id, job_id); - // Setup the standard output log stream r = pakfire_log_stream_in_child(job->log.stdout); if (r < 0) @@ -672,7 +651,7 @@ static int pakfire_job_child(struct pakfire_job* job) { pakfire_ctx_set_log_callback(ctx, pakfire_job_log, job); // Open a new log file - r = pakfire_log_file_create(&job->log.file, ctx, job_id, PAKFIRE_LOG_FILE_COMPRESS); + r = pakfire_log_file_create(&job->log.file, ctx, job->id, PAKFIRE_LOG_FILE_COMPRESS); if (r < 0) { ERROR(ctx, "Could not open log file: %s\n", strerror(-r)); goto ERROR; @@ -683,7 +662,7 @@ static int pakfire_job_child(struct pakfire_job* job) { build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE; // Create a new build environment - r = pakfire_build_create(&build, ctx, job->config, job->arch, job_id, build_flags); + r = pakfire_build_create(&build, ctx, job->config, job->arch, job->id, build_flags); if (r) { ERROR(ctx, "Could not setup the build environment: %m\n"); r = -errno; @@ -733,14 +712,10 @@ ERROR: Launches the job */ static int pakfire_job_launch(struct pakfire_job* job) { - char job_id[UUID_STR_LEN]; int pid; int r; - // Format the job ID as string - uuid_unparse(job->job_id, job_id); - - DEBUG(job->ctx, "Launching job %s\n", job_id); + DEBUG(job->ctx, "Launching job %s\n", job->id); // Update state job->state = PAKFIRE_JOB_STATE_LAUNCHED; @@ -980,13 +955,9 @@ static int pakfire_job_connect(sd_event_source* s, uint64_t usec, void* data) { struct pakfire_job* job = data; struct pakfire_httpclient* client = NULL; struct pakfire_xfer* xfer = NULL; - char job_id[UUID_STR_LEN]; int r; - // Format the job ID as string - uuid_unparse(job->job_id, job_id); - - INFO(job->ctx, "Connecting to job %s...\n", job_id); + INFO(job->ctx, "Connecting to job %s...\n", job->id); // Fetch a reference to the HTTP client client = pakfire_daemon_httpclient(job->daemon); @@ -996,7 +967,7 @@ static int pakfire_job_connect(sd_event_source* s, uint64_t usec, void* data) { } // Create a new xfer - r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s", job_id); + r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s", job->id); if (r) goto ERROR;