diff options
Diffstat (limited to 'unix.c')
-rw-r--r-- | unix.c | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -28,7 +28,6 @@ #include "arc.h" #include "base64.h" #include "commands.h" -#include "crypting.h" #include "otr.h" #include "protocols/nogaim.h" #include "help.h" @@ -41,6 +40,7 @@ #include <sys/time.h> #include <sys/wait.h> #include <pwd.h> +#include <locale.h> global_t global; /* Against global namespace pollution */ @@ -54,17 +54,22 @@ int main( int argc, char *argv[] ) char *old_cwd = NULL; struct sigaction sig, old; + /* Required to make iconv to ASCII//TRANSLIT work. This makes BitlBee + system-locale-sensitive. :-( */ + setlocale( LC_CTYPE, "" ); + if( argc > 1 && strcmp( argv[1], "-x" ) == 0 ) return crypt_main( argc, argv ); log_init(); + global.conf_file = g_strdup( CONF_FILE_DEF ); global.conf = conf_load( argc, argv ); if( global.conf == NULL ) return( 1 ); b_main_init(); - nogaim_init(); + /* Ugly Note: libotr and gnutls both use libgcrypt. libgcrypt has a process-global config state whose initialization happpens twice if libotr and gnutls are used together. libotr installs custom @@ -74,7 +79,17 @@ int main( int argc, char *argv[] ) otr_init(); srand( time( NULL ) ^ getpid() ); + global.helpfile = g_strdup( HELP_FILE ); + if( help_init( &global.help, global.helpfile ) == NULL ) + log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE ); + + global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage ); + if( global.storage == NULL ) + { + log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); + return( 1 ); + } if( global.conf->runmode == RUNMODE_INETD ) { @@ -126,13 +141,6 @@ int main( int argc, char *argv[] ) setuid( pw->pw_uid ); } } - - global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage ); - if( global.storage == NULL ) - { - log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); - return( 1 ); - } /* Catch some signals to tell the user what's happening before quitting */ memset( &sig, 0, sizeof( sig ) ); @@ -151,8 +159,6 @@ int main( int argc, char *argv[] ) if( !getuid() || !geteuid() ) log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" ); - if( help_init( &global.help, global.helpfile ) == NULL ) - log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE ); b_main_run(); @@ -162,12 +168,15 @@ int main( int argc, char *argv[] ) if( global.restart ) { char *fn = ipc_master_save_state(); + char *env; - chdir( old_cwd ); - - setenv( "_BITLBEE_RESTART_STATE", fn, 1 ); + env = g_strdup_printf( "_BITLBEE_RESTART_STATE=%s", fn ); + putenv( env ); g_free( fn ); + /* Looks like env should *not* be freed here as putenv + doesn't make a copy. Odd. */ + chdir( old_cwd ); close( global.listen_socket ); if( execv( argv[0], argv ) == -1 ) @@ -242,7 +251,7 @@ static void sighandler( int signal ) { /* FIXME: Calling log_message() here is not a very good idea! */ - if( signal == SIGTERM ) + if( signal == SIGTERM || signal == SIGQUIT || signal == SIGINT ) { static int first = 1; |