upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / os / tpf / os.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  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 /*
18  * This file will include OS specific functions which are not inlineable.
19  * Any inlineable functions should be defined in os-inline.c instead.
20  */
21
22 #include "httpd.h"
23 #include "http_core.h"
24 #include "os.h"
25 #include "scoreboard.h"
26 #include "http_log.h"
27
28 static FILE *sock_fp;
29
30 #ifndef __PIPE_
31 int pipe(int fildes[2])
32 {
33     errno = ENOSYS;
34     return(-1);
35 }
36 #endif
37   
38 /* fork and exec functions are not defined on
39    TPF due to the implementation of tpf_fork() */
40  
41 pid_t fork(void)
42 {
43     errno = ENOSYS;
44     return(-1);
45 }
46
47 int execl(const char *path, const char *arg0, ...)
48 {
49     errno = ENOSYS;
50     return(-1);
51 }
52
53 int execle(const char *path, const char *arg0, ...)
54 {
55     errno = ENOSYS;
56     return(-1);
57 }
58
59 int execve(const char *path, char *const argv[], char *const envp[])
60 {
61     errno = ENOSYS;
62     return(-1);
63 }
64
65 int execvp(const char *file, char *const argv[])
66 {
67     errno = ENOSYS;
68     return(-1);
69 }
70
71
72 pid_t os_fork(server_rec *s, int slot)
73 {
74     struct tpf_fork_input fork_input;
75     APACHE_TPF_INPUT input_parms;
76     int count;
77     listen_rec *lr;
78
79     fflush(stdin);
80     if (dup2(fileno(sock_fp), STDIN_FILENO) == -1)
81         ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s,
82         "unable to replace stdin with sock device driver");
83     fflush(stdout);
84     if (dup2(fileno(sock_fp), STDOUT_FILENO) == -1)
85         ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s,
86         "unable to replace stdout with sock device driver");
87     input_parms.generation = ap_my_generation;
88     input_parms.scoreboard_heap = ap_scoreboard_image;
89
90     lr = ap_listeners;
91     count = 0;
92     do {
93         input_parms.listeners[count] = lr->fd;
94         lr = lr->next;
95         count++;
96     } while(lr != ap_listeners);
97
98     input_parms.slot = slot;
99     input_parms.restart_time = ap_restart_time;
100     fork_input.ebw_data = &input_parms;
101     fork_input.program = ap_server_argv0;
102     fork_input.prog_type = TPF_FORK_NAME;
103     fork_input.istream = TPF_FORK_IS_BALANCE;
104     fork_input.ebw_data_length = sizeof(input_parms);
105     fork_input.parm_data = "-x";
106     return tpf_fork(&fork_input);
107 }
108
109 int os_check_server(char *server) {
110 #ifndef USE_TPF_DAEMON
111     int rv;
112     int *current_acn;
113     if((rv = inetd_getServerStatus(server)) == INETD_SERVER_STATUS_INACTIVE)
114         return 1;
115     else {
116         current_acn = (int *)cinfc_fast(CINFC_CMMACNUM);
117         if(ecbp2()->ce2acn != *current_acn)
118             return 1;
119     }
120 #endif
121     return 0;
122 }
123
124 AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
125     const request_rec *r,
126     apr_proc_t *newproc, const char *progname,
127     const char * const *args,
128     const char * const *env,
129     apr_procattr_t *attr, apr_pool_t *p)
130 {
131     return apr_proc_create(newproc, progname, args, env, attr, p);
132 }