From 18fe941f9d8b540aed41a6664b5797426770f1f7 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 21 Apr 2002 12:47:08 +0000 Subject: [PATCH] Fix job pipes problems - 1.2 tree now passes "make check" tests... Add additional debug2 messages to track pipe usage. Also stop jobs and browsing on scheduler shutdown. Use strace, if available, to provide a system call trace in the test report. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@2341 7a7537e8-13f0-0310-91df-b6672ffda945 --- scheduler/client.c | 19 ++++++------- scheduler/ipp.c | 7 +++-- scheduler/job.c | 62 +++++++++++++++++++++++++++++++++---------- scheduler/listen.c | 19 ++++++++++--- scheduler/main.c | 6 +++-- test/run-stp-tests.sh | 16 +++++++++-- 6 files changed, 96 insertions(+), 33 deletions(-) diff --git a/scheduler/client.c b/scheduler/client.c index b2752dfa7..4740aa29b 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -1,5 +1,5 @@ /* - * "$Id: client.c,v 1.91.2.8 2002/04/20 21:05:13 mike Exp $" + * "$Id: client.c,v 1.91.2.9 2002/04/21 12:47:03 mike Exp $" * * Client routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -79,6 +79,7 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ int val; /* Parameter value */ client_t *con; /* New client pointer */ const struct hostent *host; /* Host entry for address */ + char *hostname;/* Hostname for address */ http_addr_t temp; /* Temporary address variable */ @@ -123,11 +124,11 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ con->http.hostaddr.ipv4.sin_port = lis->address.ipv4.sin_port; if (HostNameLookups) - host = httpAddrLookup(&(con->http.hostaddr), con->http.hostname, - sizeof(con->http.hostname)); + hostname = httpAddrLookup(&(con->http.hostaddr), con->http.hostname, + sizeof(con->http.hostname)); else { - host = NULL; + hostname = NULL; httpAddrString(&(con->http.hostaddr), con->http.hostname, sizeof(con->http.hostname)); } @@ -141,7 +142,7 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ strncpy(con->http.hostname, ServerName, sizeof(con->http.hostname) - 1); } - if (host == NULL && HostNameLookups == 2) + if (hostname == NULL && HostNameLookups == 2) { /* * Can't have an unresolved IP address with double-lookups enabled... @@ -224,11 +225,11 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ #ifdef AF_INET6 if (con->http.hostaddr.addr.sa_family == AF_INET6) - LogMessage(L_DEBUG, "AcceptClient() %d from %s:%d.", con->http.fd, + LogMessage(L_DEBUG, "AcceptClient: %d from %s:%d.", con->http.fd, con->http.hostname, ntohs(con->http.hostaddr.ipv6.sin6_port)); else #endif /* AF_INET6 */ - LogMessage(L_DEBUG, "AcceptClient() %d from %s:%d.", con->http.fd, + LogMessage(L_DEBUG, "AcceptClient: %d from %s:%d.", con->http.fd, con->http.hostname, ntohs(con->http.hostaddr.ipv4.sin_port)); /* @@ -247,7 +248,7 @@ AcceptClient(listener_t *lis) /* I - Listener socket */ fcntl(con->http.fd, F_SETFD, fcntl(con->http.fd, F_GETFD) | FD_CLOEXEC); - LogMessage(L_DEBUG2, "AcceptClient() Adding fd %d to InputSet...", + LogMessage(L_DEBUG2, "AcceptClient: Adding fd %d to InputSet...", con->http.fd); FD_SET(con->http.fd, &InputSet); @@ -2521,5 +2522,5 @@ pipe_command(client_t *con, /* I - Client connection */ /* - * End of "$Id: client.c,v 1.91.2.8 2002/04/20 21:05:13 mike Exp $". + * End of "$Id: client.c,v 1.91.2.9 2002/04/21 12:47:03 mike Exp $". */ diff --git a/scheduler/ipp.c b/scheduler/ipp.c index 247216597..ac740e132 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c,v 1.127.2.10 2002/03/22 15:47:28 mike Exp $" + * "$Id: ipp.c,v 1.127.2.11 2002/04/21 12:47:03 mike Exp $" * * IPP routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -432,6 +432,9 @@ ProcessIPPRequest(client_t *con) /* I - Client connection */ httpPrintf(HTTP(con), "Content-Length: %d\r\n\r\n", con->http.data_remaining); + LogMessage(L_DEBUG2, "ProcessIPPRequest: Adding fd %d to OutputSet...", + con->http.fd); + FD_SET(con->http.fd, &OutputSet); } @@ -5684,5 +5687,5 @@ validate_user(client_t *con, /* I - Client connection */ /* - * End of "$Id: ipp.c,v 1.127.2.10 2002/03/22 15:47:28 mike Exp $". + * End of "$Id: ipp.c,v 1.127.2.11 2002/04/21 12:47:03 mike Exp $". */ diff --git a/scheduler/job.c b/scheduler/job.c index 87bfeaad2..2e89397b6 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1,5 +1,5 @@ /* - * "$Id: job.c,v 1.124.2.13 2002/04/20 21:05:13 mike Exp $" + * "$Id: job.c,v 1.124.2.14 2002/04/21 12:47:05 mike Exp $" * * Job management routines for the Common UNIX Printing System (CUPS). * @@ -85,8 +85,14 @@ AddJob(int priority, /* I - Job priority */ job = calloc(sizeof(job_t), 1); - job->id = NextJobId ++; - job->priority = priority; + job->id = NextJobId ++; + job->priority = priority; + job->back_pipes[0] = -1; + job->back_pipes[1] = -1; + job->print_pipes[0] = -1; + job->print_pipes[1] = -1; + job->status_pipe = -1; + strncpy(job->dest, dest, sizeof(job->dest) - 1); NumJobs ++; @@ -1516,6 +1522,8 @@ StartJob(int id, /* I - Job ID */ classification[0] = '\0'; if (getenv("LD_LIBRARY_PATH") != NULL) snprintf(ldpath, sizeof(ldpath), "LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH")); + else if (getenv("DYLD_LIBRARY_PATH") != NULL) + snprintf(ldpath, sizeof(ldpath), "DYLD_LIBRARY_PATH=%s", getenv("DYLD_LIBRARY_PATH")); else ldpath[0] = '\0'; @@ -1580,7 +1588,7 @@ StartJob(int id, /* I - Job ID */ return; } - LogMessage(L_DEBUG, "StartJob: statusfds = %d, %d", + LogMessage(L_DEBUG, "StartJob: statusfds = [ %d %d ]", statusfds[0], statusfds[1]); current->status_pipe = statusfds[0]; @@ -1590,7 +1598,7 @@ StartJob(int id, /* I - Job ID */ filterfds[1][0] = open("/dev/null", O_RDONLY); filterfds[1][1] = -1; - LogMessage(L_DEBUG, "StartJob: filterfds[%d] = %d, %d", 1, filterfds[1][0], + LogMessage(L_DEBUG, "StartJob: filterfds[%d] = [ %d %d ]", 1, filterfds[1][0], filterfds[1][1]); for (i = 0, slot = 0; i < num_filters; i ++) @@ -1608,7 +1616,7 @@ StartJob(int id, /* I - Job ID */ pipe(filterfds[slot]); else { - if (current->current_file == 0) + if (current->current_file == 1) { if (strncmp(printer->device_uri, "file:", 5) != 0) pipe(current->print_pipes); @@ -1622,6 +1630,9 @@ StartJob(int id, /* I - Job ID */ current->print_pipes[1] = open(printer->device_uri + 5, O_WRONLY | O_CREAT | O_TRUNC, 0600); } + + LogMessage(L_DEBUG2, "StartJob: print_pipes = [ %d %d ]", + current->print_pipes[0], current->print_pipes[1]); } filterfds[slot][0] = current->print_pipes[0]; @@ -1629,13 +1640,16 @@ StartJob(int id, /* I - Job ID */ } LogMessage(L_DEBUG, "StartJob: filter = \"%s\"", command); - LogMessage(L_DEBUG, "StartJob: filterfds[%d] = %d, %d", + LogMessage(L_DEBUG, "StartJob: filterfds[%d] = [ %d %d ]", slot, filterfds[slot][0], filterfds[slot][1]); pid = start_process(command, argv, envp, filterfds[!slot][0], filterfds[slot][1], statusfds[1], current->back_pipes[0], 0); + LogMessage(L_DEBUG2, "StartJob: Closing filter pipes for slot %d [ %d %d ]...", + !slot, filterfds[!slot][0], filterfds[!slot][1]); + close(filterfds[!slot][0]); close(filterfds[!slot][1]); @@ -1667,7 +1681,7 @@ StartJob(int id, /* I - Job ID */ if (strncmp(printer->device_uri, "file:", 5) != 0) { - if (current->current_file == 0) + if (current->current_file == 1) { sscanf(printer->device_uri, "%254[^:]", method); snprintf(command, sizeof(command), "%s/backend/%s", ServerBin, method); @@ -1678,7 +1692,7 @@ StartJob(int id, /* I - Job ID */ filterfds[slot][1] = open("/dev/null", O_WRONLY); LogMessage(L_DEBUG, "StartJob: backend = \"%s\"", command); - LogMessage(L_DEBUG, "StartJob: filterfds[%d] = %d, %d", + LogMessage(L_DEBUG, "StartJob: filterfds[%d] = [ %d %d ]", slot, filterfds[slot][0], filterfds[slot][1]); pid = start_process(command, argv, envp, filterfds[!slot][0], @@ -1749,14 +1763,26 @@ StartJob(int id, /* I - Job ID */ if (current->current_file == current->num_files) { - close(filterfds[!slot][0]); - close(filterfds[!slot][1]); + LogMessage(L_DEBUG2, "StartJob: Closing print pipes [ %d %d ]...", + current->print_pipes[0], current->print_pipes[1]); + + close(current->print_pipes[0]); + close(current->print_pipes[1]); + + current->print_pipes[0] = -1; + current->print_pipes[1] = -1; } } + LogMessage(L_DEBUG2, "StartJob: Closing filter pipes for slot %d [ %d %d ]...", + slot, filterfds[slot][0], filterfds[slot][1]); + close(filterfds[slot][0]); close(filterfds[slot][1]); + LogMessage(L_DEBUG2, "StartJob: Closing status output pipe %d...", + statusfds[1]); + close(statusfds[1]); LogMessage(L_DEBUG2, "StartJob: Adding fd %d to InputSet...", @@ -1862,10 +1888,14 @@ StopJob(int id, /* I - Job ID */ * Close the pipe and clear the input bit. */ + LogMessage(L_DEBUG2, "StopJob: Closing status input pipe %d...", + current->status_pipe); + + close(current->status_pipe); + LogMessage(L_DEBUG2, "StopJob: Removing fd %d from InputSet...", current->status_pipe); - close(current->status_pipe); FD_CLR(current->status_pipe, &InputSet); current->status_pipe = -1; } @@ -2065,10 +2095,14 @@ UpdateJob(job_t *job) /* I - Job to check */ * Close the pipe and clear the input bit. */ + LogMessage(L_DEBUG2, "UpdateJob: Closing status input pipe %d...", + job->status_pipe); + + close(job->status_pipe); + LogMessage(L_DEBUG2, "UpdateJob: Removing fd %d from InputSet...", job->status_pipe); - close(job->status_pipe); FD_CLR(job->status_pipe, &InputSet); job->status_pipe = -1; } @@ -2259,5 +2293,5 @@ start_process(const char *command, /* I - Full path to command */ /* - * End of "$Id: job.c,v 1.124.2.13 2002/04/20 21:05:13 mike Exp $". + * End of "$Id: job.c,v 1.124.2.14 2002/04/21 12:47:05 mike Exp $". */ diff --git a/scheduler/listen.c b/scheduler/listen.c index 4f37d2256..a06576709 100644 --- a/scheduler/listen.c +++ b/scheduler/listen.c @@ -1,5 +1,5 @@ /* - * "$Id: listen.c,v 1.9.2.4 2002/01/27 21:20:32 mike Exp $" + * "$Id: listen.c,v 1.9.2.5 2002/04/21 12:47:07 mike Exp $" * * Server listening routines for the Common UNIX Printing System (CUPS) * scheduler. @@ -54,10 +54,15 @@ PauseListening(void) if (NumClients == MaxClients) LogMessage(L_WARN, "Max clients reached, holding new connections..."); - LogMessage(L_DEBUG, "PauseListening: clearing input bits..."); + LogMessage(L_DEBUG, "PauseListening: Clearing input bits..."); for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++) + { + LogMessage(L_DEBUG2, "PauseListening: Removing fd %d from InputSet...", + lis->fd); + FD_CLR(lis->fd, &InputSet); + } } @@ -78,10 +83,14 @@ ResumeListening(void) if (NumClients >= (MaxClients - 1)) LogMessage(L_WARN, "Resuming new connection processing..."); - LogMessage(L_DEBUG, "ResumeListening: setting input bits..."); + LogMessage(L_DEBUG, "ResumeListening: Setting input bits..."); for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++) + { + LogMessage(L_DEBUG2, "ResumeListening: Adding fd %d to InputSet...", + lis->fd); FD_SET(lis->fd, &InputSet); + } } @@ -151,6 +160,8 @@ StartListening(void) exit(errno); } + LogMessage(L_DEBUG2, "StartListening: fd=%d", lis->fd); + fcntl(lis->fd, F_SETFD, fcntl(lis->fd, F_GETFD) | FD_CLOEXEC); /* @@ -216,5 +227,5 @@ StopListening(void) /* - * End of "$Id: listen.c,v 1.9.2.4 2002/01/27 21:20:32 mike Exp $". + * End of "$Id: listen.c,v 1.9.2.5 2002/04/21 12:47:07 mike Exp $". */ diff --git a/scheduler/main.c b/scheduler/main.c index 9e37c949d..35ba4bc92 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1,5 +1,5 @@ /* - * "$Id: main.c,v 1.57.2.10 2002/04/20 21:05:16 mike Exp $" + * "$Id: main.c,v 1.57.2.11 2002/04/21 12:47:07 mike Exp $" * * Scheduler main loop for the Common UNIX Printing System (CUPS). * @@ -551,6 +551,8 @@ main(int argc, /* I - Number of command-line arguments */ * immediately. */ + StopBrowsing(); + StopAllJobs(); DeleteAllCerts(); CloseAllClients(); StopListening(); @@ -813,5 +815,5 @@ usage(void) /* - * End of "$Id: main.c,v 1.57.2.10 2002/04/20 21:05:16 mike Exp $". + * End of "$Id: main.c,v 1.57.2.11 2002/04/21 12:47:07 mike Exp $". */ diff --git a/test/run-stp-tests.sh b/test/run-stp-tests.sh index 5e8746a21..1b75b7998 100755 --- a/test/run-stp-tests.sh +++ b/test/run-stp-tests.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# "$Id: run-stp-tests.sh,v 1.4.2.4 2002/04/20 21:05:16 mike Exp $" +# "$Id: run-stp-tests.sh,v 1.4.2.5 2002/04/21 12:47:08 mike Exp $" # # Perform the complete set of IPP compliance tests specified in the # CUPS Software Test Plan. @@ -169,6 +169,11 @@ echo "Starting scheduler..." ../scheduler/cupsd -c /tmp/$user/cupsd.conf -f & cupsd=$! +if test -x /usr/bin/strace; then + # Trace system calls in cupsd if we have strace... + /usr/bin/strace -tt -o /tmp/$user/log/cupsd.trace -p $cupsd & +fi + echo "Scheduler is PID $cupsd; run debugger now if you need to." echo "" echo "Press ENTER to continue..." @@ -292,6 +297,13 @@ echo "
" >>$strfile
 cat /tmp/$user/log/page_log >>$strfile
 echo "
" >>$strfile +if test -f /tmp/$user/log/cupsd.trace; then + echo "

cupsd.trace

" >>$strfile + echo "
" >>$strfile
+	cat /tmp/$user/log/cupsd.trace >>$strfile
+	echo "
" >>$strfile +fi + # # Format the reports and tell the user where to find them... # @@ -324,5 +336,5 @@ echo " $pdffile" echo "" # -# End of "$Id: run-stp-tests.sh,v 1.4.2.4 2002/04/20 21:05:16 mike Exp $" +# End of "$Id: run-stp-tests.sh,v 1.4.2.5 2002/04/21 12:47:08 mike Exp $" # -- 2.39.5