Main Page | Modules | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

netware/procsup.c

Go to the documentation of this file.
00001 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
00002  * applicable.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "apr_arch_threadproc.h"
00018 
00019 apr_status_t apr_proc_detach(int daemonize)
00020 {
00021 #if 0
00022     int x;
00023     pid_t pgrp;
00024 
00025     chdir("/");
00026 #if !defined(MPE) && !defined(OS2) && !defined(TPF) && !defined(BEOS)
00027 /* Don't detach for MPE because child processes can't survive the death of
00028    the parent. */
00029     if ((x = fork()) > 0)
00030         exit(0);
00031     else if (x == -1) {
00032         perror("fork");
00033         fprintf(stderr, "unable to fork new process\n");
00034         exit(1);  /* we can't do anything here, so just exit. */
00035     }
00036 /*    RAISE_SIGSTOP(DETACH);*/
00037 #endif
00038 #if APR_HAVE_SETSID
00039     if ((pgrp = setsid()) == -1) {
00040         return errno;
00041     }
00042 #elif defined(NEXT) || defined(NEWSOS)
00043     if (setpgrp(0, getpid()) == -1 || (pgrp = getpgrp(0)) == -1) {
00044         return errno;
00045     }
00046 #elif defined(OS2) || defined(TPF)
00047     /* OS/2 don't support process group IDs */
00048     pgrp = getpid();
00049 #elif defined(MPE)
00050     /* MPE uses negative pid for process group */
00051     pgrp = -getpid();
00052 #else
00053     if ((pgrp = setpgid(0, 0)) == -1) {
00054         return errno;
00055     }
00056 #endif
00057 
00058     /* close out the standard file descriptors */
00059     if (freopen("/dev/null", "r", stdin) == NULL) {
00060         return errno;
00061         /* continue anyhow -- note we can't close out descriptor 0 because we
00062          * have nothing to replace it with, and if we didn't have a descriptor
00063          * 0 the next file would be created with that value ... leading to
00064          * havoc.
00065          */
00066     }
00067     if (freopen("/dev/null", "w", stdout) == NULL) {
00068         return errno;
00069     }
00070      /* We are going to reopen this again in a little while to the error
00071       * log file, but better to do it twice and suffer a small performance
00072       * hit for consistancy than not reopen it here.
00073       */
00074     if (freopen("/dev/null", "w", stderr) == NULL) {
00075         return errno;
00076     }
00077 #endif
00078     return APR_SUCCESS;
00079 }
00080 
00081 #if 0
00082 #if (!HAVE_WAITPID)
00083 /* From ikluft@amdahl.com
00084  * this is not ideal but it works for SVR3 variants
00085  * Modified by dwd@bell-labs.com to call wait3 instead of wait because
00086  *   apache started to use the WNOHANG option.
00087  */
00088 int waitpid(pid_t pid, int *statusp, int options)
00089 {
00090     int tmp_pid;
00091     if (kill(pid, 0) == -1) {
00092         errno = ECHILD;
00093         return -1;
00094     }
00095     while (((tmp_pid = wait3(statusp, options, 0)) != pid) &&
00096                 (tmp_pid != -1) && (tmp_pid != 0) && (pid != -1))
00097         ;
00098     return tmp_pid;
00099 }
00100 #endif
00101 #endif
00102