# HG changeset patch # User Paul Boddie # Date 1716754700 -7200 # Node ID b2d63bdb1d548b4a53cbae8f9d5a9c890e277da1 # Parent 046eef71b69d568dafd96a3f96cd1dc6e386d0d8 Added a test of a popenv (popen using a vector) C library function. diff -r 046eef71b69d -r b2d63bdb1d54 test_files/programs/Makefile --- a/test_files/programs/Makefile Sun May 26 22:17:39 2024 +0200 +++ b/test_files/programs/Makefile Sun May 26 22:18:20 2024 +0200 @@ -1,7 +1,7 @@ PKGDIR ?= .. L4DIR ?= $(PKGDIR)/../../.. -TARGET = cat clip dstest_exec_payload ls test_systemv +TARGET = cat clip dstest_exec_payload ls test_popenv test_systemv MODE = static_newlib @@ -13,6 +13,8 @@ SRC_C_ls = ls.c +SRC_C_test_popenv = test_popenv.c + SRC_C_test_systemv = test_systemv.c REQUIRES_LIBS = libe2access diff -r 046eef71b69d -r b2d63bdb1d54 test_files/programs/test_popenv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test_files/programs/test_popenv.c Sun May 26 22:18:20 2024 +0200 @@ -0,0 +1,83 @@ +/* + * Run a program using the supplied arguments. + * + * Copyright (C) 2024 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 + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include +#include +#include + +/* NOTE: To be provided via a header. */ + +extern pid_t popenv(int, const char *[], FILE **input, FILE **output, FILE **error); + + + +/* Transfer size for communication. */ + +static const offset_t TO_TRANSFER = 1024; + + + +/* List objects in the filesystem image. */ + +int main(int argc, char *argv[]) +{ + FILE *input, *output, *error; + pid_t pid; + char buffer[TO_TRANSFER]; + size_t nread; + + if (argc < 2) + { + printf("Usage: test_popenv ...\n"); + return 1; + } + + printf("Running: %s\n", argv[1]); + + pid = popenv(argc - 1, (const char **) argv + 1, &input, &output, &error); + + if (pid == -1) + { + printf("Error: %d\n", errno); + return 1; + } + + printf("Process: %d\n", pid); + + /* Wait for events on the streams and the process. + NOTE: Currently just reading from the process. */ + + while ((nread = fread(buffer, sizeof(char), TO_TRANSFER, output))) + { + if (!fwrite(buffer, sizeof(char), nread, stdout)) + break; + } + + fclose(input); + fclose(output); + + /* NOTE: Error not yet used. */ + + return 0; +} + +/* vim: tabstop=4 expandtab shiftwidth=4 +*/