# HG changeset patch # User Paul Boddie # Date 1678664416 -3600 # Node ID 7f39fb2e0f381fd4a6aae97d3f6a57a50f33dc7b # Parent 4291b6876e47b5035bbf72141fd9e043cf5ddfd0 Expanded the execution test payload to test filesystem access. diff -r 4291b6876e47 -r 7f39fb2e0f38 conf/dstest_exec.cfg --- a/conf/dstest_exec.cfg Fri Mar 10 18:54:41 2023 +0100 +++ b/conf/dstest_exec.cfg Mon Mar 13 00:40:16 2023 +0100 @@ -59,4 +59,4 @@ }, log = { "client", "g" }, }, - "rom/dstest_exec", "home/paulb/dstest_exec_payload", "hello", "world"); + "rom/dstest_exec", "home/paulb/dstest_exec_payload", "home/paulb/LICENCE.txt", "21"); diff -r 4291b6876e47 -r 7f39fb2e0f38 test_files/Control --- a/test_files/Control Fri Mar 10 18:54:41 2023 +0100 +++ b/test_files/Control Mon Mar 13 00:40:16 2023 +0100 @@ -1,3 +1,3 @@ provides: fstest_files -requires: libc libstdc++ libexec libipc +requires: libc libstdc++ libexec libfsclient libsystypes l4re_c-util maintainer: paul@boddie.org.uk diff -r 4291b6876e47 -r 7f39fb2e0f38 test_files/programs/Makefile --- a/test_files/programs/Makefile Fri Mar 10 18:54:41 2023 +0100 +++ b/test_files/programs/Makefile Mon Mar 13 00:40:16 2023 +0100 @@ -7,6 +7,6 @@ SRC_C_dstest_exec_payload = dstest_exec_payload.c -REQUIRES_LIBS = libc +REQUIRES_LIBS = libc libfsclient l4re_c-util libsystypes include $(L4DIR)/mk/prog.mk diff -r 4291b6876e47 -r 7f39fb2e0f38 test_files/programs/dstest_exec_payload.c --- a/test_files/programs/dstest_exec_payload.c Fri Mar 10 18:54:41 2023 +0100 +++ b/test_files/programs/dstest_exec_payload.c Mon Mar 13 00:40:16 2023 +0100 @@ -1,7 +1,7 @@ /* * A test of executing code in a new task. * - * Copyright (C) 2022 Paul Boddie + * Copyright (C) 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -19,19 +19,152 @@ * Boston, MA 02110-1301, USA */ +#include +#include + #include +#include +#include + +#include +#include +#include + + + +/* Read a line from the file. */ + +static int readline(file_t *file, int *lineno, char **start, char **end) +{ + static char buf[256]; + static offset_t current = 0, limit = 0; + char *newline = NULL; + + do + { + /* Obtain file content. */ + + if (!limit) + { + limit = client_read(file, buf, 256); + + if (!limit) + { + *start = NULL; + *end = NULL; + return 0; + } + + current = 0; + + /* Start of line at start of buffer. */ + + if (newline != NULL) + { + current += 1; + *start = buf; + *end = (char *) memchr(buf + current, (int) '\n', limit - current); + + if (*end == NULL) + *end = buf + limit; + + return 1; + } + } + + /* Find newline. */ + + newline = (char *) memchr(buf + current, (int) '\n', limit); + + if (newline != NULL) + { + (*lineno)++; + current = newline - (char *) buf + 1; + + /* Start of line before end of buffer. */ + + if (current < limit) + { + *start = newline + 1; + *end = (char *) memchr(buf + current, (int) '\n', limit - current); + + if (*end == NULL) + *end = buf + limit; + + return 1; + } + + /* Otherwise, reset the buffer to read the start of line. */ + + else + limit = 0; + } + + /* No newline: read more data. */ + + else + limit = 0; + } + while (1); +} int main(int argc, char *argv[]) { - int i; + file_t *file; + int i, lineno; + char *start, *end; printf("Hello from %s (%d)!\n", argc > 0 ? argv[0] : "exec_payload.c", argc); for (i = 0; i < argc; i++) printf("Arg #%d: %s\n", i, argv[i]); + if (argc < 2) + return 1; + + printf("Filesystem is %lx\n", l4re_env_get_cap(ENV_FILESYSTEM_SERVER_NAME)); + printf("Opening file %s...\n", argv[1]); + + file = client_open(argv[1], O_RDONLY); + + if (!client_opened(file)) + { + if (file != NULL) + printf("Error: %s\n", l4sys_errtostr(file->error)); + else + printf("Could not open file.\n"); + + while (1); + } + + lineno = atoi(argv[2]); + + printf("Finding line %d...\n", lineno); + + i = 1; + while (i < lineno) + if (!readline(file, &i, &start, &end)) + break; + + printf("Showing line %d...\n", lineno); + + while (i == lineno) + { + fwrite(start, sizeof(char), end - start, stdout); + if (!readline(file, &i, &start, &end)) + break; + } + + fputs("\n\n", stdout); + + printf("Closing file...\n"); + + client_close(file); + client_notifier_close(client_notifier_task()); + + printf("Terminating.\n"); return 0; }