}
/*
- Called after a new job has been launched to register with the daemon's event loop.
+ Called after a job has exited
*/
-int pakfire_daemon_job_launched(struct pakfire_daemon* daemon,
- struct pakfire_job* job, int pidfd) {
- int r;
-
- CTX_DEBUG(daemon->ctx, "Registering job %p with PIDFD %d\n", job, pidfd);
-
- r = sd_event_add_child_pidfd(daemon->loop, NULL, pidfd,
- WEXITED, pakfire_job_exited, job);
- if (r < 0) {
- CTX_DEBUG(daemon->ctx, "Could not register the job with the event loop: %s\n", strerror(-r));
-
- return r;
- }
-
- return 0;
-}
-
-/*
- Called after a job has exited.
-*/
-int pakfire_daemon_job_exited(struct pakfire_daemon* daemon, struct pakfire_job* job) {
- CTX_DEBUG(daemon->ctx, "Deregistering job %p\n", job);
+int pakfire_daemon_job_finished(struct pakfire_daemon* daemon, struct pakfire_job* job) {
+ CTX_DEBUG(daemon->ctx, "Removing job %p\n", job);
-#if 0
for (unsigned int i = 0; i < MAX_JOBS; i++) {
if (daemon->jobs[i] != job)
continue;
break;
}
-#endif
return 0;
}
int pakfire_daemon_main(struct pakfire_daemon* daemon);
-int pakfire_daemon_job_launched(
- struct pakfire_daemon* daemon, struct pakfire_job* job, int pidfd);
-int pakfire_daemon_job_exited(
- struct pakfire_daemon* daemon, struct pakfire_job* job);
+int pakfire_daemon_job_finished(struct pakfire_daemon* daemon, struct pakfire_job* job);
#endif /* PAKFIRE_PRIVATE */
#endif /* PAKFIRE_DAEMON_H */
enum {
PAKFIRE_JOB_STATE_INIT = 0,
PAKFIRE_JOB_STATE_LAUNCHED,
+ PAKFIRE_JOB_STATE_EXITED,
+ PAKFIRE_JOB_STATE_KILLED,
} state;
};
}
/*
+ This method is triggered by SIGCHLD whenever the job exits
+*/
+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:
+ CTX_DEBUG(job->ctx, "Job %s has exited with status code %d\n",
+ job_id, si->si_status);
+
+ // Update state
+ job->state = PAKFIRE_JOB_STATE_EXITED;
+
+ break;
+
+ case CLD_KILLED:
+ CTX_ERROR(job->ctx, "Job %s has been killed by signal %d\n",
+ job_id, si->si_signo);
+
+ // Update state
+ job->state = PAKFIRE_JOB_STATE_KILLED;
+ break;
+ }
+
+ return 0;
+}
+
+/*
+ Called to initialize the parent process.
*/
static int pakfire_job_parent(struct pakfire_job* job) {
int r;
- // Tell the daemon process that the job has been launched
- r = pakfire_daemon_job_launched(job->daemon, job, job->pidfd);
- if (r < 0)
+ // Register the PID file descriptor
+ r = sd_event_add_child_pidfd(job->loop, NULL, job->pidfd, WEXITED, pakfire_job_exited, job);
+ if (r < 0) {
+ CTX_DEBUG(job->ctx, "Could not register the job with the event loop: %s\n", strerror(-r));
+
return r;
+ }
return 0;
}
return 0;
}
-
-/*
- This method is triggered by SIGCHLD whenever the job exits.
-*/
-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:
- CTX_DEBUG(job->ctx, "Job %s has exited with status code %d\n",
- job_id, si->si_status);
- break;
-
- case CLD_KILLED:
- CTX_ERROR(job->ctx, "Job %s has been killed by signal %d\n",
- job_id, si->si_signo);
- break;
- }
-
- // Let the daemon know this job has exited
- r = pakfire_daemon_job_exited(job->daemon, job);
- if (r)
- return r;
-
- return 0;
-}