rbb 99/05/26 06:47:04
Modified: apr/file_io/unix pipe.c readwrite.c apr/test testfile.c testproc.c testsock.c apr/threadproc/unix proc.c include apr_file_io.h apr_thread_proc.h Log: The process test works with these changes. Next up is the socket test. Revision Changes Path 1.10 +10 -7 apache-apr/apr/file_io/unix/pipe.c Index: pipe.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/pipe.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- pipe.c 1999/05/25 03:14:15 1.9 +++ pipe.c 1999/05/26 13:46:54 1.10 @@ -56,13 +56,14 @@ #include "fileio.h" #include "apr_file_io.h" #include "apr_general.h" +#include "apr_lib.h" #include <errno.h> #include <string.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> -ap_status_t ap_create_pipe(ap_context_t *cont, struct file_t *in, struct file_t *out) +ap_status_t ap_create_pipe(ap_context_t *cont, struct file_t **in, struct file_t **out) { int filedes[2]; @@ -70,13 +71,15 @@ return errno; } - in->cntxt = cont; - in->filedes = filedes[0]; - in->fname = strdup("PIPE"); + (*in) = (struct file_t *)ap_palloc(cont->pool, sizeof(struct file_t)); + (*in)->cntxt = cont; + (*in)->filedes = filedes[0]; + (*in)->fname = ap_pstrdup(cont->pool, "PIPE"); - out->cntxt = cont; - out->filedes = filedes[1]; - out->fname = strdup("PIPE"); + (*out) = (struct file_t *)ap_palloc(cont->pool, sizeof(struct file_t)); + (*out)->cntxt = cont; + (*out)->filedes = filedes[1]; + (*out)->fname = ap_pstrdup(cont->pool, "PIPE"); return APR_SUCCESS; } 1.12 +7 -6 apache-apr/apr/file_io/unix/readwrite.c Index: readwrite.c =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/readwrite.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- readwrite.c 1999/05/25 03:14:15 1.11 +++ readwrite.c 1999/05/26 13:46:55 1.12 @@ -71,7 +71,6 @@ return APR_EBADF; } - buf = ap_palloc(thefile->cntxt->pool, *nbytes); rv = read(thefile->filedes, buf, *nbytes); *nbytes = rv; @@ -90,11 +89,13 @@ rv = write(thefile->filedes, buf, *nbytes); - if (stat(thefile->fname, &info) == 0) { - thefile->size = info.st_size; - thefile->atime = info.st_atime; - thefile->mtime = info.st_mtime; - thefile->ctime = info.st_ctime; + if (strcmp(thefile->fname, "PIPE")) { + if (stat(thefile->fname, &info) == 0) { + thefile->size = info.st_size; + thefile->atime = info.st_atime; + thefile->mtime = info.st_mtime; + thefile->ctime = info.st_ctime; + } } *nbytes = rv; return APR_SUCCESS; 1.22 +1 -0 apache-apr/apr/test/testfile.c Index: testfile.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- testfile.c 1999/05/25 03:22:07 1.21 +++ testfile.c 1999/05/26 13:46:58 1.22 @@ -134,6 +134,7 @@ fprintf(stdout, "\tReading from the file......."); nbytes = (ap_ssize_t)strlen("this is a test"); + buf = (char *)ap_palloc(context->pool, nbytes + 1); if (ap_read(thefile, buf, &nbytes) != APR_SUCCESS) { perror("something's wrong"); exit(-1); 1.7 +14 -16 apache-apr/apr/test/testproc.c Index: testproc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testproc.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- testproc.c 1999/05/25 17:03:54 1.6 +++ testproc.c 1999/05/26 13:46:58 1.7 @@ -56,6 +56,7 @@ #include "apr_thread_proc.h" #include "apr_errno.h" #include "apr_general.h" +#include "apr_lib.h" #include "errno.h" #include <unistd.h> #include <stdio.h> @@ -70,21 +71,19 @@ ap_context_t *context; ap_proc_t *newproc; ap_procattr_t *attr; - ap_file_t *testfile; + ap_file_t *testfile, *f2; ap_ssize_t rv, length; + ap_status_t stat; char *buf; char *args[3]; - char *teststr = "Whooo Hoooo\n"; + char *teststr; - fprintf(stdout, "Creating context......."); - if (ap_create_context(NULL, NULL, &context) != APR_SUCCESS) { - fprintf(stderr, "Could not create context\n"); - exit(-1); - } - fprintf(stdout, "OK\n"); + ap_create_context(NULL, NULL, &context); + + teststr = ap_pstrdup(context->pool, "Whooo Hoooo\n"); if (argc > 1) { - write(STDOUT_FILENO, teststr, strlen(teststr)); + fprintf(stdout, "%s", teststr); exit(1); } fprintf(stdout, "Creating procattr......."); @@ -95,7 +94,7 @@ fprintf(stdout, "OK.\n"); fprintf(stdout, "Setting attr pipes, all three......."); - if (ap_setprocattr_io(attr, 1, 1, 1) != APR_SUCCESS) { + if (ap_setprocattr_io(attr, 1, 1, 0) != APR_SUCCESS) { fprintf(stderr, "Could not set pipes attr\n"); exit(-1); } @@ -115,10 +114,10 @@ } fprintf(stdout, "OK.\n"); - args[0] = strdup("testproc"); - args[1] = strdup("-X"); + args[0] = ap_pstrdup(context->pool, "testproc"); + args[1] = ap_pstrdup(context->pool, "-X"); args[2] = NULL; - + fprintf(stdout, "Createing a new process......."); if (ap_create_process(context, "../testproc", args, NULL, attr, &newproc) != APR_SUCCESS) { fprintf(stderr, "Could not create the new process\n"); @@ -132,12 +131,11 @@ exit(-1); } fprintf(stdout, "OK.\n"); - + length = 256; fprintf(stdout, "Checking the data read from pipe to child......."); + buf = ap_palloc(context->pool, length); if (ap_read(testfile, buf, &length) == APR_SUCCESS) { - fprintf(stdout, "%s %s\n", buf, teststr); - fprintf(stdout, "%d %d\n", strlen(buf), strlen(teststr)); if (!strcmp(buf, teststr)) fprintf(stdout,"OK\n"); else fprintf(stderr, "Uh-Oh\n"); 1.10 +7 -7 apache-apr/apr/test/testsock.c Index: testsock.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testsock.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- testsock.c 1999/05/25 17:03:54 1.9 +++ testsock.c 1999/05/26 13:46:58 1.10 @@ -74,7 +74,7 @@ fprintf(stdout, "Creating context......."); if (ap_create_context(NULL, NULL, &context) != APR_SUCCESS) { - fprintf(stderr, "Could not vreate context\n"); + fprintf(stderr, "Could not create context\n"); exit(-1); } fprintf(stdout, "OK\n"); @@ -85,18 +85,18 @@ fprintf(stdout, "server and client by yourself.\n"); fprintf(stdout, "Creating children to run network tests.......\n"); - ap_createprocattr_init(context, &attr1); - ap_createprocattr_init(context, &attr2); + s1 = ap_createprocattr_init(context, &attr1); + s2 = ap_createprocattr_init(context, &attr2); - if (attr1 == NULL || attr2 == NULL) { + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) { fprintf(stderr, "Problem creating proc attrs\n"); exit(-1); } - ap_create_process(context, "server", NULL, NULL, attr1, &proc1); - ap_create_process(context, "client", NULL, NULL, attr2, &proc2); + s1 = ap_create_process(context, "server", NULL, NULL, attr1, &proc1); + s2 = ap_create_process(context, "client", NULL, NULL, attr2, &proc2); - if (proc1 == NULL || proc2 == NULL) { + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) { fprintf(stderr, "Problem spawning new process\n"); exit(-1); } 1.14 +15 -36 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.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- proc.c 1999/05/25 17:04:02 1.13 +++ proc.c 1999/05/26 13:47:01 1.14 @@ -89,45 +89,20 @@ { ap_status_t stat; if (in) { - attr->parent_in = (ap_file_t *)ap_palloc(attr->cntxt->pool, - sizeof(ap_file_t)); - attr->child_in = (ap_file_t *)ap_palloc(attr->cntxt->pool, - sizeof(ap_file_t)); - if ((attr->parent_in == NULL) || (attr->child_in == NULL)) { - return APR_ENOMEM; - } - - if ((stat = ap_create_pipe(attr->cntxt, attr->child_in, - attr->parent_in)) != APR_SUCCESS) { + if ((stat = ap_create_pipe(attr->cntxt, &attr->child_in, + &attr->parent_in)) != APR_SUCCESS) { return stat; } } if (out) { - attr->parent_out = (ap_file_t *)ap_palloc(attr->cntxt->pool, - sizeof(ap_file_t)); - attr->child_out = (ap_file_t *)ap_palloc(attr->cntxt->pool, - sizeof(ap_file_t)); - - if ((attr->parent_out == NULL) || (attr->child_out == NULL)) { - return APR_ENOMEM; - } - - if ((stat = ap_create_pipe(attr->cntxt, attr->parent_out, - attr->child_out)) != APR_SUCCESS) { + if ((stat = ap_create_pipe(attr->cntxt, &attr->parent_out, + &attr->child_out)) != APR_SUCCESS) { return stat; } } if (err) { - attr->parent_err = (ap_file_t *)ap_palloc(attr->cntxt->pool, - sizeof(ap_file_t)); - attr->child_err = (ap_file_t *)ap_palloc(attr->cntxt->pool, - sizeof(ap_file_t)); - if ((attr->parent_err == NULL) || (attr->child_err == NULL)) { - return APR_ENOMEM; - } - - if ((stat = ap_create_pipe(attr->cntxt, attr->parent_err, - attr->child_err)) != APR_SUCCESS) { + if ((stat = ap_create_pipe(attr->cntxt, &attr->parent_err, + &attr->child_err)) != APR_SUCCESS) { return stat; } } @@ -151,20 +126,22 @@ return APR_SUCCESS; } -ap_status_t ap_fork(struct proc_t *proc) +ap_status_t ap_fork(ap_context_t *cont, struct proc_t **proc) { int pid; + + (*proc) = ap_palloc(cont->pool, sizeof(struct proc_t)); if ((pid = fork()) < 0) { return errno; } else if (pid == 0) { - proc->pid = pid; - proc->attr = NULL; + (*proc)->pid = pid; + (*proc)->attr = NULL; return APR_INCHILD; } - proc->pid = pid; - proc->attr = NULL; + (*proc)->pid = pid; + (*proc)->attr = NULL; return APR_INPARENT; } @@ -180,6 +157,8 @@ if ((*new) == NULL) { return APR_ENOMEM; } + + (*new)->cntxt = cont; if (((*new)->pid = fork()) < 0) { return errno; 1.31 +1 -1 apache-apr/include/apr_file_io.h Index: apr_file_io.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_file_io.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- apr_file_io.h 1999/05/25 03:14:20 1.30 +++ apr_file_io.h 1999/05/26 13:47:03 1.31 @@ -124,7 +124,7 @@ ap_status_t ap_make_dir(ap_context_t *, const char *, ap_fileperms_t); ap_status_t ap_remove_dir(ap_context_t *, const char *); -ap_status_t ap_create_pipe(ap_context_t *, ap_file_t *, ap_file_t *); +ap_status_t ap_create_pipe(ap_context_t *, ap_file_t **, ap_file_t **); ap_status_t ap_create_namedpipe(ap_context_t *, char *, ap_fileperms_t, char **); /*accessor and general file_io functions. */ 1.13 +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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- apr_thread_proc.h 1999/05/25 17:04:09 1.12 +++ apr_thread_proc.h 1999/05/26 13:47:03 1.13 @@ -112,7 +112,7 @@ ap_status_t ap_get_childout(ap_proc_t *, ap_file_t **); ap_status_t ap_get_childerr(ap_proc_t *, ap_file_t **); -ap_status_t ap_fork(ap_proc_t *); +ap_status_t ap_fork(ap_context_t *, ap_proc_t **); ap_status_t ap_create_process(ap_context_t *, char *, char *const [], char **, ap_procattr_t *, ap_proc_t **); ap_status_t ap_wait_proc(ap_proc_t *, ap_wait_how_e);