1.1 --- a/libfsclient/lib/src/process.cc Sat Dec 09 22:12:34 2023 +0100
1.2 +++ b/libfsclient/lib/src/process.cc Sat Dec 09 22:12:58 2023 +0100
1.3 @@ -81,6 +81,20 @@
1.4 return L4_EOK;
1.5 }
1.6
1.7 +/* Discard and free the given process, similar to process_close but freeing the
1.8 + structure instead of reinitialising it. */
1.9 +
1.10 +void process_free(process_t *process)
1.11 +{
1.12 + if (process == NULL)
1.13 + return;
1.14 +
1.15 + if (l4_is_valid_cap(process->ref))
1.16 + ipc_cap_free_um(process->ref);
1.17 +
1.18 + free(process);
1.19 +}
1.20 +
1.21 /* Initialise the given process structure. */
1.22
1.23 void process_init(process_t *process)
1.24 @@ -95,6 +109,20 @@
1.25 process->notifiable.handler = NULL;
1.26 }
1.27
1.28 +/* A convenience function for creating and starting a process. */
1.29 +
1.30 +long process_spawn(int argc, const char *argv[], process_t **process)
1.31 +{
1.32 + *process = process_new();
1.33 +
1.34 + /* Start the process with the given arguments. */
1.35 +
1.36 + if (*process != NULL)
1.37 + return process_start(*process, argc, argv);
1.38 + else
1.39 + return -L4_ENOMEM;
1.40 +}
1.41 +
1.42 /* Start a process using the given arguments.
1.43 NOTE: This does not yet obtain input/output pipes. */
1.44
1.45 @@ -144,6 +172,40 @@
1.46 return err;
1.47 }
1.48
1.49 +/* A convenience function for waiting for a started process. */
1.50 +
1.51 +long process_wait(process_t *process, notify_flags_t *flags, notify_values_t *values)
1.52 +{
1.53 + /* Obtain the common notifier. */
1.54 +
1.55 + notifier_t *notifier = notify_get_task();
1.56 +
1.57 + /* Subscribe to the process for notifications. */
1.58 +
1.59 + long err = notify_subscribe(process_notifiable(process), NOTIFY_TASK_ALL, notifier);
1.60 +
1.61 + if (err)
1.62 + return err;
1.63 +
1.64 + /* Wait for a signal from the process. */
1.65 +
1.66 + err = process_notify_wait_process(process, notifier);
1.67 +
1.68 + if (err)
1.69 + return err;
1.70 +
1.71 + /* Obtain the notification flags and values. */
1.72 +
1.73 + *flags = process_notifications(process);
1.74 + *values = process_notification_values(process);
1.75 +
1.76 + /* Obtain any error, closing the process. */
1.77 +
1.78 + err = process_error(process);
1.79 + process_free(process);
1.80 + return err;
1.81 +}
1.82 +
1.83
1.84
1.85 /* Conversion to the generic notification types. */