diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-17 20:22:55 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-17 20:22:55 +0100 |
commit | 3404f2ca1994cf219992cc0e1c2a6e77068c1f5f (patch) | |
tree | 94b09d2a66b9f8c5fc3593a6fba6340d011a10ad /src/daemon | |
parent | 3a1b5c900a90ba1a7dc7fb9c62cb2814c3396234 (diff) | |
download | wolfbones-3404f2ca1994cf219992cc0e1c2a6e77068c1f5f.tar.gz wolfbones-3404f2ca1994cf219992cc0e1c2a6e77068c1f5f.tar.bz2 |
added _ to daemon.c
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/daemon.c | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index a605f18..7c020ed 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -3,6 +3,7 @@ #include "port/string.h" /* for strdup */ #include "port/limits.h" /* for PATH_MAX */ #include "port/noreturn.h" /* for NORETURN */ +#include "port/gettext.h" /* for i18n */ #include "errors.h" #include "log/log.h" @@ -102,8 +103,8 @@ static wolf_error_t close_fd( int fd ) { default: wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_CLOSE_FD, - "Error while closing file descriptor %d: %s (%d)", - fd, strerror( errno ), errno ); + _( "Error while closing file descriptor %d: %s" ), + fd, strerror( errno ) ); return WOLF_ERR_INTERNAL; } } @@ -130,12 +131,12 @@ static wolf_error_t daemon_close_all_fds( void ) { nof_files = sysconf( _SC_OPEN_MAX ); if( nof_files < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_RETRIEVING_MAXNOFFDS_FAILED, - "Unable to retrieve maximal number of files: %s (%d)", - strerror( errno ), errno ); + _( "Unable to retrieve maximal number of files: %s" ), + strerror( errno ) ); return WOLF_ERR_INTERNAL; } wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CLOSING_ALL_FDS, - "Closing all filedescriptors up to %ld", nof_files ); + _( "Closing all filedescriptors up to %ld" ), nof_files ); for( i = 0; i < nof_files; i++ ) { if( ( i == STDIN_FILENO ) || @@ -161,13 +162,13 @@ static wolf_error_t open_null_fd( int must_fd, int flags ) { fd = open( "/dev/null", flags ); if( fd < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_OPEN_FD_AS_DEV_NULL, - "Unable to open fd %d as /dev/null: %s (%d)", - must_fd, strerror( errno ), errno ); + _( "Unable to open fd %d as /dev/null: %s" ), + must_fd, strerror( errno ) ); return WOLF_ERR_INTERNAL; } if( fd != must_fd ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_FD_NUMBERS_WRONG, - "Something is wrong with the file descriptors (expecting %d, got %d)!", + _( "Something is wrong with the file descriptors (expecting %d, got %d)!" ), must_fd, fd ); return WOLF_ERR_PROGRAMMING; } @@ -183,11 +184,11 @@ atomar_write_again: if( res < 0 ) { if( errno == EINTR ) goto atomar_write_again; wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PIPE_ATOMIC_WRITE_FAILED, - "Error in atomar write to fd %d: %s (%d)", - fd, strerror( errno ), errno ); + _( "Error in atomar write to fd %d: %s" ), + fd, strerror( errno ) ); } else if( (size_t)res != data_len ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PIPE_ATOMIC_WRITE_WRONG_OCTETS, - "Unexpected number of octets %zd in atomar write to fd %d (expected %zd)", + _( "Unexpected number of octets %zd in atomar write to fd %d (expected %zd)" ), res, fd, data_len ); } } @@ -200,11 +201,11 @@ atomar_read_again: if( res < 0 ) { if( errno == EINTR ) goto atomar_read_again; wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PIPE_ATOMIC_READ_FAILED, - "Error in atmoar read from fd %d: %s (%d)", - fd, strerror( errno ), errno ); + _( "Error in atmoar read from fd %d: %s" ), + fd, strerror( errno ) ); } else if( (size_t)res != data_len ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PIPE_ATOMIC_READ_WRONG_OCTETS, - "Unexpected number of octets %zd in atomar read from fd %d (expected %zd)", + _( "Unexpected number of octets %zd in atomar read from fd %d (expected %zd)" ), res, fd, data_len ); } } @@ -320,7 +321,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ if( getppid( ) == 1 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_ALREADY_RUNNING, - "Already running as daemon!" ); + _( "Already running as daemon!" ) ); return( d->error = WOLF_ERR_PROGRAMMING ); } @@ -332,7 +333,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ if( geteuid( ) != 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_START_AS_NON_ROOT, - "Unable to start daemon as not root user!" ); + _( "Unable to start daemon as not root user!" ) ); return( d->error = WOLF_ERR_INVALID_STATE ); } @@ -358,12 +359,12 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ if( pipe( exit_code_pipe ) < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_CREATE_EXIT_CODE_PIPE, - "Unable to create exit code pipe: %s (%d)", - strerror( errno ), errno ); + _( "Unable to create exit code pipe: %s" ), + strerror( errno ) ); return ( d->error = WOLF_ERR_INTERNAL ); } wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_EXIT_CODE_PIPE_CREATED, - "Created exit code pipe (%d,%d)", exit_code_pipe[0], exit_code_pipe[1] ); + _( "Created exit code pipe (%d,%d)" ), exit_code_pipe[0], exit_code_pipe[1] ); /* first fork: make sure we are no longer process group leader. * So we can get our own process group leader by calling setsid @@ -372,13 +373,13 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { case -1: /* error */ wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_FIRST_FORK_FAILED, - "Unable to fork the first time: %s", strerror( errno ) ); + _( "Unable to fork the first time: %s" ), strerror( errno ) ); return ( d->error = WOLF_ERR_INTERNAL ); case 0: /* the child becomes the daemon */ wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_FIRST_FORK_REACHED, - "First fork reached" ); + _( "First fork reached" ) ); break; default: @@ -389,7 +390,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { * code from the error pipe */ wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PARENT_AFTER_FIRST_FORK, - "Parent after first fork: child is %d", pid ); + _( "Parent after first fork: child is %d" ), pid ); d->state = TERMINATE_EXIT_CODE; return( d->error = WOLF_ERR_PROGRAMMING ); /* intensional error code here, so we get into wolf_daemon_exit! */ } @@ -399,12 +400,12 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ if( pipe( daemon_parent_pipe ) < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_CREATE_PARENT_PIPE, - "Unable to create parent pipe: %s (%d)", - strerror( errno ), errno ); + _( "Unable to create parent pipe: %s" ), + strerror( errno ) ); return ( d->error = WOLF_ERR_INTERNAL ); } wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PARENT_PIPE_CREATED, - "Created parent pipe (%d,%d)", daemon_parent_pipe[0], daemon_parent_pipe[1] ); + _( "Created parent pipe (%d,%d)" ), daemon_parent_pipe[0], daemon_parent_pipe[1] ); /* Put the first child in it's own process group and finally detach it * from its controlling terminal. This ensure we don't get funny @@ -413,7 +414,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { if( setsid( ) < 0 ) { /* should actually never fail */ wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_SET_NEW_PROCESS_GROUP, - "Starting new process group session for the parent of the daemon failed: %s", strerror( errno ) ); + _( "Starting new process group session for the parent of the daemon failed: %s" ), strerror( errno ) ); return WOLF_ERR_INTERNAL; } @@ -441,19 +442,19 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { case -1: /* error */ wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SECOND_FORK_FAILED, - "Unable to fork the second time: %s", strerror( errno ) ); + _( "Unable to fork the second time: %s" ), strerror( errno ) ); return ( d->error = WOLF_ERR_INTERNAL ); case 0: /* the child becomes the daemon */ wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SECOND_FORK_REACHED, - "Second fork reached" ); + _( "Second fork reached" ) ); break; default: (void)install_signal_handlers_parent( ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PARENT_AFTER_SECOND_FORK, - "Parent after second fork: child (and daemon) is %d", pid ); + _( "Parent after second fork: child (and daemon) is %d" ), pid ); d->state = TERMINATE_PARENT; return( d->error = WOLF_ERR_PROGRAMMING ); /* intensional error code here, so we get into wolf_daemon_exit! */ } @@ -471,7 +472,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { if( setsid( ) < 0 ) { /* should actually never fail */ wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_SET_NEW_PROCESS_GROUP, - "Starting new process group for daemon session failed: %s", strerror( errno ) ); + _( "Starting new process group for daemon session failed: %s" ), strerror( errno ) ); return WOLF_ERR_INTERNAL; } @@ -485,11 +486,11 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ if( chdir( "/" ) < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_CHANGE_ROOT_DIR, - "Changing to root diretory failed: %s", strerror( errno ) ); + _( "Changing to root diretory failed: %s" ), strerror( errno ) ); return WOLF_ERR_INTERNAL; } wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CHANGED_ROOT_DIR, - "Changed to root directory /" ); + _( "Changed to root directory /" ) ); /* Change the umask to 0133 temporarily so we don't have to * chmod the logfiles, pidfiles later. @@ -498,13 +499,13 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ mode = umask( 0133 ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SWITCHED_UMASK, - "Switched umask from %04o to %04o", mode, 0133 ); + _( "Switched umask from %04o to %04o" ), mode, 0133 ); /* check if another daemon is already running, if yes, bail out */ if( is_daemon_running( &d->pidfile, &pid, &error ) || ( error != WOLF_OK ) ) { if( error == WOLF_OK ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_DAEMON_ALREADY_RUNNING_WITH_PID, - "Another daemon is already running with pid '%d', can't start!", pid ); + _( "Another daemon is already running with pid '%d', can't start!" ), pid ); } return WOLF_ERR_INTERNAL; } @@ -541,7 +542,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { */ mode = umask( 0137 ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SWITCHED_UMASK_FINAL, - "Switched umask from %04o to %04o", mode, 0137 ); + _( "Switched umask from %04o to %04o" ), mode, 0137 ); /* drop permissions to a non-priviledged user now */ if( ( d->params.group_name != NULL ) && ( d->params.user_name != NULL ) ) { @@ -550,11 +551,11 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { if( d->groupent == NULL ) { if( errno == 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_GROUP_NOT_FOUND, - "No group '%s' found", d->params.group_name ); + _( "No group '%s' found" ), d->params.group_name ); } else { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_GETGRNAM_FAILED, - "Unable to retrieve group information for group '%s': %s (%d)", - d->params.group_name, strerror( errno ), errno ); + _( "Unable to retrieve group information for group '%s': %s" ), + d->params.group_name, strerror( errno ) ); } return WOLF_ERR_INTERNAL; } @@ -564,26 +565,26 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { if( d->userent == NULL ) { if( errno == 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_USER_NOT_FOUND, - "No user '%s' found", d->params.user_name ); + _( "No user '%s' found" ), d->params.user_name ); } else { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_GETPWNAM_FAILED, - "Unable to retrieve user information for user '%s': %s (%d)", - d->params.user_name, strerror( errno ), errno ); + _( "Unable to retrieve user information for user '%s': %s" ), + d->params.user_name, strerror( errno ) ); } return WOLF_ERR_INTERNAL; } if( setgid( d->userent->pw_gid ) < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SETTING_UNPRIVILEGED_GROUP_FAILED, - "Setting unprivileged group failed: %s (%d)", - strerror( errno ), errno ); + _( "Setting unprivileged group failed: %s" ), + strerror( errno ) ); return WOLF_ERR_INTERNAL; } if( setuid( d->userent->pw_uid ) < 0 ) { wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SETTING_UNPRIVILEGED_USER_FAILED, - "Setting unprivileged user failed: %s (%d)", - strerror( errno ), errno ); + _( "Setting unprivileged user failed: %s" ), + strerror( errno ) ); return WOLF_ERR_INTERNAL; } @@ -592,7 +593,7 @@ wolf_error_t wolf_daemon_start( wolf_daemon_p d ) { * of the unpriviledged user */ wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SWITCHED_USER, - "Switched to user '%s' (%d) and group '%s' (%d)", + _( "Switched to user '%s' (%d) and group '%s' (%d)" ), d->params.user_name, d->userent->pw_uid, d->params.group_name, d->userent->pw_gid ); } @@ -621,7 +622,7 @@ NORETURN void wolf_daemon_exit( wolf_daemon_p d ) { int exit_code; wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_EXIT_CALLED, - "daemon_exit called int state %d (error %d)", + _( "daemon_exit called int state %d (error %d)" ), d->state, d->error ); switch( d->state ) { @@ -631,12 +632,12 @@ NORETURN void wolf_daemon_exit( wolf_daemon_p d ) { * the calling script or shell */ wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_WAITING_FOR_EXIT_CODE_ON_PIPE, - "Waiting on exit_code pipe for exit code" ); + _( "Waiting on exit_code pipe for exit code" ) ); atomar_read( exit_code_pipe[0], &exit_code, sizeof( int ) ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_TERMINATING_GRAND_PARENT, - "Terminating grand-parent of daemon with code %d (PID: %lu)", + _( "Terminating grand-parent of daemon with code %d (PID: %lu)" ), exit_code, getpid( ) ); wolf_daemon_signals_terminate( ); @@ -653,13 +654,13 @@ NORETURN void wolf_daemon_exit( wolf_daemon_p d ) { /* wait for termination signal */ wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_WAITING_FOR_TERMINATION, - "Waiting on parent pipe for termination signal" ); + _( "Waiting on parent pipe for termination signal" ) ); atomar_read( daemon_parent_pipe[0], &d->pidfile.locked, sizeof( bool ) ); atomar_read( daemon_parent_pipe[0], &d->pidfile.running, sizeof( bool ) ); atomar_read( daemon_parent_pipe[0], &d->pidfile.fd, sizeof( int ) ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_PARENT_GOT_TERMINATION, - "Parent got termination (pidfile lock: %d, run: %d, fd: %d).. cleaning up now (PID: %lu)", + _( "Parent got termination (pidfile lock: %d, run: %d, fd: %d).. cleaning up now (PID: %lu)" ), d->pidfile.locked, d->pidfile.running, d->pidfile.fd, getpid( ) ); /* we need root permissions for that! */ @@ -668,7 +669,7 @@ NORETURN void wolf_daemon_exit( wolf_daemon_p d ) { wolf_daemon_signals_terminate( ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_TERMINATING_PARENT, - "Terminating parent of daemon (PID %lu)", getpid( ) ); + _( "Terminating parent of daemon (PID %lu)" ), getpid( ) ); /* exit code is irrelevant here.. */ exit( EXIT_SUCCESS ); @@ -687,7 +688,7 @@ NORETURN void wolf_daemon_exit( wolf_daemon_p d ) { wolf_daemon_signals_terminate( ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_TERMINATING_DAEMON_OK, - "Terminating daemon (PID: %lu)", getpid( ) ); + _( "Terminating daemon (PID: %lu)" ), getpid( ) ); /* exit code is irrelevant here */ _exit( EXIT_SUCCESS ); @@ -714,7 +715,7 @@ NORETURN void wolf_daemon_exit( wolf_daemon_p d ) { wolf_daemon_signals_terminate( ); wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_TERMINATING_DAEMON_ERROR, - "Terminating daemon (PID: %lu) with error", getpid( ) ); + _( "Terminating daemon (PID: %lu) with error" ), getpid( ) ); /* exit code is irrelevant here */ _exit( EXIT_SUCCESS ); @@ -739,12 +740,11 @@ wolf_error_t wolf_daemon_signals_initialize( void ) { if( res < 0 ) { (void)strerror_r( errno, errbuf, 1024 ); wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_CREATE_SIGNAL_PIPE, - "Unable to create signal pipe: %s (%d)", - errbuf, errno ); + _( "Unable to create signal pipe: %s" ), errbuf ); return WOLF_ERR_INTERNAL; } wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SIGNAL_PIPE_CREATED, - "Created signal pipe (%d,%d)", daemon_signal_pipe[0], daemon_signal_pipe[1] ); + _( "Created signal pipe (%d,%d)" ), daemon_signal_pipe[0], daemon_signal_pipe[1] ); return WOLF_OK; } @@ -788,8 +788,8 @@ signal_select_again: if( errno == 514 ) goto signal_select_again; (void)strerror_r( errno, errbuf, 1024 ); wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_SELECT_FAILED_WAITING_FOR_SIGNAL, - "Error in select when waiting for signal from pipe: %s (%d)", - errbuf, errno ); + _( "Error in select when waiting for signal from pipe: %s" ), + errbuf ); *error = WOLF_ERR_INTERNAL; return -1; } @@ -802,14 +802,14 @@ signal_select_again: case -1: /* error */ (void)strerror_r( errno, errbuf, 1024 ); wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_CANT_READ_SIGNAL_FROM_PIPE, - "Error while reading a signal from the pipe: %s (%d)", - errbuf, errno ); + _( "Error while reading a signal from the pipe: %s" ), + errbuf ); *error = WOLF_ERR_INTERNAL; return -1; default: /* unexpected result on atomic read */ wolf_log( WOLF_LOG_EMERG, WOLF_CATEGORY_DAEMON, WOLF_MSG_DAEMON_NON_ATOMIC_READ_ON_SIGNAL_PIPE, - "Unexpected error in read: result is %d", res ); + _( "Unexpected error in read: result is %d" ), res ); *error = WOLF_ERR_PROGRAMMING; return -1; } |