Changeset 85d7b85 for unix.c


Ignore:
Timestamp:
2008-04-02T14:22:57Z (12 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
f9dbc99
Parents:
875ad42 (diff), dd34575 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • unix.c

    r875ad42 r85d7b85  
    3434#include <sys/time.h>
    3535#include <sys/wait.h>
     36#include <pwd.h>
    3637
    3738global_t global;        /* Against global namespace pollution */
     
    4546        struct sigaction sig, old;
    4647       
    47         memset( &global, 0, sizeof( global_t ) );
    48        
    49         global.loop = g_main_new( FALSE );
    50        
    5148        log_init();
    52 
    53         nogaim_init();
    54 
    55         CONF_FILE = g_strdup( CONF_FILE_DEF );
    56        
    57         global.helpfile = g_strdup( HELP_FILE );
    58 
     49        global.conf_file = g_strdup( CONF_FILE_DEF );
    5950        global.conf = conf_load( argc, argv );
    6051        if( global.conf == NULL )
    6152                return( 1 );
    62 
    63 
     53       
     54        b_main_init();
     55        nogaim_init();
     56       
     57        srand( time( NULL ) ^ getpid() );
     58        global.helpfile = g_strdup( HELP_FILE );
     59       
    6460        if( global.conf->runmode == RUNMODE_INETD )
    6561        {
     
    9591        if( i != 0 )
    9692                return( i );
     93       
     94        if( ( global.conf->user && *global.conf->user ) &&
     95            ( global.conf->runmode == RUNMODE_DAEMON ||
     96              global.conf->runmode == RUNMODE_FORKDAEMON ) &&
     97            ( !getuid() || !geteuid() ) )
     98        {
     99                struct passwd *pw = NULL;
     100                pw = getpwnam( global.conf->user );
     101                if( pw )
     102                {
     103                        setgid( pw->pw_gid );
     104                        setuid( pw->pw_uid );
     105                }
     106        }
    97107
    98108        global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
    99         if ( global.storage == NULL) {
     109        if( global.storage == NULL )
     110        {
    100111                log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
    101112                return( 1 );
    102113        }
    103        
    104114       
    105115        /* Catch some signals to tell the user what's happening before quitting */
     
    120130        if( !getuid() || !geteuid() )
    121131                log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" );
    122         if( help_init( &(global.help) ) == NULL )
     132        if( help_init( &global.help, global.helpfile ) == NULL )
    123133                log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE );
    124134       
    125         g_main_run( global.loop );
     135        b_main_run();
     136       
     137        /* Mainly good for restarting, to make sure we close the help.txt fd. */
     138        help_free( &global.help );
    126139       
    127140        if( global.restart )
     
    171184                       
    172185                        log_message( LOGLVL_ERROR, "SIGTERM received, cleaning up process." );
    173                         g_timeout_add_full( G_PRIORITY_LOW, 1, (GSourceFunc) bitlbee_shutdown, NULL, NULL );
     186                        b_timeout_add( 1, (b_event_handler) bitlbee_shutdown, NULL );
    174187                       
    175188                        first = 0;
     
    193206                {
    194207                        if( WIFSIGNALED( st ) )
    195                                 log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", pid, WEXITSTATUS( st ) );
     208                                log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", (int) pid, WEXITSTATUS( st ) );
    196209                        else if( WIFEXITED( st ) )
    197                                 log_message( LOGLVL_INFO, "Client %d killed by signal %d.", pid, WTERMSIG( st ) );
     210                                log_message( LOGLVL_INFO, "Client %d killed by signal %d.", (int) pid, WTERMSIG( st ) );
    198211                }
    199212        }
Note: See TracChangeset for help on using the changeset viewer.