diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-02-08 16:45:36 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-02-08 16:45:36 +0100 |
commit | 7b3ea9022b57701e7fe156052c8e8af900f04eac (patch) | |
tree | 47f3cdb32d34b6076bdb524dcccaa5fbf51f9b77 /src/daemon/pidfile.c | |
parent | 56eef17b90b8b119e5822005d5cbfb14ec3adcb4 (diff) | |
download | wolfbones-7b3ea9022b57701e7fe156052c8e8af900f04eac.tar.gz wolfbones-7b3ea9022b57701e7fe156052c8e8af900f04eac.tar.bz2 |
more renaming of logging functions and more documentation of them
Diffstat (limited to 'src/daemon/pidfile.c')
-rw-r--r-- | src/daemon/pidfile.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/daemon/pidfile.c b/src/daemon/pidfile.c index 0456425..4ffd429 100644 --- a/src/daemon/pidfile.c +++ b/src/daemon/pidfile.c @@ -53,12 +53,12 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, wolf_error_t *err if( pidfile->fd < 0 ) { if( errno == ENOENT ) { /* this is good, pid file doesn't exist at all */ - LOG( log_DEBUG, "No pidfile '%s' found, daemon is not running", pidfile->filename ); + WOLF_LOG( log_DEBUG, "No pidfile '%s' found, daemon is not running", pidfile->filename ); (void)close( pidfile->fd ); *error = WOLF_OK; return pidfile->running; } else { - LOG( log_EMERG, "Unable to open pidfile '%s' for reading: %s", pidfile->filename, strerror( errno ) ); + WOLF_LOG( log_EMERG, "Unable to open pidfile '%s' for reading: %s", pidfile->filename, strerror( errno ) ); *error = WOLF_ERR_INTERNAL; return pidfile->running; } @@ -69,12 +69,12 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, wolf_error_t *err if( res < 0 ) { if( errno == EAGAIN ) { /* another process locks the file already */ - LOG( log_DEBUG, "Another process locks the pidfile, daemon already running" ); + WOLF_LOG( log_DEBUG, "Another process locks the pidfile, daemon already running" ); *error = WOLF_OK; pidfile->locked = true; pidfile->running = true; } else { - LOG( log_EMERG, "Unable to lock pidfile '%s': %s", pidfile->filename, strerror( errno ) ); + WOLF_LOG( log_EMERG, "Unable to lock pidfile '%s': %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); *error = WOLF_ERR_INTERNAL; pidfile->running = false; @@ -87,7 +87,7 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, wolf_error_t *err /* try to read the pid from the file */ bytes_read = read( pidfile->fd, buf, sizeof( buf ) - 1 ); if( bytes_read < 0 ) { - LOG( log_EMERG, "Unable to read pid from pidfile '%s': %s", pidfile->filename, strerror( errno ) ); + WOLF_LOG( log_EMERG, "Unable to read pid from pidfile '%s': %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); *error = WOLF_ERR_INTERNAL; return pidfile->running; @@ -103,12 +103,12 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, wolf_error_t *err ( end_ptr == NULL ) /* pre-condition for check for '\0'! */ || ( end_ptr - buf < 1 ) /* too short */ || ( *pid < 2 ) /* too small value */ ) { - LOG( log_EMERG, "pidfile '%s' contains invalid data, can't read PID from it!", pidfile->filename ); + WOLF_LOG( log_EMERG, "pidfile '%s' contains invalid data, can't read PID from it!", pidfile->filename ); (void)close( pidfile->fd ); *error = WOLF_ERR_INTERNAL; return pidfile->running; } - LOG( log_DEBUG, "Found PID '%lu' in pidfile", *pid ); + WOLF_LOG( log_DEBUG, "Found PID '%lu' in pidfile", *pid ); /* the pid is valid, but is there a process with the pid actually running? * (this handles the case of kill -9!) @@ -117,18 +117,18 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, wolf_error_t *err if( res < 0 ) { if( errno == ESRCH ) { /* 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 ); + WOLF_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 = WOLF_ERR_INTERNAL; return pidfile->running; } else { - LOG( log_EMERG, "Can't check if processor with PID '%lu' is alive: %s", *pid, strerror( errno ) ); + WOLF_LOG( log_EMERG, "Can't check if processor with PID '%lu' is alive: %s", *pid, strerror( errno ) ); (void)close( pidfile->fd ); *error = WOLF_ERR_INTERNAL; return pidfile->running; } } - LOG( log_DEBUG, "A process with PID '%lu' is already running", *pid ); + WOLF_LOG( log_DEBUG, "A process with PID '%lu' is already running", *pid ); /* process successfuly signaled, so a process with this PID exists * (worst case, we assume, it's the daemon) @@ -146,7 +146,7 @@ wolf_error_t pidfile_create( struct pidfile_t *pidfile ) { /* create or open pid file with correct permissions */ 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 ) ); + WOLF_LOG( log_EMERG, "Unable to open pidfile '%s' for writing: %s", pidfile->filename, strerror( errno ) ); return WOLF_ERR_INTERNAL; } @@ -157,12 +157,12 @@ wolf_error_t pidfile_create( struct pidfile_t *pidfile ) { /* another process locks the file already, this should not happen, maybe a * race between to daemons started in parallel? */ - LOG( log_EMERG, "Unable to lock pidfile '%s' after creation, daemon started in parallel?", pidfile->filename ); + WOLF_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 WOLF_ERR_INVALID_STATE; } else { - LOG( log_EMERG, "Unable to lock pidfile '%s' after creation: %s", pidfile->filename, strerror( errno ) ); + WOLF_LOG( log_EMERG, "Unable to lock pidfile '%s' after creation: %s", pidfile->filename, strerror( errno ) ); (void)close( pidfile->fd ); (void)unlink( pidfile->filename ); return WOLF_ERR_INTERNAL; @@ -173,7 +173,7 @@ wolf_error_t pidfile_create( struct pidfile_t *pidfile ) { * in the pid file */ if( ftruncate( pidfile->fd, (off_t)0 ) < 0 ) { - LOG( log_EMERG, "Unable to truncate the pidfile '%s' before writing to it", pidfile->filename, strerror( errno ) ); + WOLF_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 WOLF_ERR_INTERNAL; @@ -185,15 +185,15 @@ wolf_error_t pidfile_create( struct pidfile_t *pidfile ) { snprintf( pid_string, 20, "%lu\n", (unsigned long)getpid( ) ); bytes_writen = write( pidfile->fd, pid_string, strlen( pid_string ) ); if( bytes_writen < 0 ) { - LOG( log_EMERG, "Unable to write PID into the pidfile '%s': %s", pidfile->filename, strerror( errno ) ); + WOLF_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 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 ); + WOLF_LOG( log_EMERG, "Non-atomic write failed when storing the PID into the pidfile '%s'", pidfile->filename ); } - LOG( log_DEBUG, "Stored '%lu' into the pidfile '%s' and locked it", (unsigned long)getpid( ), pidfile->filename ); + WOLF_LOG( log_DEBUG, "Stored '%lu' into the pidfile '%s' and locked it", (unsigned long)getpid( ), pidfile->filename ); pidfile->locked = true; @@ -203,12 +203,12 @@ wolf_error_t pidfile_create( struct pidfile_t *pidfile ) { 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)", + WOLF_LOG( log_DEBUG, "Releasing (unlocking/closing) pidfile '%s' (fd: %d, locked: %d)", pidfile->filename, pidfile->fd, pidfile->locked ); if( pidfile->locked ) { if( lockf( pidfile->fd, F_ULOCK, (off_t)0 ) < 0 ) { - LOG( log_ALERT, "Unable to unlock the pidfile '%s': %s (%d)", + WOLF_LOG( log_ALERT, "Unable to unlock the pidfile '%s': %s (%d)", pidfile->filename, strerror( errno ), errno ); error = WOLF_ERR_INTERNAL; } @@ -216,7 +216,7 @@ wolf_error_t pidfile_release( struct pidfile_t *pidfile ) { if( pidfile->fd >= 0 ) { if( close( pidfile->fd ) < 0 ) { - LOG( log_ALERT, "Unable to close the pidfile '%s': %s (%d)", + WOLF_LOG( log_ALERT, "Unable to close the pidfile '%s': %s (%d)", pidfile->filename, strerror( errno ), errno ); error = WOLF_ERR_INTERNAL; } @@ -229,13 +229,13 @@ wolf_error_t pidfile_release( struct pidfile_t *pidfile ) { 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)", + WOLF_LOG( log_DEBUG, "Removing pidfile '%s' (fd: %d, locked: %d, running: %d)", pidfile->filename, pidfile->fd, pidfile->locked, pidfile->running ); /* unconditionally remove the pidfile */ if( unlink( pidfile->filename ) < 0 ) { - LOG( log_ALERT, "Unable to remove the pidfile '%s': %s (%d)", + WOLF_LOG( log_ALERT, "Unable to remove the pidfile '%s': %s (%d)", pidfile->filename, strerror( errno ), errno ); error = WOLF_ERR_INTERNAL; } |