Changeset 1293

Show
Ignore:
Timestamp:
06/22/07 12:49:13 (1 year ago)
Author:
till
Message:

- file descriptor handling for daemon mode fixed
- some return value checks added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeytrap/trunk/src/ctrl.c

    r1292 r1293  
    127127                DEBUG_FPRINTF(stdout, "  Successfully changed into daemon environment.\n"); 
    128128                fprintf(stdout, "\nhoneytrap v%s Copyright (C) 2005-2007 Tillmann Werner <tillmann.werner@gmx.de>\n", VERSION); 
    129                 fflush(stdout); 
     129                fflush(NULL); 
    130130                exit(EXIT_SUCCESS); 
    131131        } 
     
    133133 
    134134        /* change working directory to root directory */ 
    135         DEBUG_FPRINTF(stdout, "  Current working directory is %s.\n", old_cwd); 
    136         DEBUG_FPRINTF(stdout, "  Changing working directory to /.\n"); 
     135        DEBUG_FPRINTF(stdout, "  Current working directory is %s, changing it to /.\n", old_cwd); 
    137136        if (chdir("/") < 0) { 
    138137                fprintf(stderr, "  Error - Cannot change working directory: %s\n", strerror(errno)); 
     
    141140 
    142141 
    143  
    144         /* close open file descriptors */ 
     142        /* close open file descriptors, only keep logfile and signal pipe */ 
    145143        if (rl.rlim_max == RLIM_INFINITY) rl.rlim_max = 1024; 
    146         for (i=0; i < rl.rlim_max; i++) if (i != logfile_fd) close(i); 
     144        for (i=0; i < rl.rlim_max; i++) 
     145                if ((i != logfile_fd) && (i != sigpipe[0]) && (i != sigpipe[1]) && (close(i) == -1)) 
     146                        fprintf(stdout, "  Warnging - Could not close file descriptor %d: %s.\n", i, strerror(errno)); 
    147147 
    148148        /* attach file descriptors 0, 1 and 2 to /dev/null to prevent accidentally standard IO */ 
    149         fd0 = open("/dev/null", O_RDWR); 
    150         fd1 = dup(fd0); 
    151         fd2 = dup(fd0); 
     149        if ((fd0 = open("/dev/null", O_RDWR)) == -1) { 
     150                fprintf(stderr, "  Error - Unable to set stdin to /dev/null: %s.\n", strerror(errno)); 
     151                exit(EXIT_FAILURE); 
     152        } 
     153        if ((fd1 = dup(fd0)) == -1) { 
     154                fprintf(stderr, "  Error - Unable to set stdout to /dev/null: %s.\n", strerror(errno)); 
     155                exit(EXIT_FAILURE); 
     156        } 
     157        if ((fd2 = dup(fd0)) == -1) { 
     158                fprintf(stderr, "  Error - Unable to set stderr to /dev/null: %s.\n", strerror(errno)); 
     159                exit(EXIT_FAILURE); 
     160        } 
     161        fflush(NULL); 
    152162 
    153163        return(1); 
  • honeytrap/trunk/src/signals.c

    r1292 r1293  
    143143        /* create a pipe for process-internal signal delivery */ 
    144144        if (pipe(sigpipe) == -1) { 
    145                 logmsg(LOG_ERR, 1, "Error - Unable to create signal pipe: %s.\n", strerror(errno)); 
     145                fprintf(stderr, "  Error - Unable to create signal pipe: %s.\n", strerror(errno)); 
    146146                exit(EXIT_FAILURE); 
    147147        }