1 /* 2 * A test of executing code in new tasks and threads. 3 * 4 * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/sys/err.h> 23 24 #include <fsclient/process.h> 25 #include <systypes/format.h> 26 27 #include <stdio.h> 28 29 30 31 int main(int argc, char *argv[]) 32 { 33 long err; 34 35 if (argc < 2) 36 { 37 printf("Need the program to run.\n"); 38 return 1; 39 } 40 41 /* Obtain the common notifier. */ 42 43 process_notifier_t *notifier = process_notify_task(); 44 45 /* Create a new process structure. */ 46 47 process_t process; 48 49 process_init(&process); 50 51 printf("Start process...\n"); 52 53 /* Start a process for the given program. */ 54 55 err = process_start(&process, argc - 1, argv + 1); 56 57 if (err) 58 { 59 printf("Could not start process: %s\n", l4sys_errtostr(err)); 60 return 1; 61 } 62 63 printf("Finished program initiation.\n"); 64 65 /* Subscribe to the process for notifications. */ 66 67 err = process_notify_subscribe(&process, NOTIFY_TASK_SIGNAL, notifier); 68 69 if (err) 70 { 71 printf("Could not subscribe to process: %s\n", l4sys_errtostr(err)); 72 return 1; 73 } 74 75 /* Wait for a signal from the process. */ 76 77 err = process_notify_wait_process(&process, notifier); 78 79 if (err) 80 { 81 printf("Could not wait for process: %s\n", l4sys_errtostr(err)); 82 return 1; 83 } 84 85 notify_flags_t flags = process_notifications(&process); 86 notify_values_t values = process_notification_values(&process); 87 88 process_close(&process); 89 90 printf("End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", flags, values.sig, values.val); 91 92 process_notify_close(notifier); 93 94 printf("End of test.\n"); 95 return 0; 96 } 97 98 /* vim: tabstop=2 expandtab shiftwidth=2 99 */