소스 검색

* Fixed stdin/stdout/stderr not being closed when bot is forked into background.

svn: 1615
Bryan Drewery 21 년 전
부모
커밋
1d28c381bb
4개의 변경된 파일23개의 추가작업 그리고 22개의 파일을 삭제
  1. 1 0
      doc/UPDATES
  2. 17 21
      src/bg.c
  3. 1 0
      src/bg.h
  4. 4 1
      src/main.c

+ 1 - 0
doc/UPDATES

@@ -15,6 +15,7 @@ This is a summary of ChangeLog basically.
 * Removed compatability support for <= 1.1.9 userfiles (bot records).
 * Now compiling all x86 binaries as i486 (as opposed to pentium binaries on FreeBSD like before).
 * cmd_conf now correctly writes new data to binary (not tested)
+* Fixed stdin/stdout/stderr not being closed when bot is forked into background.
 
 1.2
 * No longer displaying SALTS on ./bin -v

+ 17 - 21
src/bg.c

@@ -31,12 +31,25 @@ pid_t watcher;                  /* my child/watcher */
 static void init_watcher(pid_t);
 #endif /* !CYGWIN_HACKS */
 
+int close_tty()
+{
+  int fd = -1;
+
+  if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+    dup2(fd, STDIN_FILENO);
+    dup2(fd, STDOUT_FILENO);
+    dup2(fd, STDERR_FILENO);
+    if (fd > 2)
+      close(fd);
+    return 1;
+  }
+  return 0;
+}
+
 /*
 int
 my_daemon(int nochdir, int noclose)
 {
-  int fd;
-
   switch (fork()) {
     case -1:
       return (-1);
@@ -52,25 +65,8 @@ my_daemon(int nochdir, int noclose)
   if (!nochdir)
     (void) chdir("/");
 
-  if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
-    struct stat64 st;
-
-    if (__builtin_expect(__fxstat64(_STAT_VER, fd, &st), 0) == 0
-        && __builtin_expect(S_ISCHR(st.st_mode), 1) != 0
-#if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR
-        && st.st_rdev == makedev(DEV_NULL_MAJOR, DEV_NULL_MINOR)
-#endif
-      ) {
-      (void) dup2(fd, STDIN_FILENO);
-      (void) dup2(fd, STDOUT_FILENO);
-      (void) dup2(fd, STDERR_FILENO);
-      if (fd > 2)
-        (void) close(fd);
-    } else {
-      (void) close(fd);
-      return -1;
-    }
-  }
+  if (!noclose)
+    close_tty();
   return (0);
 }
 */

+ 1 - 0
src/bg.h

@@ -7,6 +7,7 @@ extern time_t 		lastfork;
 extern pid_t 		watcher;
 
 pid_t do_fork();
+int close_tty();
 void writepid(const char *, pid_t);
 
 #endif /* !_BG_H */

+ 4 - 1
src/main.c

@@ -807,11 +807,13 @@ printf("out: %s\n", out);
      confuses windows ;)
    */
   use_stderr = 0;		/* stop writing to stderr now! */
+
   if (backgrd) {
 #ifndef CYGWIN_HACKS
     pid_t pid = 0;
   
     pid = do_fork();
+
 /*
     printf("  |- %-10s (%d)\n", conf.bot->nick, pid);
     if (localhub) {
@@ -831,6 +833,7 @@ printf("out: %s\n", out);
             COLOR_END(-1), BOLD(-1), BOLD_END(-1), BOLD(-1), BOLD_END(-1), BOLD(-1), BOLD_END(-1),
             BOLD(-1), BOLD_END(-1), YELLOW(-1), COLOR_END(-1), pid, YELLOW(-1), COLOR_END(-1));
 #endif
+    close_tty();
   } else {
 #endif /* !CYGWIN_HACKS */
 #ifdef CYGWIN_HACKS
@@ -847,7 +850,7 @@ printf("out: %s\n", out);
     dcc[n].addr = iptolong(getmyip());
     dcc[n].sock = STDOUT;
     dcc[n].timeval = now;
-    dcc[n].u.chat->con_flags = LOG_ALL;
+    dcc[n].u.chat->con_flags = conmask;
     dcc[n].u.chat->strip_flags = STRIP_ALL;
     dcc[n].status = STAT_ECHO;
     strcpy(dcc[n].nick, "HQ");