diff options
Diffstat (limited to 'src/daemon/pidfile.c')
-rw-r--r-- | src/daemon/pidfile.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/daemon/pidfile.c b/src/daemon/pidfile.c index 53f81c9..0456425 100644 --- a/src/daemon/pidfile.c +++ b/src/daemon/pidfile.c @@ -39,7 +39,7 @@ void pidfile_set_from_filename( struct pidfile_t *pidfile, const char *filename snprintf( pidfile->filename, PATH_MAX, "%s", filename ); } -bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) { +bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, wolf_error_t *error ) { int res; ssize_t bytes_read; char buf[256]; @@ -55,11 +55,11 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) /* this is good, pid file doesn't exist at all */ LOG( log_DEBUG, "No pidfile '%s' found, daemon is not running", pidfile->filename ); (void)close( pidfile->fd ); - *error = OK; + *error = WOLF_OK; return pidfile->running; } else { LOG( log_EMERG, "Unable to open pidfile '%s' for reading: %s", pidfile->filename, strerror( errno ) ); - *error = ERR_INTERNAL; + *error = WOLF_ERR_INTERNAL; return pidfile->running; } } @@ -70,13 +70,13 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) if( errno == EAGAIN ) { /* another process locks the file already */ LOG( log_DEBUG, "Another process locks the pidfile, daemon already running" ); - *error = OK; + *error = WOLF_OK; pidfile->locked = true; pidfile->running = true; } else { LOG( log_EMERG, "Unable to lock pidfile '%s': %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); - *error = ERR_INTERNAL; + *error = WOLF_ERR_INTERNAL; pidfile->running = false; return pidfile->running; } @@ -89,7 +89,7 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) if( bytes_read < 0 ) { LOG( log_EMERG, "Unable to read pid from pidfile '%s': %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); - *error = ERR_INTERNAL; + *error = WOLF_ERR_INTERNAL; return pidfile->running; } @@ -105,7 +105,7 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) ( *pid < 2 ) /* too small value */ ) { LOG( log_EMERG, "pidfile '%s' contains invalid data, can't read PID from it!", pidfile->filename ); (void)close( pidfile->fd ); - *error = ERR_INTERNAL; + *error = WOLF_ERR_INTERNAL; return pidfile->running; } LOG( log_DEBUG, "Found PID '%lu' in pidfile", *pid ); @@ -119,12 +119,12 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) /* this is fine, process doesn't exist with this PID */ LOG( log_EMERG, "Found PID '%lu' in pidfile '%s', but no such process is running. Check and manually delete the pidfile!", *pid, pidfile->filename ); (void)close( pidfile->fd ); - *error = ERR_INTERNAL; + *error = WOLF_ERR_INTERNAL; return pidfile->running; } else { LOG( log_EMERG, "Can't check if processor with PID '%lu' is alive: %s", *pid, strerror( errno ) ); (void)close( pidfile->fd ); - *error = ERR_INTERNAL; + *error = WOLF_ERR_INTERNAL; return pidfile->running; } } @@ -134,11 +134,11 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error ) * (worst case, we assume, it's the daemon) */ (void)close( pidfile->fd ); - *error = OK; + *error = WOLF_OK; return pidfile->running; } -error_t pidfile_create( struct pidfile_t *pidfile ) { +wolf_error_t pidfile_create( struct pidfile_t *pidfile ) { int res; char pid_string[20]; ssize_t bytes_writen; @@ -147,7 +147,7 @@ error_t pidfile_create( struct pidfile_t *pidfile ) { pidfile->fd = open( pidfile->filename, O_CREAT | O_WRONLY | O_EXCL, 0644 ); if( pidfile->fd < 0 ) { LOG( log_EMERG, "Unable to open pidfile '%s' for writing: %s", pidfile->filename, strerror( errno ) ); - return ERR_INTERNAL; + return WOLF_ERR_INTERNAL; } /* Try to lock the pid file (non-blocking) */ @@ -160,12 +160,12 @@ error_t pidfile_create( struct pidfile_t *pidfile ) { LOG( log_EMERG, "Unable to lock pidfile '%s' after creation, daemon started in parallel?", pidfile->filename ); (void)close( pidfile->fd ); (void)unlink( pidfile->filename ); - return ERR_INVALID_STATE; + return WOLF_ERR_INVALID_STATE; } else { LOG( log_EMERG, "Unable to lock pidfile '%s' after creation: %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); (void)unlink( pidfile->filename ); - return ERR_INTERNAL; + return WOLF_ERR_INTERNAL; } } @@ -176,7 +176,7 @@ error_t pidfile_create( struct pidfile_t *pidfile ) { LOG( log_EMERG, "Unable to truncate the pidfile '%s' before writing to it", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); (void)unlink( pidfile->filename ); - return ERR_INTERNAL; + return WOLF_ERR_INTERNAL; } /* We remember the pid in the file for init scripts which rely on the pid @@ -188,7 +188,7 @@ error_t pidfile_create( struct pidfile_t *pidfile ) { LOG( log_EMERG, "Unable to write PID into the pidfile '%s': %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); (void)unlink( pidfile->filename ); - return ERR_INTERNAL; + return WOLF_ERR_INTERNAL; } else if( bytes_writen != (ssize_t)strlen( pid_string ) ) { /* non-atomic write on files with so little data, strange, should never happen! */ LOG( log_EMERG, "Non-atomic write failed when storing the PID into the pidfile '%s'", pidfile->filename ); @@ -197,11 +197,11 @@ error_t pidfile_create( struct pidfile_t *pidfile ) { pidfile->locked = true; - return OK; + return WOLF_OK; } -error_t pidfile_release( struct pidfile_t *pidfile ) { - error_t error = OK; +wolf_error_t pidfile_release( struct pidfile_t *pidfile ) { + wolf_error_t error = WOLF_OK; LOG( log_DEBUG, "Releasing (unlocking/closing) pidfile '%s' (fd: %d, locked: %d)", pidfile->filename, pidfile->fd, pidfile->locked ); @@ -210,7 +210,7 @@ error_t pidfile_release( struct pidfile_t *pidfile ) { if( lockf( pidfile->fd, F_ULOCK, (off_t)0 ) < 0 ) { LOG( log_ALERT, "Unable to unlock the pidfile '%s': %s (%d)", pidfile->filename, strerror( errno ), errno ); - error = ERR_INTERNAL; + error = WOLF_ERR_INTERNAL; } } @@ -218,7 +218,7 @@ error_t pidfile_release( struct pidfile_t *pidfile ) { if( close( pidfile->fd ) < 0 ) { LOG( log_ALERT, "Unable to close the pidfile '%s': %s (%d)", pidfile->filename, strerror( errno ), errno ); - error = ERR_INTERNAL; + error = WOLF_ERR_INTERNAL; } pidfile->fd = -1; } @@ -226,8 +226,8 @@ error_t pidfile_release( struct pidfile_t *pidfile ) { return error; } -error_t pidfile_remove( struct pidfile_t *pidfile ) { - error_t error = OK; +wolf_error_t pidfile_remove( struct pidfile_t *pidfile ) { + wolf_error_t error = WOLF_OK; LOG( log_DEBUG, "Removing pidfile '%s' (fd: %d, locked: %d, running: %d)", pidfile->filename, pidfile->fd, pidfile->locked, pidfile->running ); @@ -237,7 +237,7 @@ error_t pidfile_remove( struct pidfile_t *pidfile ) { if( unlink( pidfile->filename ) < 0 ) { LOG( log_ALERT, "Unable to remove the pidfile '%s': %s (%d)", pidfile->filename, strerror( errno ), errno ); - error = ERR_INTERNAL; + error = WOLF_ERR_INTERNAL; } return error; |