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