From 85e551026c0b73f77ed38804c5785edb36481e2b Mon Sep 17 00:00:00 2001 From: kcwu Date: Wed, 22 Mar 2006 17:59:09 +0000 Subject: redirect stderr(fd 2) to file. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3299 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/mbbsd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 722c059f..5de68ea1 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -81,8 +81,7 @@ start_daemon(void) while (n) close(--n); - /* in2: open /dev/null to fd:2 */ - if( ((fd = open("/dev/null", O_WRONLY)) >= 0) && fd != 2 ){ + if( ((fd = open("log/stderr", O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) && fd != 2 ){ dup2(fd, 2); close(fd); } @@ -1479,6 +1478,7 @@ main(int argc, char *argv[], char *envp[]) static int shell_login(int argc, char *argv[], char *envp[]) { + int fd; STATINC(STAT_SHELLLOGIN); /* Give up root privileges: no way back from here */ @@ -1505,6 +1505,10 @@ shell_login(int argc, char *argv[], char *envp[]) } close(2); /* don't close fd 1, at least init_tty need it */ + if( ((fd = open("log/stderr", O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) && fd != 2 ){ + dup2(fd, 2); + close(fd); + } init_tty(); if (check_ban_and_load(0)) { -- cgit v1.2.3