1.1 --- a/test_files/programs/dstest_exec_payload.c Sun Mar 19 00:49:19 2023 +0100
1.2 +++ b/test_files/programs/dstest_exec_payload.c Sun Mar 19 01:18:23 2023 +0100
1.3 @@ -19,151 +19,17 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <l4/re/env.h>
1.8 -#include <l4/sys/err.h>
1.9 -
1.10 #include <stdio.h>
1.11 -#include <stdlib.h>
1.12 -#include <string.h>
1.13 -
1.14 -#include <fsclient/client.h>
1.15 -#include <systypes/env.h>
1.16 -#include <systypes/fcntl.h>
1.17 -
1.18 -
1.19 -
1.20 -/* Read a line from the file. */
1.21 -
1.22 -static int readline(file_t *file, int *lineno, char **start, char **end)
1.23 -{
1.24 - static char buf[256];
1.25 - static offset_t current = 0, limit = 0;
1.26 - char *newline = NULL;
1.27 -
1.28 - do
1.29 - {
1.30 - /* Obtain file content. */
1.31 -
1.32 - if (!limit)
1.33 - {
1.34 - limit = client_read(file, buf, 256);
1.35 -
1.36 - if (!limit)
1.37 - {
1.38 - *start = NULL;
1.39 - *end = NULL;
1.40 - return 0;
1.41 - }
1.42 -
1.43 - current = 0;
1.44 -
1.45 - /* Start of line at start of buffer. */
1.46 -
1.47 - if (newline != NULL)
1.48 - {
1.49 - current += 1;
1.50 - *start = buf;
1.51 - *end = (char *) memchr(buf + current, (int) '\n', limit - current);
1.52 -
1.53 - if (*end == NULL)
1.54 - *end = buf + limit;
1.55 -
1.56 - return 1;
1.57 - }
1.58 - }
1.59 -
1.60 - /* Find newline. */
1.61 -
1.62 - newline = (char *) memchr(buf + current, (int) '\n', limit - current);
1.63 -
1.64 - if (newline != NULL)
1.65 - {
1.66 - (*lineno)++;
1.67 - current = newline - (char *) buf + 1;
1.68 -
1.69 - /* Start of line before end of buffer. */
1.70 -
1.71 - if (current < limit)
1.72 - {
1.73 - *start = newline + 1;
1.74 - *end = (char *) memchr(buf + current, (int) '\n', limit - current);
1.75 -
1.76 - if (*end == NULL)
1.77 - *end = buf + limit;
1.78 -
1.79 - return 1;
1.80 - }
1.81 -
1.82 - /* Otherwise, reset the buffer to read the start of line. */
1.83 -
1.84 - else
1.85 - limit = 0;
1.86 - }
1.87 -
1.88 - /* No newline: read more data. */
1.89 -
1.90 - else
1.91 - limit = 0;
1.92 - }
1.93 - while (1);
1.94 -}
1.95
1.96
1.97
1.98 int main(int argc, char *argv[])
1.99 {
1.100 - file_t *file;
1.101 - int i, lineno;
1.102 - char *start, *end;
1.103 -
1.104 - printf("Hello from %s (%d)!\n", argc > 0 ? argv[0] : "exec_payload.c", argc);
1.105 + int i;
1.106
1.107 for (i = 0; i < argc; i++)
1.108 printf("Arg #%d: %s\n", i, argv[i]);
1.109
1.110 - if (argc < 2)
1.111 - return 1;
1.112 -
1.113 - printf("Filesystem is %lx\n", l4re_env_get_cap(ENV_FILESYSTEM_SERVER_NAME));
1.114 - printf("Opening file %s...\n", argv[1]);
1.115 -
1.116 - file = client_open(argv[1], O_RDONLY);
1.117 -
1.118 - if (!client_opened(file))
1.119 - {
1.120 - if (file != NULL)
1.121 - printf("Error: %s\n", l4sys_errtostr(file->error));
1.122 - else
1.123 - printf("Could not open file.\n");
1.124 -
1.125 - while (1);
1.126 - }
1.127 -
1.128 - lineno = atoi(argv[2]);
1.129 -
1.130 - printf("Finding line %d...\n", lineno);
1.131 -
1.132 - i = 1;
1.133 - while (i < lineno)
1.134 - if (!readline(file, &i, &start, &end))
1.135 - break;
1.136 -
1.137 - printf("Showing line %d...\n", lineno);
1.138 -
1.139 - while (i == lineno)
1.140 - {
1.141 - fwrite(start, sizeof(char), end - start, stdout);
1.142 - if (!readline(file, &i, &start, &end))
1.143 - break;
1.144 - }
1.145 -
1.146 - fputs("\n\n", stdout);
1.147 -
1.148 - printf("Closing file...\n");
1.149 -
1.150 - client_close(file);
1.151 - client_notifier_close(client_notifier_task());
1.152 -
1.153 printf("Terminating.\n");
1.154 return 0;
1.155 }