// 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];
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;
}
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);
*/
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)) {
}
// 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;
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 {
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
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;
*/
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;
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;
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;
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)
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;
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;
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;
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);
}
// 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;