1.1 --- a/test_files/programs/Makefile Sun May 26 22:17:39 2024 +0200
1.2 +++ b/test_files/programs/Makefile Sun May 26 22:18:20 2024 +0200
1.3 @@ -1,7 +1,7 @@
1.4 PKGDIR ?= ..
1.5 L4DIR ?= $(PKGDIR)/../../..
1.6
1.7 -TARGET = cat clip dstest_exec_payload ls test_systemv
1.8 +TARGET = cat clip dstest_exec_payload ls test_popenv test_systemv
1.9
1.10 MODE = static_newlib
1.11
1.12 @@ -13,6 +13,8 @@
1.13
1.14 SRC_C_ls = ls.c
1.15
1.16 +SRC_C_test_popenv = test_popenv.c
1.17 +
1.18 SRC_C_test_systemv = test_systemv.c
1.19
1.20 REQUIRES_LIBS = libe2access
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/test_files/programs/test_popenv.c Sun May 26 22:18:20 2024 +0200
2.3 @@ -0,0 +1,83 @@
2.4 +/*
2.5 + * Run a program using the supplied arguments.
2.6 + *
2.7 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
2.8 + *
2.9 + * This program is free software; you can redistribute it and/or
2.10 + * modify it under the terms of the GNU General Public License as
2.11 + * published by the Free Software Foundation; either version 2 of
2.12 + * the License, or (at your option) any later version.
2.13 + *
2.14 + * This program is distributed in the hope that it will be useful,
2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 + * GNU General Public License for more details.
2.18 + *
2.19 + * You should have received a copy of the GNU General Public License
2.20 + * along with this program; if not, write to the Free Software
2.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
2.22 + * Boston, MA 02110-1301, USA
2.23 + */
2.24 +
2.25 +#include <stdio.h>
2.26 +#include <sys/types.h>
2.27 +#include <errno.h>
2.28 +
2.29 +/* NOTE: To be provided via a header. */
2.30 +
2.31 +extern pid_t popenv(int, const char *[], FILE **input, FILE **output, FILE **error);
2.32 +
2.33 +
2.34 +
2.35 +/* Transfer size for communication. */
2.36 +
2.37 +static const offset_t TO_TRANSFER = 1024;
2.38 +
2.39 +
2.40 +
2.41 +/* List objects in the filesystem image. */
2.42 +
2.43 +int main(int argc, char *argv[])
2.44 +{
2.45 + FILE *input, *output, *error;
2.46 + pid_t pid;
2.47 + char buffer[TO_TRANSFER];
2.48 + size_t nread;
2.49 +
2.50 + if (argc < 2)
2.51 + {
2.52 + printf("Usage: test_popenv <program> <argument>...\n");
2.53 + return 1;
2.54 + }
2.55 +
2.56 + printf("Running: %s\n", argv[1]);
2.57 +
2.58 + pid = popenv(argc - 1, (const char **) argv + 1, &input, &output, &error);
2.59 +
2.60 + if (pid == -1)
2.61 + {
2.62 + printf("Error: %d\n", errno);
2.63 + return 1;
2.64 + }
2.65 +
2.66 + printf("Process: %d\n", pid);
2.67 +
2.68 + /* Wait for events on the streams and the process.
2.69 + NOTE: Currently just reading from the process. */
2.70 +
2.71 + while ((nread = fread(buffer, sizeof(char), TO_TRANSFER, output)))
2.72 + {
2.73 + if (!fwrite(buffer, sizeof(char), nread, stdout))
2.74 + break;
2.75 + }
2.76 +
2.77 + fclose(input);
2.78 + fclose(output);
2.79 +
2.80 + /* NOTE: Error not yet used. */
2.81 +
2.82 + return 0;
2.83 +}
2.84 +
2.85 +/* vim: tabstop=4 expandtab shiftwidth=4
2.86 +*/