diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-02-12 20:20:49 +1300 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2006-02-12 20:20:49 +1300 |
commit | ec3e4116687f5e990e6d24e2c79e629665ac5e7e (patch) | |
tree | b99eab8a9fcab6125bc37914c10ebcf7a514df7f /bitlbee.c | |
parent | 9fae35c9cf2d5a319623946705e5d7179ea5c338 (diff) | |
parent | 1d2e3c2ee2fb4c12ad25832b93ae9513d042717a (diff) |
Merge Wilmer
Diffstat (limited to 'bitlbee.c')
-rw-r--r-- | bitlbee.c | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -44,6 +44,7 @@ int bitlbee_daemon_init() #endif int i; GIOChannel *ch; + FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); @@ -103,13 +104,30 @@ int bitlbee_daemon_init() } else if( i != 0 ) exit( 0 ); - close( 0 ); - close( 1 ); - close( 2 ); + chdir( "/" ); + + /* Sometimes std* are already closed (for example when we're in a RESTARTed + BitlBee process. So let's only close TTY-fds. */ + if( isatty( 0 ) ) close( 0 ); + if( isatty( 0 ) ) close( 1 ); + if( isatty( 0 ) ) close( 2 ); } #endif + if( global.conf->runmode == RUNMODE_FORKDAEMON ) + ipc_master_load_state(); + + if( ( fp = fopen( global.conf->pidfile, "w" ) ) ) + { + fprintf( fp, "%d\n", (int) getpid() ); + fclose( fp ); + } + else + { + log_message( LOGLVL_WARNING, "Warning: Couldn't write PID to `%s'", global.conf->pidfile ); + } + return( 0 ); } @@ -235,6 +253,12 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); pid_t client_pid = 0; + if( new_socket == -1 ) + { + log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) ); + return TRUE; + } + if( global.conf->runmode == RUNMODE_FORKDAEMON ) { int fds[2]; |