Commit 26dc8871 authored by Ryan Bloom's avatar Ryan Bloom
Browse files

Make reliable piped logs work on 2.0.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85136 13f79535-47bb-0310-9956-ffa450edef68
parent 1b0d7396
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
Apache 2.0 STATUS:
Last modified at [$Date: 2000/05/01 21:52:18 $]
Last modified at [$Date: 2000/05/04 04:02:10 $]

Release:

@@ -31,11 +31,6 @@ RELEASE SHOWSTOPPERS:
        http_connection.c and into the MPMs.
	Status:

    * Reliable piped logs look broken everywhere. Each MPM includes essentially
	identical code to ap_register_other_child(), etc. Most of this code can
	be moved out of the MPMs and into some common file (http_core.c?).
	Dean says presumably you mean an os-specific file?

    * Put back resource limit code

    * suEXEC doesn't work
+0 −40
Original line number Diff line number Diff line
@@ -130,44 +130,4 @@ void ap_start_restart(int graceful);
 */
void ap_signal_parent(ap_pool_t *p, const char* signal, const char* server_root);

#ifdef HAS_OTHER_CHILD
/*
 * register an other_child -- a child which the main loop keeps track of
 * and knows it is different than the rest of the scoreboard.
 *
 * pid is the pid of the child.
 *
 * maintenance is a function that is invoked with a reason, the data
 * pointer passed here, and when appropriate a status result from waitpid().
 *
 * write_fd is an fd that is probed for writing by select() if it is ever
 * unwritable, then maintenance is invoked with reason OC_REASON_UNWRITABLE.
 * This is useful for log pipe children, to know when they've blocked.  To
 * disable this feature, use -1 for write_fd.
 */
API_EXPORT(void) ap_register_other_child(int pid,
       void (*maintenance) (int reason, void *data, ap_wait_t status), void *data,
				      int write_fd);
#define OC_REASON_DEATH		0	/* child has died, caller must call
					 * unregister still */
#define OC_REASON_UNWRITABLE	1	/* write_fd is unwritable */
#define OC_REASON_RESTART	2	/* a restart is occuring, perform
					 * any necessary cleanup (including
					 * sending a special signal to child)
					 */
#define OC_REASON_UNREGISTER	3	/* unregister has been called, do
					 * whatever is necessary (including
					 * kill the child) */
#define OC_REASON_LOST		4	/* somehow the child exited without
					 * us knowing ... buggy os? */

/*
 * unregister an other_child.  Note that the data pointer is used here, and
 * is assumed to be unique per other_child.  This is because the pid and
 * write_fd are possibly killed off separately.
 */
API_EXPORT(void) ap_unregister_other_child(void *data);

#endif

#endif
+2 −2
Original line number Diff line number Diff line
@@ -299,7 +299,7 @@ static int call_exec(request_rec *r, char *argv0, char **env, int shellcmd)

static void cgid_maint(int reason, void *data, ap_wait_t status)
{
#ifdef HAS_OTHER_CHILD
#ifdef APR_HAS_OTHER_CHILD
    int *sd = data;
    switch (reason) {
        case OC_REASON_DEATH:
@@ -584,7 +584,7 @@ static void cgid_init(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp, server_re
            cgid_server(main_server);
            exit(-1);
        } 
#ifdef HAS_OTHER_CHILD
#ifdef APR_HAS_OTHER_CHILD
        ap_register_other_child(pid, cgid_maint, &pid, -1);
#endif
    } 
+18 −15
Original line number Diff line number Diff line
@@ -594,15 +594,12 @@ static int piped_log_spawn(piped_log *pl)
    ap_os_proc_t pid;
    ap_proc_t *procnew;

    /* pjr - calls to block and unblock alarms weren't here before, was this */
    /*       an oversight or intentional?                                    */

#ifdef SIGHUP
    ap_signal(SIGHUP, SIG_IGN);
#endif
    if ((ap_createprocattr_init(&procattr, pl->p)         != APR_SUCCESS) ||
        (ap_setprocattr_dir(procattr, pl->program)        != APR_SUCCESS) ||
        (ap_set_childin(procattr, ap_piped_log_read_fd(pl), ap_piped_log_write_fd(pl)) != APR_SUCCESS)) {
        (ap_setprocattr_childin(procattr, ap_piped_log_read_fd(pl), 
                                ap_piped_log_write_fd(pl)) != APR_SUCCESS)) {
        /* Something bad happened, give up and go away. */
	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
	    "piped_log_spawn: unable to exec '%s': %s",
@@ -610,7 +607,13 @@ static int piped_log_spawn(piped_log *pl)
        rc = -1;
    }
    else {
        rc = ap_create_process(&procnew, pl->program, NULL, NULL, procattr, pl->p);
        char **args;
        const char *pname;

        ap_tokenize_to_argv(pl->program, &args, pl->p);
        pname = ap_pstrdup(pl->p, args[0]);
 
        rc = ap_create_process(&procnew, pname, args, NULL, procattr, pl->p);
    
        if (rc == APR_SUCCESS) {            
            /* pjr - This no longer happens inside the child, */
@@ -618,13 +621,11 @@ static int piped_log_spawn(piped_log *pl)
            /*   successful that the child is running.        */
            RAISE_SIGSTOP(PIPED_LOG_SPAWN); 
            pl->pid = procnew;
            ap_get_os_proc(&pid, procnew);
            ap_register_other_child(pid, piped_log_maintenance, pl, ap_piped_log_write_fd(pl));
            ap_register_other_child(procnew, piped_log_maintenance, pl, 
                                    ap_piped_log_write_fd(pl), pl->p);
        }
    }
    
/*  ap_unblock_alarms(); */
    
    return 0;
}

@@ -634,8 +635,8 @@ static void piped_log_maintenance(int reason, void *data, ap_wait_t status)
    piped_log *pl = data;

    switch (reason) {
    case OC_REASON_DEATH:
    case OC_REASON_LOST:
    case APR_OC_REASON_DEATH:
    case APR_OC_REASON_LOST:
	pl->pid = NULL;
	ap_unregister_other_child(pl);
	if (pl->program == NULL) {
@@ -651,20 +652,20 @@ static void piped_log_maintenance(int reason, void *data, ap_wait_t status)
	}
	break;
    
    case OC_REASON_UNWRITABLE:
    case APR_OC_REASON_UNWRITABLE:
	if (pl->pid != NULL) {
	    ap_kill(pl->pid, SIGTERM);
	}
	break;
    
    case OC_REASON_RESTART:
    case APR_OC_REASON_RESTART:
	pl->program = NULL;
	if (pl->pid != NULL) {
	    ap_kill(pl->pid, SIGTERM);
	}
	break;

    case OC_REASON_UNREGISTER:
    case APR_OC_REASON_UNREGISTER:
	break;
    }
}
@@ -706,6 +707,8 @@ API_EXPORT(piped_log *) ap_open_piped_log(ap_pool_t *p, const char *program)
	errno = save_errno;
	return NULL;
    }
    ap_block_pipe(ap_piped_log_read_fd(pl));
    ap_block_pipe(ap_piped_log_write_fd(pl));
    ap_register_cleanup(p, pl, piped_log_cleanup, piped_log_cleanup_for_exec);
    if (piped_log_spawn(pl) == -1) {
	int save_errno = errno;
+2 −2
Original line number Diff line number Diff line
@@ -136,8 +136,8 @@ static void show_compile_settings(void)
#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
    printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
#endif
#ifdef HAS_OTHER_CHILD
    printf(" -D HAS_OTHER_CHILD\n");
#ifdef APR_HAS_OTHER_CHILD
    printf(" -D APR_HAS_OTHER_CHILD\n");
#endif
#ifdef HAVE_RELIABLE_PIPED_LOGS
    printf(" -D HAVE_RELIABLE_PIPED_LOGS\n");
Loading