Code cleanup

This commit is contained in:
Michiel Broek 2007-02-11 14:35:34 +00:00
parent 9adbb84b63
commit 94268e6ac9
3 changed files with 11 additions and 17 deletions

View File

@ -9,6 +9,9 @@ v0.91.3 11-Feb-2007
The check filebase command now also removes dead symlinks from The check filebase command now also removes dead symlinks from
the download directories. the download directories.
mbtask:
Some code cleanup.
v0.91.2 14-Jan-2007 - 11-Feb-2007 v0.91.2 14-Jan-2007 - 11-Feb-2007

View File

@ -4,7 +4,7 @@
* Purpose ...............: MBSE BBS Task Manager * Purpose ...............: MBSE BBS Task Manager
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2006 * Copyright (C) 1997-2007
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -489,16 +489,11 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
while ((vector[i++] = strtok(NULL," \t\n")) && (i<16)); while ((vector[i++] = strtok(NULL," \t\n")) && (i<16));
vector[15] = NULL; vector[15] = NULL;
for (i = 0; i < 16; i++)
if (vector[i])
Syslog('l', "Launch: i=%d vector=\"%s\"", i, vector[i]);
if (file_exist(vector[0], X_OK)) { if (file_exist(vector[0], X_OK)) {
Syslog('?', "Launch: can't execute %s, command not found", vector[0]); WriteError("Launch: can't execute %s, command not found", vector[0]);
return 0; return 0;
} }
Syslog('l', "Launch: b4 fork()");
switch (pid = fork()) { switch (pid = fork()) {
case -1: case -1:
WriteError("$Launch: error, can't fork grandchild"); WriteError("$Launch: error, can't fork grandchild");
@ -509,39 +504,36 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
* before the main process sees it ever started. * before the main process sees it ever started.
*/ */
msleep(150); msleep(150);
Syslog('l', "Launch: child process");
/* From Paul Vixies cron: */ /* From Paul Vixies cron: */
rc = setsid(); /* It doesn't seem to help */ rc = setsid(); /* It doesn't seem to help */
if (rc == -1) if (rc == -1)
Syslog('?', "$Launch: setsid()"); WriteError("$Launch: setsid()");
close(0); close(0);
if (open("/dev/null", O_RDONLY) != 0) { if (open("/dev/null", O_RDONLY) != 0) {
Syslog('?', "$Launch: \"%s\": reopen of stdin to /dev/null failed", buf); WriteError("$Launch: \"%s\": reopen of stdin to /dev/null failed", buf);
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
} }
close(1); close(1);
if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
Syslog('?', "$Launch: \"%s\": reopen of stdout to /dev/null failed", buf); WriteError("$Launch: \"%s\": reopen of stdout to /dev/null failed", buf);
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
} }
close(2); close(2);
if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
Syslog('?', "$Launch: \"%s\": reopen of stderr to /dev/null failed", buf); WriteError("$Launch: \"%s\": reopen of stderr to /dev/null failed", buf);
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
} }
errno = 0; errno = 0;
rc = execv(vector[0],vector); rc = execv(vector[0],vector);
Syslog('?', "$Launch: execv \"%s\" failed, returned %d", cmd, rc); WriteError("$Launch: execv \"%s\" failed, returned %d", cmd, rc);
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
default: default:
/* grandchild's daddy's process */ /* grandchild's daddy's process */
break; break;
} }
Syslog('l', "Launch: parent process");
/* /*
* Add it to the tasklist. * Add it to the tasklist.
*/ */

View File

@ -4,7 +4,7 @@
* Purpose ...............: MBSE BBS Daemon * Purpose ...............: MBSE BBS Daemon
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2006 * Copyright (C) 1997-2007
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -92,7 +92,6 @@ char *exe_cmd(char *in)
strncpy(ibuf, in, SS_BUFSIZE); strncpy(ibuf, in, SS_BUFSIZE);
strncpy(cmd, ibuf, 4); strncpy(cmd, ibuf, 4);
// token[0] = '\0';
strncpy(ebuf, "200:1,Syntax error;", 19); strncpy(ebuf, "200:1,Syntax error;", 19);
/* /*