Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • unix.c

    r58bc4e6 rb73ac9c  
    2929#include "protocols/nogaim.h"
    3030#include "help.h"
    31 #include "ipc.h"
    3231#include <signal.h>
    3332#include <unistd.h>
    3433#include <sys/time.h>
    35 #include <sys/wait.h>
    3634
    3735global_t global;        /* Against global namespace pollution */
     
    3937static void sighandler( int signal );
    4038
    41 int main( int argc, char *argv[], char **envp )
     39int main( int argc, char *argv[] )
    4240{
    4341        int i = 0;
    44         char *old_cwd = NULL;
    4542        struct sigaction sig, old;
    4643       
     
    4946        global.loop = g_main_new( FALSE );
    5047       
    51         log_init();
    52 
    53         nogaim_init();
    54 
     48        log_init( );
     49        nogaim_init( );
     50       
    5551        CONF_FILE = g_strdup( CONF_FILE_DEF );
    5652       
     
    7369                log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION );
    7470        }
    75         else if( global.conf->runmode == RUNMODE_FORKDAEMON )
    76         {
    77                 /* In case the operator requests a restart, we need this. */
    78                 old_cwd = g_malloc( 256 );
    79                 if( getcwd( old_cwd, 255 ) == NULL )
    80                 {
    81                         log_message( LOGLVL_WARNING, "Could not save current directory: %s", strerror( errno ) );
    82                         g_free( old_cwd );
    83                         old_cwd = NULL;
    84                 }
    85                
    86                 i = bitlbee_daemon_init();
    87                 log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION );
    88         }
    8971        if( i != 0 )
    9072                return( i );
    9173
    92         global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
     74        global.storage = storage_init( global.conf->primary_storage,
     75                                                                   global.conf->migrate_storage );
    9376        if ( global.storage == NULL) {
    9477                log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
     
    10083        memset( &sig, 0, sizeof( sig ) );
    10184        sig.sa_handler = sighandler;
    102         sigaction( SIGCHLD, &sig, &old );
    10385        sigaction( SIGPIPE, &sig, &old );
    10486        sig.sa_flags = SA_RESETHAND;
     
    119101        g_main_run( global.loop );
    120102       
    121         if( global.restart )
    122         {
    123                 char *fn = ipc_master_save_state();
    124                 char **args;
    125                 int n, i;
    126                
    127                 chdir( old_cwd );
    128                
    129                 n = 0;
    130                 args = g_new0( char *, argc + 3 );
    131                 args[n++] = argv[0];
    132                 if( fn )
    133                 {
    134                         args[n++] = "-R";
    135                         args[n++] = fn;
    136                 }
    137                 for( i = 1; argv[i] && i < argc; i ++ )
    138                 {
    139                         if( strcmp( argv[i], "-R" ) == 0 )
    140                                 i += 2;
    141                        
    142                         args[n++] = argv[i];
    143                 }
    144                
    145                 close( global.listen_socket );
    146                
    147                 execve( args[0], args, envp );
    148         }
    149        
    150103        return( 0 );
    151104}
     
    153106static void sighandler( int signal )
    154107{
    155         /* FIXME: Calling log_message() here is not a very good idea! */
     108        /* FIXME: In fact, calling log_message() here can be dangerous. But well, let's take the risk for now. */
    156109       
    157110        if( signal == SIGTERM )
     
    179132                }
    180133        }
    181         else if( signal == SIGCHLD )
    182         {
    183                 pid_t pid;
    184                 int st;
    185                
    186                 while( ( pid = waitpid( 0, &st, WNOHANG ) ) > 0 )
    187                 {
    188                         if( WIFSIGNALED( st ) )
    189                                 log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", pid, WEXITSTATUS( st ) );
    190                         else if( WIFEXITED( st ) )
    191                                 log_message( LOGLVL_INFO, "Client %d killed by signal %d.", pid, WTERMSIG( st ) );
    192                 }
    193         }
    194134        else if( signal != SIGPIPE )
    195135        {
Note: See TracChangeset for help on using the changeset viewer.