~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/threadproc/netware/procsup.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include "apr_arch_threadproc.h"
 
18
 
 
19
apr_status_t apr_proc_detach(int daemonize)
 
20
{
 
21
#if 0
 
22
    int x;
 
23
    pid_t pgrp;
 
24
 
 
25
    chdir("/");
 
26
#if !defined(MPE) && !defined(OS2) && !defined(TPF) && !defined(BEOS)
 
27
/* Don't detach for MPE because child processes can't survive the death of
 
28
   the parent. */
 
29
    if ((x = fork()) > 0)
 
30
        exit(0);
 
31
    else if (x == -1) {
 
32
        perror("fork");
 
33
        fprintf(stderr, "unable to fork new process\n");
 
34
        exit(1);  /* we can't do anything here, so just exit. */
 
35
    }
 
36
/*    RAISE_SIGSTOP(DETACH);*/
 
37
#endif
 
38
#if APR_HAVE_SETSID
 
39
    if ((pgrp = setsid()) == -1) {
 
40
        return errno;
 
41
    }
 
42
#elif defined(NEXT) || defined(NEWSOS)
 
43
    if (setpgrp(0, getpid()) == -1 || (pgrp = getpgrp(0)) == -1) {
 
44
        return errno;
 
45
    }
 
46
#elif defined(OS2) || defined(TPF)
 
47
    /* OS/2 don't support process group IDs */
 
48
    pgrp = getpid();
 
49
#elif defined(MPE)
 
50
    /* MPE uses negative pid for process group */
 
51
    pgrp = -getpid();
 
52
#else
 
53
    if ((pgrp = setpgid(0, 0)) == -1) {
 
54
        return errno;
 
55
    }
 
56
#endif
 
57
 
 
58
    /* close out the standard file descriptors */
 
59
    if (freopen("/dev/null", "r", stdin) == NULL) {
 
60
        return errno;
 
61
        /* continue anyhow -- note we can't close out descriptor 0 because we
 
62
         * have nothing to replace it with, and if we didn't have a descriptor
 
63
         * 0 the next file would be created with that value ... leading to
 
64
         * havoc.
 
65
         */
 
66
    }
 
67
    if (freopen("/dev/null", "w", stdout) == NULL) {
 
68
        return errno;
 
69
    }
 
70
     /* We are going to reopen this again in a little while to the error
 
71
      * log file, but better to do it twice and suffer a small performance
 
72
      * hit for consistancy than not reopen it here.
 
73
      */
 
74
    if (freopen("/dev/null", "w", stderr) == NULL) {
 
75
        return errno;
 
76
    }
 
77
#endif
 
78
    return APR_SUCCESS;
 
79
}
 
80
 
 
81
#if 0
 
82
#if (!HAVE_WAITPID)
 
83
/* From ikluft@amdahl.com
 
84
 * this is not ideal but it works for SVR3 variants
 
85
 * Modified by dwd@bell-labs.com to call wait3 instead of wait because
 
86
 *   apache started to use the WNOHANG option.
 
87
 */
 
88
int waitpid(pid_t pid, int *statusp, int options)
 
89
{
 
90
    int tmp_pid;
 
91
    if (kill(pid, 0) == -1) {
 
92
        errno = ECHILD;
 
93
        return -1;
 
94
    }
 
95
    while (((tmp_pid = wait3(statusp, options, 0)) != pid) &&
 
96
                (tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
 
97
        ;
 
98
    return tmp_pid;
 
99
}
 
100
#endif
 
101
#endif
 
102