// Control Connection
struct pakfire_xfer* control;
+
+ // Track the current state
+ enum {
+ PAKFIRE_JOB_STATE_INIT = 0,
+ PAKFIRE_JOB_STATE_LAUNCHED,
+ } state;
};
static int pakfire_parse_job(struct pakfire_job* job, json_object* data) {
free(job);
}
+/*
+
+*/
+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)
+ return r;
+
+ return 0;
+}
+
+static int pakfire_job_child(struct pakfire_job* job) {
+ // Fetch our PID
+ pid_t pid = getpid();
+
+ CTX_DEBUG(job->ctx, "Launched job child as PID %d\n", pid);
+
+ // XXX TODO
+ return 1;
+}
+
+/*
+ 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);
+
+ CTX_DEBUG(job->ctx, "Launching job %s\n", job_id);
+
+ // Update state
+ job->state = PAKFIRE_JOB_STATE_LAUNCHED;
+
+ // Configure child process
+ struct clone_args args = {
+ .flags = CLONE_PIDFD,
+ .exit_signal = SIGCHLD,
+ .pidfd = (long long unsigned int)&job->pidfd,
+ };
+
+ // Fork this process
+ pid = clone3(&args, sizeof(args));
+ if (pid < 0) {
+ CTX_ERROR(job->ctx, "Could not clone: %m\n");
+
+ return -errno;
+
+ // Child process
+ } else if (pid == 0) {
+ r = pakfire_job_child(job);
+ _exit(r);
+ }
+
+ return pakfire_job_parent(job);
+}
+
static int pakfire_job_recv(struct pakfire_xfer* xfer,
const char* message, const size_t size, void* data) {
// XXX TODO
// Store a reference to the control connection
job->control = pakfire_xfer_ref(xfer);
+ switch (job->state) {
+ // If the job has connected for the first time, we launch it
+ case PAKFIRE_JOB_STATE_INIT:
+ return pakfire_job_launch(job);
+
+ // Otherwise there is nothing to do
+ default:
+ break;
+ }
+
return 0;
}
return NULL;
}
-/*
-
-*/
-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)
- return r;
-
- return 0;
-}
-
-static int pakfire_job_child(struct pakfire_job* job) {
- // Fetch our PID
- pid_t pid = getpid();
-
- CTX_DEBUG(job->ctx, "Launched job child as PID %d\n", pid);
-
- // XXX TODO
- return 1;
-}
-
-/*
- Launches the job and returns the pidfd
-*/
-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);
-
- CTX_DEBUG(job->ctx, "Launching job %s\n", job_id);
-
- // Configure child process
- struct clone_args args = {
- .flags = CLONE_PIDFD,
- .exit_signal = SIGCHLD,
- .pidfd = (long long unsigned int)&job->pidfd,
- };
-
- // Fork this process
- pid = clone3(&args, sizeof(args));
- if (pid < 0) {
- CTX_ERROR(job->ctx, "Could not clone: %m\n");
-
- return -errno;
-
- // Child process
- } else if (pid == 0) {
- r = pakfire_job_child(job);
- _exit(r);
- }
-
- return pakfire_job_parent(job);
-}
-
/*
Terminates the job (if it is still running)
*/