rbb 99/04/26 08:35:20
Modified: apr/test Makefile testproc.c apr/threadproc/unix proc.c include apr_thread_proc.h docs threadproc.txt Log: Fixed create_process on UNIX, program arguments now work properly. I have also fixed the test program to reflect this change. Revision Changes Path 1.6 +2 -2 apache-apr/apr/test/Makefile Index: Makefile =================================================================== RCS file: /home/cvs/apache-apr/apr/test/Makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Makefile 1999/04/23 17:59:51 1.5 +++ Makefile 1999/04/26 15:35:17 1.6 @@ -54,10 +54,10 @@ testfile ab_apr testproc testproc: - $(CC) testproc.c $(INCLUDES) $(CFLAGS) $(LIBS) $< + $(CC) testproc.c $(INCLUDES) $(CFLAGS) $(LIBS) -o testproc $< testfile: - $(CC) testfile.c $(INCLUDES) $(CFLAGS) $(LIBS) $< + $(CC) testfile.c $(INCLUDES) $(CFLAGS) $(LIBS) -o testfile $< ab_apr: $(CC) ab_apr.c $(INCLUDES) $(CFLAGS) $(LIBS) -o ab_apr $< 1.3 +14 -3 apache-apr/apr/test/testproc.c Index: testproc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testproc.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- testproc.c 1999/04/23 20:16:03 1.2 +++ testproc.c 1999/04/26 15:35:18 1.3 @@ -60,6 +60,7 @@ #include <unistd.h> #include <stdio.h> #include <signal.h> +#include <string.h> int test_filedel(void); int testdirs(void); @@ -70,7 +71,13 @@ apr_procattr_t *attr; apr_file_t *testfile; char buf[256]; + char *args[3]; + char *teststr = "Whooo Hoooo\n"; + if (argc > 1) { + fprintf(stdout, "%s", teststr); + exit(1); + } fprintf(stdout, "Creating procattr......."); attr = apr_createprocattr_init(); if (attr == NULL) { @@ -99,9 +106,13 @@ exit(-1); } fprintf(stdout, "OK.\n"); - + + args[0] = strdup("testproc"); + args[1] = strdup("-X"); + args[2] = NULL; + fprintf(stdout, "Createing a new process......."); - if ((newproc = apr_create_process("a.out", NULL, NULL, attr)) == NULL) { + if ((newproc = apr_create_process("../testproc", args, NULL, attr)) == NULL) { fprintf(stderr, "Could not create the new process\n"); exit(-1); } @@ -116,7 +127,7 @@ fprintf(stdout, "Checking the data read from pipe to child......."); apr_read(testfile, buf, 256); - if (!strcmp(buf, "Hello, World\n")) + if (!strcmp(buf, teststr)) fprintf(stdout,"OK\n"); else fprintf(stderr, "Uh-Oh\n"); } 1.3 +18 -4 apache-apr/apr/threadproc/unix/proc.c Index: proc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/threadproc/unix/proc.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- proc.c 1999/04/23 20:16:04 1.2 +++ proc.c 1999/04/26 15:35:18 1.3 @@ -129,9 +129,11 @@ return 1; } -apr_proc_t *apr_create_process(char *progname, char *args, char **env, apr_procattr_t *attr) +apr_proc_t *apr_create_process(char *progname, char *const args[], char **env, apr_procattr_t *attr) { apr_proc_t *new = (apr_proc_t *)malloc(sizeof(apr_proc_t)); + int i; + char **newargs; if ((new->pid = fork()) < 0) { return NULL; @@ -162,12 +164,24 @@ exit(-1); /* We have big problems, the child should exit. */ } } - if (attr->cmdtype == APR_SHELLCMD) { - execle(SHELL_PATH, SHELL_PATH, "-c", args, NULL, env); + i = 0; + while (args[i]) { + i++; + } + newargs = (char **)malloc(sizeof (char *) * (i + 3)); + newargs[0] = strdup(SHELL_PATH); + newargs[1] = strdup("-c"); + i = 0; + while (args[i]) { + newargs[i + 2] = strdup(args[i]); + i++; + } + newargs[i + 3] = NULL; + execve(SHELL_PATH, newargs, env); } else { - execle(progname, args, NULL, env); + execve(progname, args, env); } exit(-1); /* if we get here, there is a problem, so exit with an */ /* error code. */ 1.2 +1 -1 apache-apr/include/apr_thread_proc.h Index: apr_thread_proc.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_thread_proc.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- apr_thread_proc.h 1999/04/23 17:59:59 1.1 +++ apr_thread_proc.h 1999/04/26 15:35:19 1.2 @@ -77,7 +77,7 @@ apr_file_t *apr_get_childerr(apr_proc_t *); apr_int32_t apr_fork(apr_proc_t *); -apr_proc_t *apr_create_process(char *, char *, char **, apr_procattr_t *); +apr_proc_t *apr_create_process(char *, char *const [], char **, apr_procattr_t *); #endif /* ! APR_FILE_IO_H */ 1.5 +2 -1 apache-apr/docs/threadproc.txt Index: threadproc.txt =================================================================== RCS file: /home/cvs/apache-apr/docs/threadproc.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- threadproc.txt 1999/04/26 13:07:53 1.4 +++ threadproc.txt 1999/04/26 15:35:20 1.5 @@ -56,7 +56,8 @@ create a new process and run a new executable in it. Arguments: arg 1) Path name of the executable file - arg 2) array of Command line arguments to executable + arg 2) array of command line arguments. The first string in the array + should be the program name to execute. arg 3) array of environment strings of the form name=value. If NULL, inherit environ from parent. arg 4) a pointer to structure that describes the attributes of the new