46 #include <sys/types.h>
57 # define ENABLE_NOBODY
65 #define OOREXX_PIDFILE "/var/run/ooRexx.pid"
68 #define OOREXX_PIDFILE "/tmp/ooRexx.pid"
85 void Run (
bool asService)
137 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
165 snprintf(pid_buf,
sizeof(pid_buf),
"%d\n", (
int)getpid());
166 write(pfile, pid_buf, strlen(pid_buf));
172 for(
int i = 0; i < 1024; i++) {
180 pw = getpwnam(
"nobody");
197 int main(
int argc,
char *argv[])
206 printf(
"Error: Invalid command line option(s).\n");
207 printf(
" Aborting execution.\n\n");
213 len = read(pfile, pid_buf,
sizeof(pid_buf) - 1);
216 pid = (pid_t)atoi(pid_buf);
217 if (pid && (pid == getpid() || kill(pid, 0) < 0)) {
221 printf(
"Error: There is already a server running.\n");
222 printf(
" Aborting execution.\n");
229 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
233 printf(
" Aborting execution.\n\n");
236 snprintf(pid_buf,
sizeof(pid_buf),
"%d\n", (
int)getpid());
237 write(pfile, pid_buf, strlen(pid_buf));
251 if (fstat(0, &st) <0) {
256 if ((st.st_mode & S_IFMT) == S_IFCHR) {
271 printf(
"Starting request processing loop.\n");
274 printf(
"Starting request processing loop.\n");
279 pw = getpwnam(
"nobody");
287 (void) sigemptyset(&sa.sa_mask);
288 (void) sigaddset(&sa.sa_mask, SIGTERM);
289 sa.sa_flags = SA_RESTART;
290 sa.sa_handler =
Stop;
291 if (sigaction(SIGTERM, &sa, NULL) == -1) {
void listenForConnections()
static bool morph2daemon(void)
int main(int argc, char *argv[])