# HG changeset patch # User Paul Boddie # Date 1702405209 -3600 # Node ID d3a47186d0d9c3721a82af4166405f8cdd9eb018 # Parent 02161499be5d1ad9bd955ba293587d7470eefb17 Simplified the example by using a blocking pipe and waiting function. diff -r 02161499be5d -r d3a47186d0d9 tests/dstest_exec.cc --- a/tests/dstest_exec.cc Tue Dec 12 19:16:58 2023 +0100 +++ b/tests/dstest_exec.cc Tue Dec 12 19:20:09 2023 +0100 @@ -44,13 +44,9 @@ file_t *reader, *writer; long err; - /* Obtain the common notifier. */ - - notifier_t *notifier = client_notifier_task(); - /* Create a pipe for process output. */ - err = client_pipe(&reader, &writer, O_NONBLOCK); + err = client_pipe(&reader, &writer, 0); if (err) { @@ -58,14 +54,6 @@ return err; } - err = client_subscribe(reader, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED, notifier); - - if (err) - { - printf("Could not subscribe to pipe notifications: %s\n", l4sys_errtostr(err)); - return err; - } - /* Start the process. */ err = process_spawn(argc, argv, writer, &process); @@ -82,59 +70,30 @@ client_close(writer); - /* Wait for a signal from the process or input from the process. */ - - err = notify_subscribe(process_notifiable(process), NOTIFY_TASK_ALL, notifier); + /* Read until the pipe yields no more data. */ - if (err) - { - printf("Could not subscribe to task notifications: %s\n", l4sys_errtostr(err)); - return err; - } - - notifiable_t *notifiable; + char buffer[TO_TRANSFER]; while (1) { - err = notify_wait_many(¬ifiable, notifier); - - if (err) - { - printf("Could not wait for process: %s\n", l4sys_errtostr(err)); - return err; - } - - /* Handle any signal. */ - - if (notifiable == process_notifiable(process)) - break; + offset_t nread = client_read(reader, buffer, TO_TRANSFER); - /* Handle any input. */ - - else if (notifiable == file_notifiable(reader)) - { - char buffer[TO_TRANSFER]; - offset_t nread = client_read(reader, buffer, TO_TRANSFER); - - while (nread) - { - fwrite(buffer, sizeof(char), nread, stdout); - nread = client_read(reader, buffer, TO_TRANSFER); - } - } + if (nread) + fwrite(buffer, sizeof(char), nread, stdout); + else + break; } - notify_flags_t flags = process_notifications(process); - notify_values_t values = process_notification_values(process); + /* Close the pipe and obtain the process state. */ + + client_close(reader); + + notify_flags_t flags; + notify_values_t values; + + err = process_wait(process, &flags, &values); printf("End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", flags, values.sig, values.val); - printf("End reader (flags %" pFMTnotify_flags "x)\n", file_notifications(reader)); - - err = process_error(process); - - client_close(reader); - process_free(process); - client_notifier_close(notifier); return err; }