summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2008-12-21 17:09:49 +0100
committerAndreas Baumann <abaumann@yahoo.com>2008-12-21 17:09:49 +0100
commit07bbb6aa8857a2fbc77d6db6b6d1e7bafb7d0976 (patch)
treed99410ede29d8f09f35351cc1beeb0866082ae57
parent01e67d010b9badcf2ffc65d74b0f9285f26d45e5 (diff)
downloadwolfbones-07bbb6aa8857a2fbc77d6db6b6d1e7bafb7d0976.tar.gz
wolfbones-07bbb6aa8857a2fbc77d6db6b6d1e7bafb7d0976.tar.bz2
making log a little bit less leaking Unixisms
-rw-r--r--include/log.h66
-rw-r--r--include/port/stdbool.h (renamed from src/port/stdbool.h)2
-rw-r--r--include/port/sys.h (renamed from src/port/sys.h)0
-rw-r--r--include/port/unused.h (renamed from src/port/unused.h)0
-rw-r--r--src/daemon/daemon.c86
-rw-r--r--src/daemon/pidfile.c44
-rw-r--r--src/daemon/signals.c24
-rw-r--r--src/log.c115
-rw-r--r--src/log.h60
-rw-r--r--src/port/limits.h2
-rw-r--r--src/port/lockf.h2
-rw-r--r--src/port/snprintf.h2
-rw-r--r--src/port/stdint.h2
-rw-r--r--src/port/stdio.h2
-rw-r--r--src/port/string.h2
-rw-r--r--src/port/unistd.h2
-rw-r--r--tests/GNUmakefile12
-rw-r--r--tests/daemon/GNUmakefile42
-rw-r--r--tests/daemon/testd.c20
19 files changed, 285 insertions, 200 deletions
diff --git a/include/log.h b/include/log.h
new file mode 100644
index 0000000..58f9cbf
--- /dev/null
+++ b/include/log.h
@@ -0,0 +1,66 @@
+#ifndef __LOG_H
+#define __LOG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define log_EMERG 0 /* system is unusable */
+#define log_ALERT 1 /* action must be taken immediately */
+#define log_CRIT 2 /* critical conditions */
+#define log_ERR 3 /* error conditions */
+#define log_WARNING 4 /* warning conditions */
+#define log_NOTICE 5 /* normal but significant condition */
+#define log_INFO 6 /* informational */
+#define log_DEBUG 7 /* debug-level messages */
+
+#define log_DEBUG1 ( log_DEBUG + 1 )
+#define log_DEBUG2 ( log_DEBUG + 2 )
+#define log_DEBUG3 ( log_DEBUG + 3 )
+#define log_DEBUG4 ( log_DEBUG + 4 )
+#define log_DEBUG5 ( log_DEBUG + 5 )
+
+#define log_KERN (0<<3) /* kernel messages */
+#define log_USER (1<<3) /* random user-level messages */
+#define log_MAIL (2<<3) /* mail system */
+#define log_DAEMON (3<<3) /* system daemons */
+#define log_AUTH (4<<3) /* security/authorization messages */
+#define log_SYSLOG (5<<3) /* messages generated internally by syslogd */
+#define log_LPR (6<<3) /* line printer subsystem */
+#define log_NEWS (7<<3) /* network news subsystem */
+#define log_UUCP (8<<3) /* UUCP subsystem */
+#define log_CRON (9<<3) /* clock daemon */
+#define log_AUTHPRIV (10<<3) /* security/authorization messages (private) */
+#define log_FTP (11<<3) /* ftp daemon */
+
+const char *log_syslog_facility_to_str( int facility );
+
+int log_str_to_syslog_facility( const char *facility );
+
+const char *log_level_to_str( int level );
+
+int log_str_to_level( const char *level );
+
+void openlogtofile( const char *filename, int level );
+
+void openlogtosyslog( const char *ident, int facility, int level );
+
+void openlogtostderr( int level );
+
+void closelogtofile( void );
+
+void closelogtosyslog( void );
+
+void closelogtostderr( void );
+
+void reopenlogtofile( void );
+
+void reopenlogtosyslog( void );
+
+void LOG( int level, const char *format, ... );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/port/stdbool.h b/include/port/stdbool.h
index 9c011e4..e17c657 100644
--- a/src/port/stdbool.h
+++ b/include/port/stdbool.h
@@ -1,7 +1,7 @@
#ifndef __STDBOOL_H
#define __STDBOOL_H
-#include "sys.h"
+#include "port/sys.h"
/* C99 Boolean types for compilers without C99 support, see
* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
diff --git a/src/port/sys.h b/include/port/sys.h
index 65b68e2..65b68e2 100644
--- a/src/port/sys.h
+++ b/include/port/sys.h
diff --git a/src/port/unused.h b/include/port/unused.h
index c7692f6..c7692f6 100644
--- a/src/port/unused.h
+++ b/include/port/unused.h
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f3a9e1c..bbc554c 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -75,7 +75,7 @@ static error_t close_fd( int fd ) {
break;
default:
- LOG( LOG_EMERG, "Error while closing file descriptor %d: %s (%d)",
+ LOG( log_EMERG, "Error while closing file descriptor %d: %s (%d)",
fd, strerror( errno ), errno );
return ERR_INTERNAL;
}
@@ -102,11 +102,11 @@ static error_t daemon_close_all_fds( void ) {
nof_files = sysconf( _SC_OPEN_MAX );
if( nof_files < 0 ) {
- LOG( LOG_EMERG, "Unable to retrieve maximal number of files: %s (%d)",
+ LOG( log_EMERG, "Unable to retrieve maximal number of files: %s (%d)",
strerror( errno ), errno );
return ERR_INTERNAL;
}
- LOG( LOG_DEBUG, "Closing all filedescriptors up to %ld", nof_files );
+ LOG( log_DEBUG, "Closing all filedescriptors up to %ld", nof_files );
for( i = 0; i < nof_files; i++ ) {
if( ( i == STDIN_FILENO ) ||
@@ -131,12 +131,12 @@ static error_t open_null_fd( int must_fd, int flags ) {
fd = open( "/dev/null", flags );
if( fd < 0 ) {
- LOG( LOG_EMERG, "Unable to open fd %d as /dev/null: %s (%d)",
+ LOG( log_EMERG, "Unable to open fd %d as /dev/null: %s (%d)",
must_fd, strerror( errno ), errno );
return ERR_INTERNAL;
}
if( fd != must_fd ) {
- LOG( LOG_EMERG, "Something is wrong with the file descriptors (expecting %d,got %d)!",
+ LOG( log_EMERG, "Something is wrong with the file descriptors (expecting %d,got %d)!",
must_fd, fd );
return ERR_PROGRAMMING;
}
@@ -151,10 +151,10 @@ atomar_write_again:
res = write( fd, data, data_len );
if( res < 0 ) {
if( errno == EINTR ) goto atomar_write_again;
- LOG( LOG_EMERG, "Error in atomar write to fd %d: %s (%d)",
+ LOG( log_EMERG, "Error in atomar write to fd %d: %s (%d)",
fd, strerror( errno ), errno );
} else if( (size_t)res != data_len ) {
- LOG( LOG_EMERG, "Unexpected number of octets %zd in atomar write to fd %d (expected %zd)",
+ LOG( log_EMERG, "Unexpected number of octets %zd in atomar write to fd %d (expected %zd)",
res, fd, data_len );
}
}
@@ -166,10 +166,10 @@ atomar_read_again:
res = read( fd, data, data_len );
if( res < 0 ) {
if( errno == EINTR ) goto atomar_read_again;
- LOG( LOG_EMERG, "Error in atmoar read from fd %d: %s (%d)",
+ LOG( log_EMERG, "Error in atmoar read from fd %d: %s (%d)",
fd, strerror( errno ), errno );
} else if( (size_t)res != data_len ) {
- LOG( LOG_EMERG, "Unexpected number of octets %zd in atomar read from fd %d (expected %zd)",
+ LOG( log_EMERG, "Unexpected number of octets %zd in atomar read from fd %d (expected %zd)",
res, fd, data_len );
}
}
@@ -185,7 +185,7 @@ error_t daemon_start( daemon_p d ) {
* error..
*/
if( getppid( ) == 1 ) {
- LOG( LOG_EMERG, "Already running as daemon!" );
+ LOG( log_EMERG, "Already running as daemon!" );
return( d->error = ERR_PROGRAMMING );
}
@@ -196,7 +196,7 @@ error_t daemon_start( daemon_p d ) {
* we must be root (uid 0 by convention) for that.
*/
if( geteuid( ) != 0 ) {
- LOG( LOG_EMERG, "Unable to start daemon as not root user!" );
+ LOG( log_EMERG, "Unable to start daemon as not root user!" );
return( d->error = ERR_INVALID_STATE );
}
@@ -221,11 +221,11 @@ error_t daemon_start( daemon_p d ) {
* itself back to the grand-parent (exit codes).
*/
if( pipe( exit_code_pipe ) < 0 ) {
- LOG( LOG_EMERG, "Unable to create exit code pipe: %s (%d)",
+ LOG( log_EMERG, "Unable to create exit code pipe: %s (%d)",
strerror( errno ), errno );
return ( d->error = ERR_INTERNAL );
}
- LOG( LOG_DEBUG, "Created exit code pipe (%d,%d)", exit_code_pipe[0], exit_code_pipe[1] );
+ LOG( log_DEBUG, "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
@@ -233,12 +233,12 @@ error_t daemon_start( daemon_p d ) {
switch( ( pid = fork( ) ) ) {
case -1:
/* error */
- LOG( LOG_EMERG, "Unable to fork the first time: %s", strerror( errno ) );
+ LOG( log_EMERG, "Unable to fork the first time: %s", strerror( errno ) );
return ( d->error = ERR_INTERNAL );
case 0:
/* the child becomes the daemon */
- LOG( LOG_DEBUG, "First fork reached" );
+ LOG( log_DEBUG, "First fork reached" );
break;
default:
@@ -248,7 +248,7 @@ error_t daemon_start( daemon_p d ) {
/* TODO: wait for some time for correct exit
* code from the error pipe
*/
- LOG( LOG_DEBUG, "Parent after first fork: child is %d", pid );
+ LOG( log_DEBUG, "Parent after first fork: child is %d", pid );
return ( d->error = TERMINATE_EXIT_CODE );
}
@@ -256,11 +256,11 @@ error_t daemon_start( daemon_p d ) {
* (for termination and cleanup which can only be done as root)
*/
if( pipe( daemon_parent_pipe ) < 0 ) {
- LOG( LOG_EMERG, "Unable to create parent pipe: %s (%d)",
+ LOG( log_EMERG, "Unable to create parent pipe: %s (%d)",
strerror( errno ), errno );
return ( d->error = ERR_INTERNAL );
}
- LOG( LOG_DEBUG, "Created parent pipe (%d,%d)", daemon_parent_pipe[0], daemon_parent_pipe[1] );
+ LOG( log_DEBUG, "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
@@ -268,7 +268,7 @@ error_t daemon_start( daemon_p d ) {
*/
if( setsid( ) < 0 ) {
/* should actually never fail */
- LOG( LOG_EMERG, "Starting new process group session for the parent of the daemon failed: %s", strerror( errno ) );
+ LOG( log_EMERG, "Starting new process group session for the parent of the daemon failed: %s", strerror( errno ) );
return ERR_INTERNAL;
}
@@ -295,17 +295,17 @@ error_t daemon_start( daemon_p d ) {
switch( ( pid = fork( ) ) ) {
case -1:
/* error */
- LOG( LOG_EMERG, "Unable to fork the second time: %s", strerror( errno ) );
+ LOG( log_EMERG, "Unable to fork the second time: %s", strerror( errno ) );
return ( d->error = ERR_INTERNAL );
case 0:
/* the child becomes the daemon */
- LOG( LOG_DEBUG, "Second fork reached" );
+ LOG( log_DEBUG, "Second fork reached" );
break;
default:
(void)signal_install_handlers_parent( );
- LOG( LOG_DEBUG, "Parent after second fork: child (and daemon) is %d", pid );
+ LOG( log_DEBUG, "Parent after second fork: child (and daemon) is %d", pid );
return ( d->error = TERMINATE_PARENT );
}
@@ -321,7 +321,7 @@ error_t daemon_start( daemon_p d ) {
*/
if( setsid( ) < 0 ) {
/* should actually never fail */
- LOG( LOG_EMERG, "Starting new process group for daemon session failed: %s", strerror( errno ) );
+ LOG( log_EMERG, "Starting new process group for daemon session failed: %s", strerror( errno ) );
return ERR_INTERNAL;
}
@@ -334,10 +334,10 @@ error_t daemon_start( daemon_p d ) {
* directory (especially they can't write files there)
*/
if( chdir( "/" ) < 0 ) {
- LOG( LOG_EMERG, "Changing to root diretory failed: %s", strerror( errno ) );
+ LOG( log_EMERG, "Changing to root diretory failed: %s", strerror( errno ) );
return ERR_INTERNAL;
}
- LOG( LOG_DEBUG, "Changed to root directory /" );
+ LOG( log_DEBUG, "Changed to root directory /" );
/* Change the umask to 0133 temporarily so we don't have to
* chmod the logfiles, pidfiles later.
@@ -345,12 +345,12 @@ error_t daemon_start( daemon_p d ) {
* Create pid files with permissions 0644 (rw-r--r--)
*/
mode = umask( 0133 );
- LOG( LOG_DEBUG, "Switched umask from %04o to %04o", mode, 0133 );
+ LOG( log_DEBUG, "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 != OK ) ) {
if( error == OK ) {
- LOG( LOG_EMERG, "Another daemon is already running with pid '%d', can't start!", pid );
+ LOG( log_EMERG, "Another daemon is already running with pid '%d', can't start!", pid );
}
return ERR_INTERNAL;
}
@@ -386,7 +386,7 @@ error_t daemon_start( daemon_p d ) {
* New files always get the permission 640 (rw-r-----)
*/
mode = umask( 0137 );
- LOG( LOG_DEBUG, "Switched umask from %04o to %04o", mode, 0137 );
+ LOG( log_DEBUG, "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 ) ) {
@@ -394,9 +394,9 @@ error_t daemon_start( daemon_p d ) {
d->groupent = getgrnam( d->params.group_name );
if( d->groupent == NULL ) {
if( errno == 0 ) {
- LOG( LOG_EMERG, "No group '%s' found", d->params.group_name );
+ LOG( log_EMERG, "No group '%s' found", d->params.group_name );
} else {
- LOG( LOG_EMERG, "Unable to retrieve group information for group '%s': %s (%d)",
+ LOG( log_EMERG, "Unable to retrieve group information for group '%s': %s (%d)",
d->params.group_name, strerror( errno ), errno );
}
return ERR_INTERNAL;
@@ -406,22 +406,22 @@ error_t daemon_start( daemon_p d ) {
d->userent = getpwnam( d->params.user_name );
if( d->userent == NULL ) {
if( errno == 0 ) {
- LOG( LOG_EMERG, "No user '%s' found", d->params.user_name );
+ LOG( log_EMERG, "No user '%s' found", d->params.user_name );
} else {
- LOG( LOG_EMERG, "Unable to retrieve user information for user '%s': %s (%d)",
+ LOG( log_EMERG, "Unable to retrieve user information for user '%s': %s (%d)",
d->params.user_name, strerror( errno ), errno );
}
return ERR_INTERNAL;
}
if( setgid( d->userent->pw_gid ) < 0 ) {
- LOG( LOG_EMERG, "Setting unprivileged group failed: %s (%d)",
+ LOG( log_EMERG, "Setting unprivileged group failed: %s (%d)",
strerror( errno ), errno );
return ERR_INTERNAL;
}
if( setuid( d->userent->pw_uid ) < 0 ) {
- LOG( LOG_EMERG, "Setting unprivileged user failed: %s (%d)",
+ LOG( log_EMERG, "Setting unprivileged user failed: %s (%d)",
strerror( errno ), errno );
return ERR_INTERNAL;
}
@@ -430,7 +430,7 @@ error_t daemon_start( daemon_p d ) {
/* TODO: also check the permissions of the home dir
* of the unpriviledged user */
- LOG( LOG_DEBUG, "Switched to user '%s' (%d) and group '%s' (%d)",
+ LOG( log_DEBUG, "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 );
}
@@ -458,7 +458,7 @@ NORETURN void daemon_exit( daemon_p d ) {
int exit_code;
int pid_file_fd;
- LOG( LOG_DEBUG, "daemon_exit called with error %d", d->error );
+ LOG( log_DEBUG, "daemon_exit called with error %d", d->error );
switch( d->error ) {
case TERMINATE_EXIT_CODE:
@@ -466,11 +466,11 @@ NORETURN void daemon_exit( daemon_p d ) {
* so we can return the correct exit code to
* the calling script or shell
*/
- LOG( LOG_DEBUG, "Waiting on exit_code pipe for exit code" );
+ LOG( log_DEBUG, "Waiting on exit_code pipe for exit code" );
atomar_read( exit_code_pipe[0], &exit_code, sizeof( int ) );
- LOG( LOG_DEBUG, "Terminating grand-parent of daemon with code %d (PID: %lu)",
+ LOG( log_DEBUG, "Terminating grand-parent of daemon with code %d (PID: %lu)",
exit_code, getpid( ) );
signal_terminate( );
@@ -486,10 +486,10 @@ NORETURN void daemon_exit( daemon_p d ) {
*/
/* wait for termination signal */
- LOG( LOG_DEBUG, "Waiting on parent pipe for termination signal" );
+ LOG( log_DEBUG, "Waiting on parent pipe for termination signal" );
atomar_read( daemon_parent_pipe[0], &pid_file_fd, sizeof( int ) );
- LOG( LOG_DEBUG, "Parent got termination (pidfile fd: %d).. cleaning up now (PID: %lu)",
+ LOG( log_DEBUG, "Parent got termination (pidfile fd: %d).. cleaning up now (PID: %lu)",
pid_file_fd, getpid( ) );
/* we need root permissions for that! */
@@ -498,7 +498,7 @@ NORETURN void daemon_exit( daemon_p d ) {
signal_terminate( );
- LOG( LOG_DEBUG, "Terminating parent of daemon pid file fd %d (PID %lu)",
+ LOG( log_DEBUG, "Terminating parent of daemon pid file fd %d (PID %lu)",
pid_file_fd, getpid( ) );
/* exit code is irrelevant here.. */
@@ -515,7 +515,7 @@ NORETURN void daemon_exit( daemon_p d ) {
signal_terminate( );
- LOG( LOG_DEBUG, "Terminating daemon (PID: %lu)", getpid( ) );
+ LOG( log_DEBUG, "Terminating daemon (PID: %lu)", getpid( ) );
/* exit code is irrelevant here */
_exit( EXIT_SUCCESS );
@@ -539,7 +539,7 @@ NORETURN void daemon_exit( daemon_p d ) {
signal_terminate( );
- LOG( LOG_DEBUG, "Terminating daemon (PID: %lu)", getpid( ) );
+ LOG( log_DEBUG, "Terminating daemon (PID: %lu)", getpid( ) );
/* exit code is irrelevant here */
_exit( EXIT_SUCCESS );
diff --git a/src/daemon/pidfile.c b/src/daemon/pidfile.c
index 3c5f42a..53f81c9 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, error_t *error )
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 );
+ LOG( log_DEBUG, "No pidfile '%s' found, daemon is not running", pidfile->filename );
(void)close( pidfile->fd );
*error = OK;
return pidfile->running;
} else {
- LOG( LOG_EMERG, "Unable to open pidfile '%s' for reading: %s", pidfile->filename, strerror( errno ) );
+ LOG( log_EMERG, "Unable to open pidfile '%s' for reading: %s", pidfile->filename, strerror( errno ) );
*error = ERR_INTERNAL;
return pidfile->running;
}
@@ -69,12 +69,12 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error )
if( res < 0 ) {
if( errno == EAGAIN ) {
/* another process locks the file already */
- LOG( LOG_DEBUG, "Another process locks the pidfile, daemon already running" );
+ LOG( log_DEBUG, "Another process locks the pidfile, daemon already running" );
*error = OK;
pidfile->locked = true;
pidfile->running = true;
} else {
- LOG( LOG_EMERG, "Unable to lock pidfile '%s': %s", pidfile->filename, strerror( errno ) );
+ LOG( log_EMERG, "Unable to lock pidfile '%s': %s", pidfile->filename, strerror( errno ) );
(void)close( pidfile->fd );
*error = ERR_INTERNAL;
pidfile->running = false;
@@ -87,7 +87,7 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error )
/* 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 ) );
+ LOG( log_EMERG, "Unable to read pid from pidfile '%s': %s", pidfile->filename, strerror( errno ) );
(void)close( pidfile->fd );
*error = ERR_INTERNAL;
return pidfile->running;
@@ -103,12 +103,12 @@ bool is_daemon_running( struct pidfile_t *pidfile, pid_t *pid, error_t *error )
( 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 );
+ LOG( log_EMERG, "pidfile '%s' contains invalid data, can't read PID from it!", pidfile->filename );
(void)close( pidfile->fd );
*error = ERR_INTERNAL;
return pidfile->running;
}
- LOG( LOG_DEBUG, "Found PID '%lu' in pidfile", *pid );
+ 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, error_t *error )
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 );
+ 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;
return pidfile->running;
} else {
- LOG( LOG_EMERG, "Can't check if processor with PID '%lu' is alive: %s", *pid, strerror( errno ) );
+ LOG( log_EMERG, "Can't check if processor with PID '%lu' is alive: %s", *pid, strerror( errno ) );
(void)close( pidfile->fd );
*error = ERR_INTERNAL;
return pidfile->running;
}
}
- LOG( LOG_DEBUG, "A process with PID '%lu' is already running", *pid );
+ 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 @@ 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 ) );
+ LOG( log_EMERG, "Unable to open pidfile '%s' for writing: %s", pidfile->filename, strerror( errno ) );
return ERR_INTERNAL;
}
@@ -157,12 +157,12 @@ 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 );
+ 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;
} else {
- LOG( LOG_EMERG, "Unable to lock pidfile '%s' after creation: %s", pidfile->filename, strerror( errno ) );
+ 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;
@@ -173,7 +173,7 @@ 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 ) );
+ 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;
@@ -185,15 +185,15 @@ 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 ) );
+ 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;
} 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 );
+ 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 );
+ LOG( log_DEBUG, "Stored '%lu' into the pidfile '%s' and locked it", (unsigned long)getpid( ), pidfile->filename );
pidfile->locked = true;
@@ -203,12 +203,12 @@ error_t pidfile_create( struct pidfile_t *pidfile ) {
error_t pidfile_release( struct pidfile_t *pidfile ) {
error_t error = OK;
- LOG( LOG_DEBUG, "Releasing (unlocking/closing) pidfile '%s' (fd: %d, locked: %d)",
+ 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)",
+ LOG( log_ALERT, "Unable to unlock the pidfile '%s': %s (%d)",
pidfile->filename, strerror( errno ), errno );
error = ERR_INTERNAL;
}
@@ -216,7 +216,7 @@ 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)",
+ LOG( log_ALERT, "Unable to close the pidfile '%s': %s (%d)",
pidfile->filename, strerror( errno ), errno );
error = ERR_INTERNAL;
}
@@ -229,13 +229,13 @@ error_t pidfile_release( struct pidfile_t *pidfile ) {
error_t pidfile_remove( struct pidfile_t *pidfile ) {
error_t error = OK;
- LOG( LOG_DEBUG, "Removing pidfile '%s' (fd: %d, locked: %d, running: %d)",
+ 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)",
+ LOG( log_ALERT, "Unable to remove the pidfile '%s': %s (%d)",
pidfile->filename, strerror( errno ), errno );
error = ERR_INTERNAL;
}
diff --git a/src/daemon/signals.c b/src/daemon/signals.c
index ca1024e..253c2ab 100644
--- a/src/daemon/signals.c
+++ b/src/daemon/signals.c
@@ -163,7 +163,7 @@ install_ignore_again:
if( sigaction( sig, &sa, NULL ) < 0 ) {
(void)strerror_r( errno, errbuf, 1024 );
- LOG( LOG_CRIT, "Can't ignore signal handler for signal '%s' (%s, %d): %s (errno: %d)",
+ LOG( log_CRIT, "Can't ignore signal handler for signal '%s' (%s, %d): %s (errno: %d)",
signal_get_long_name( sig ),
signal_get_short_name( sig ),
sig,
@@ -171,7 +171,7 @@ install_ignore_again:
errno );
return ERR_PROGRAMMING;
}
- LOG( LOG_DEBUG, "Ignoring signal handler for signal '%s' (%s)",
+ LOG( log_DEBUG, "Ignoring signal handler for signal '%s' (%s)",
signal_get_long_name( sig ),
signal_get_short_name( sig ) );
sig = va_arg( ap, int );
@@ -198,7 +198,7 @@ install_empty_again:
if( sigaction( sig, &sa, NULL ) < 0 ) {
(void)strerror_r( errno, errbuf, 1024 );
- LOG( LOG_CRIT, "Can't install empty signal handler for signal '%s' (%s, %d): %s (errno: %d)",
+ LOG( log_CRIT, "Can't install empty signal handler for signal '%s' (%s, %d): %s (errno: %d)",
signal_get_long_name( sig ),
signal_get_short_name( sig ),
sig,
@@ -206,7 +206,7 @@ install_empty_again:
errno );
return ERR_PROGRAMMING;
}
- LOG( LOG_DEBUG, "Installed empty signal handler for signal '%s' (%s)",
+ LOG( log_DEBUG, "Installed empty signal handler for signal '%s' (%s)",
signal_get_long_name( sig ),
signal_get_short_name( sig ) );
sig = va_arg( ap, int );
@@ -224,7 +224,7 @@ static void fatal_handler( int sig ) {
(void)sigaction( sig, &sa, NULL );
/* log what happened */
- LOG( LOG_ALERT, "Got signal '%s' (%s)",
+ LOG( log_ALERT, "Got signal '%s' (%s)",
signal_get_long_name( sig ),
signal_get_short_name( sig ) );
@@ -246,7 +246,7 @@ install_func_again:
if( sigaction( sig, &sa, NULL ) < 0 ) {
(void)strerror_r( errno, errbuf, 1024 );
- LOG( LOG_CRIT, "Can't install signal handler for signal '%s' (%s, %d): %s (errno: %d)",
+ LOG( log_CRIT, "Can't install signal handler for signal '%s' (%s, %d): %s (errno: %d)",
signal_get_long_name( sig ),
signal_get_short_name( sig ),
sig,
@@ -254,7 +254,7 @@ install_func_again:
errno );
return ERR_PROGRAMMING;
}
- LOG( LOG_DEBUG, "Installed signal handler for signal '%s' (%s)",
+ LOG( log_DEBUG, "Installed signal handler for signal '%s' (%s)",
signal_get_long_name( sig ),
signal_get_short_name( sig ) );
sig = va_arg( ap, int );
@@ -324,11 +324,11 @@ error_t signal_initialize( void ) {
res = pipe( daemon_signal_pipe );
if( res < 0 ) {
(void)strerror_r( errno, errbuf, 1024 );
- LOG( LOG_EMERG, "Unable to create signal pipe: %s (%d)",
+ LOG( log_EMERG, "Unable to create signal pipe: %s (%d)",
errbuf, errno );
return ERR_INTERNAL;
}
- LOG( LOG_DEBUG, "Created signal pipe (%d,%d)", daemon_signal_pipe[0], daemon_signal_pipe[1] );
+ LOG( log_DEBUG, "Created signal pipe (%d,%d)", daemon_signal_pipe[0], daemon_signal_pipe[1] );
return OK;
}
@@ -371,7 +371,7 @@ signal_select_again:
/* gdb no-brainer when pressing Ctrl-C (at least Linux) */
if( errno == 514 ) goto signal_select_again;
(void)strerror_r( errno, errbuf, 1024 );
- LOG( LOG_EMERG, "Error in select when waiting for signal from pipe: %s (%d)",
+ LOG( log_EMERG, "Error in select when waiting for signal from pipe: %s (%d)",
errbuf, errno );
*error = ERR_INTERNAL;
return -1;
@@ -384,13 +384,13 @@ signal_select_again:
case -1: /* error */
(void)strerror_r( errno, errbuf, 1024 );
- LOG( LOG_EMERG, "Error while reading a signal from the pipe: %s (%d)",
+ LOG( log_EMERG, "Error while reading a signal from the pipe: %s (%d)",
errbuf, errno );
*error = ERR_INTERNAL;
return -1;
default: /* unexpected result on atomic read */
- LOG( LOG_EMERG, "Unexpected error in read: result is %d", res );
+ LOG( log_EMERG, "Unexpected error in read: result is %d", res );
*error = ERR_PROGRAMMING;
return -1;
}
diff --git a/src/log.c b/src/log.c
index a004e79..c8d7ca2 100644
--- a/src/log.c
+++ b/src/log.c
@@ -6,6 +6,8 @@
#include <stdarg.h> /* for variable arguments */
#include <errno.h> /* for errno */
+#include <syslog.h> /* for syslog, closelog and levels */
+
const char *log_syslog_facility_to_str( int facility ) {
switch( facility ) {
case LOG_KERN: return "KERN";
@@ -24,7 +26,7 @@ const char *log_syslog_facility_to_str( int facility ) {
#if defined LOG_FTP
case LOG_FTP: return "FTP";
#endif
- default: return "<unknown";
+ default: return "<unknown>";
}
}
@@ -49,41 +51,86 @@ int log_str_to_syslog_facility( const char *facility ) {
return LOG_DAEMON;
}
-const char *log_level_to_str( int level ) {
+int log_str_to_level( const char *level ) {
+ if( strcmp( level, "EMERG" ) == 0 ) return log_EMERG;
+ if( strcmp( level, "ALERT" ) == 0 ) return log_ALERT;
+ if( strcmp( level, "CRIT" ) == 0 ) return log_CRIT;
+ if( strcmp( level, "ERR" ) == 0 ) return log_ERR;
+ if( strcmp( level, "WARNING" ) == 0 ) return log_WARNING;
+ if( strcmp( level, "NOTICE" ) == 0 ) return log_NOTICE;
+ if( strcmp( level, "INFO" ) == 0 ) return log_INFO;
+ if( strcmp( level, "DEBUG" ) == 0 ) return log_DEBUG;
+ if( strcmp( level, "DEBUG1" ) == 0 ) return log_DEBUG1;
+ if( strcmp( level, "DEBUG2" ) == 0 ) return log_DEBUG2;
+ if( strcmp( level, "DEBUG3" ) == 0 ) return log_DEBUG3;
+ if( strcmp( level, "DEBUG4" ) == 0 ) return log_DEBUG4;
+ if( strcmp( level, "DEBUG5" ) == 0 ) return log_DEBUG5;
+
+ return log_NOTICE;
+}
+
+static int map_log_to_syslog_level( int level ) {
switch( level ) {
- case LOG_EMERG: return "EMERG";
- case LOG_ALERT: return "ALERT";
- case LOG_CRIT: return "CRIT";
- case LOG_ERR: return "ERR";
- case LOG_WARNING: return "WARNING";
- case LOG_NOTICE: return "NOTICE";
- case LOG_INFO: return "INFO";
- case LOG_DEBUG: return "DEBUG";
- case LOG_DEBUG1: return "DEBUG1";
- case LOG_DEBUG2: return "DEBUG2";
- case LOG_DEBUG3: return "DEBUG3";
- case LOG_DEBUG4: return "DEBUG4";
- case LOG_DEBUG5: return "DEBUG5";
- default: return "<unknown>";
+ case log_EMERG: return LOG_EMERG;
+ case log_ALERT: return LOG_ALERT;
+ case log_CRIT: return LOG_CRIT;
+ case log_ERR: return LOG_ERR;
+ case log_WARNING: return LOG_WARNING;
+ case log_NOTICE: return LOG_NOTICE;
+ case log_INFO: return LOG_INFO;
+ case log_DEBUG:
+ case log_DEBUG1:
+ case log_DEBUG2:
+ case log_DEBUG3:
+ case log_DEBUG4:
+ case log_DEBUG5: return LOG_DEBUG;
+ default: return LOG_EMERG;
}
}
-int log_str_to_level( const char *level ) {
- if( strcmp( level, "EMERG" ) == 0 ) return LOG_EMERG;
- if( strcmp( level, "ALERT" ) == 0 ) return LOG_ALERT;
- if( strcmp( level, "CRIT" ) == 0 ) return LOG_CRIT;
- if( strcmp( level, "ERR" ) == 0 ) return LOG_ERR;
- if( strcmp( level, "WARNING" ) == 0 ) return LOG_WARNING;
- if( strcmp( level, "NOTICE" ) == 0 ) return LOG_NOTICE;
- if( strcmp( level, "INFO" ) == 0 ) return LOG_INFO;
- if( strcmp( level, "DEBUG" ) == 0 ) return LOG_DEBUG;
- if( strcmp( level, "DEBUG1" ) == 0 ) return LOG_DEBUG1;
- if( strcmp( level, "DEBUG2" ) == 0 ) return LOG_DEBUG2;
- if( strcmp( level, "DEBUG3" ) == 0 ) return LOG_DEBUG3;
- if( strcmp( level, "DEBUG4" ) == 0 ) return LOG_DEBUG4;
- if( strcmp( level, "DEBUG5" ) == 0 ) return LOG_DEBUG5;
-
- return LOG_NOTICE;
+static int map_log_facility_to_syslog_facility( int facility ) {
+ switch( facility ) {
+ case log_KERN: return LOG_KERN;
+ case log_USER: return LOG_USER;
+ case log_MAIL: return LOG_MAIL;
+ case log_DAEMON: return LOG_DAEMON;
+ case log_AUTH: return LOG_AUTH;
+ case log_SYSLOG: return LOG_SYSLOG;
+ case log_LPR: return LOG_LPR;
+ case log_NEWS: return LOG_NEWS;
+ case log_UUCP: return LOG_UUCP;
+ case log_CRON: return LOG_CRON;
+#if defined LOG_AUTHPRIV
+ case log_AUTHPRIV: return LOG_AUTHPRIV;
+#else
+ case log_AUTHPRIV: return LOG_DAEMON;
+#endif
+#if defined LOG_FTP
+ case log_FTP: return LOG_FTP;
+#else
+ case log_FTP: return LOG_DAEMON;
+#endif
+ default: return LOG_DAEMON;
+ }
+}
+
+const char *log_level_to_str( int level ) {
+ switch( level ) {
+ case log_EMERG: return "EMERG";
+ case log_ALERT: return "ALERT";
+ case log_CRIT: return "CRIT";
+ case log_ERR: return "ERR";
+ case log_WARNING: return "WARNING";
+ case log_NOTICE: return "NOTICE";
+ case log_INFO: return "INFO";
+ case log_DEBUG: return "DEBUG";
+ case log_DEBUG1: return "DEBUG1";
+ case log_DEBUG2: return "DEBUG2";
+ case log_DEBUG3: return "DEBUG3";
+ case log_DEBUG4: return "DEBUG4";
+ case log_DEBUG5: return "DEBUG5";
+ default: return "<unknown>";
+ }
}
static const char *log_logfile_filename;
@@ -104,8 +151,8 @@ void openlogtosyslog( const char *ident, int facility, int level ) {
openlog( ident, LOG_CONS | LOG_NDELAY, facility );
setlogmask( LOG_UPTO( level ) );
syslog_ident = ident;
- syslog_facility = facility;
- syslog_level = level;
+ syslog_facility = map_log_facility_to_syslog_facility( facility );
+ syslog_level = map_log_to_syslog_level( level );
}
void openlogtostderr( int level ) {
diff --git a/src/log.h b/src/log.h
deleted file mode 100644
index f6c0534..0000000
--- a/src/log.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef __LOG_H
-#define __LOG_H
-
-#include "port/sys.h"
-
-#include <syslog.h> /* for syslog, closelog and levels */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if 0
-/* defined in syslog.h */
-#define LOG_EMERG 0 /* system is unusable */
-#define LOG_ALERT 1 /* action must be taken immediately */
-#define LOG_CRIT 2 /* critical conditions */
-#define LOG_ERR 3 /* error conditions */
-#define LOG_WARNING 4 /* warning conditions */
-#define LOG_NOTICE 5 /* normal but significant condition */
-#define LOG_INFO 6 /* informational */
-#define LOG_DEBUG 7 /* debug-level messages */
-#endif
-
-#define LOG_DEBUG1 ( LOG_DEBUG + 1 )
-#define LOG_DEBUG2 ( LOG_DEBUG + 2 )
-#define LOG_DEBUG3 ( LOG_DEBUG + 3 )
-#define LOG_DEBUG4 ( LOG_DEBUG + 4 )
-#define LOG_DEBUG5 ( LOG_DEBUG + 5 )
-
-const char *log_syslog_facility_to_str( int facility );
-
-int log_str_to_syslog_facility( const char *facility );
-
-const char *log_level_to_str( int level );
-
-int log_str_to_level( const char *level );
-
-void openlogtofile( const char *filename, int level );
-
-void openlogtosyslog( const char *ident, int facility, int level );
-
-void openlogtostderr( int level );
-
-void closelogtofile( void );
-
-void closelogtosyslog( void );
-
-void closelogtostderr( void );
-
-void reopenlogtofile( void );
-
-void reopenlogtosyslog( void );
-
-void LOG( int level, const char *format, ... );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/port/limits.h b/src/port/limits.h
index a9e13a7..40ae1bb 100644
--- a/src/port/limits.h
+++ b/src/port/limits.h
@@ -1,7 +1,7 @@
#ifndef __LIMITS_H
#define __LIMITS_H
-#include "sys.h"
+#include "port/sys.h"
#include <limits.h>
diff --git a/src/port/lockf.h b/src/port/lockf.h
index 5ec99b3..e060ee6 100644
--- a/src/port/lockf.h
+++ b/src/port/lockf.h
@@ -1,7 +1,7 @@
#ifndef __LOCKF_H
#define __LOCKF_H
-#include "sys.h"
+#include "port/sys.h"
#if !defined HAVE_LOCKF
diff --git a/src/port/snprintf.h b/src/port/snprintf.h
index 158e5fb..c374a15 100644
--- a/src/port/snprintf.h
+++ b/src/port/snprintf.h
@@ -1,7 +1,7 @@
#ifndef __SNPRINTF_H
#define __SNPRINTF_H
-#include "sys.h"
+#include "port/sys.h"
#define HAVE_CONFIG_H 0
#define TEST_SNPRINTF 0
diff --git a/src/port/stdint.h b/src/port/stdint.h
index d5d830a..345ec7e 100644
--- a/src/port/stdint.h
+++ b/src/port/stdint.h
@@ -1,7 +1,7 @@
#ifndef __STDINT_H
#define __STDINT_H
-#include "sys.h"
+#include "port/sys.h"
#if defined HAVE_STDINT_H
#include <stdint.h>
diff --git a/src/port/stdio.h b/src/port/stdio.h
index 59a7d67..54b5d35 100644
--- a/src/port/stdio.h
+++ b/src/port/stdio.h
@@ -1,7 +1,7 @@
#ifndef __STDIO_H
#define __STDIO_H
-#include "sys.h"
+#include "port/sys.h"
#include <stdio.h>
diff --git a/src/port/string.h b/src/port/string.h
index 8f96466..baae59d 100644
--- a/src/port/string.h
+++ b/src/port/string.h
@@ -1,7 +1,7 @@
#ifndef __STRING_H
#define __STRING_H
-#include "sys.h"
+#include "port/sys.h"
#include <string.h>
diff --git a/src/port/unistd.h b/src/port/unistd.h
index 712f851..33be786 100644
--- a/src/port/unistd.h
+++ b/src/port/unistd.h
@@ -1,7 +1,7 @@
#ifndef __UNISTD_H
#define __UNISTD_H
-#include "sys.h"
+#include "port/sys.h"
#include <unistd.h>
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index caf20e7..a0942bf 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -1,6 +1,6 @@
TOPDIR = ..
-SUBDIRS =
+SUBDIRS = daemon
INCLUDE_DIRS = -I.
@@ -14,16 +14,6 @@ OBJS =
test: all
@./stdargs_for_signal_functions
-# TODO:still a little bit unrealiable with fakeroot
-# @fakeroot $(TOPDIR)/src/testd -d --pidfile /tmp/testd.pid && \
-# sleep 3 && \
-# ls -altr /tmp/testd* && \
-# cat /tmp/testd.pid
-# -@ps -alef | grep test | grep -v grep
-# @sleep 1
-# @pkill testd
-# -@ls -altr /tmp/testd*
-
local_all:
local_clean:
diff --git a/tests/daemon/GNUmakefile b/tests/daemon/GNUmakefile
new file mode 100644
index 0000000..c3aa194
--- /dev/null
+++ b/tests/daemon/GNUmakefile
@@ -0,0 +1,42 @@
+TOPDIR = ../..
+
+SUBDIRS =
+
+INCLUDE_DIRS = -I$(TOPDIR)/include -I.
+
+BINS = \
+ testd
+
+OBJS = \
+ testd_cmdline.o
+
+-include $(TOPDIR)/makefiles/sub.mk
+
+# ABa: currently a special rule for cmdline.c as gengetopt is not
+# completly fixed yet
+testd.d : testd_cmdline.h
+testd_cmdline.h : testd.ggo
+ gengetopt --file-name testd_cmdline --include-getopt --conf-parser -i $<
+testd_cmdline.c : testd.ggo
+ gengetopt --file-name testd_cmdline --include-getopt --conf-parser -i $<
+
+testd_cmdline.o : testd_cmdline.c testd_cmdline.h
+ $(CC) -c -o $@ $<
+
+local_all: testd_cmdline.h
+
+local_clean:
+
+local_distclean:
+ -@rm testd_cmdline.c testd_cmdline.h
+
+local_test:
+# TODO:still a little bit unrealiable with fakeroot
+# @fakeroot $(TOPDIR)/src/testd -d --pidfile /tmp/testd.pid && \
+# sleep 3 && \
+# ls -altr /tmp/testd* && \
+# cat /tmp/testd.pid
+# -@ps -alef | grep test | grep -v grep
+# @sleep 1
+# @pkill testd
+# -@ls -altr /tmp/testd*
diff --git a/tests/daemon/testd.c b/tests/daemon/testd.c
index 7d8fafb..f5a70b6 100644
--- a/tests/daemon/testd.c
+++ b/tests/daemon/testd.c
@@ -1,9 +1,9 @@
#include "port/stdbool.h" /* for bool */
-#include "port/string.h" /* for memset */
#include <sys/types.h> /* for pid_t */
#include <unistd.h> /* for exit, unistd, getuid, getppid */
#include <stdlib.h> /* for EXIT_FAILURE */
+#include <string.h> /* for memset */
#include "errors.h" /* global error codes */
#include "log.h" /* logging facility */
@@ -67,18 +67,18 @@ int main( int argc, char *argv[] ) {
args_info.config_file_arg : DEFAULT_CONFIG_FILE ) );
}
- openlogtostderr( LOG_DEBUG - 1 + (int)args_info.debug_given );
+ openlogtostderr( log_DEBUG - 1 + (int)args_info.debug_given );
if( args_info.logfile_given )
openlogtofile( args_info.logfile_arg,
args_info.logfile_level_given ?
- log_str_to_level( args_info.logfile_level_arg ) : LOG_NOTICE );
+ log_str_to_level( args_info.logfile_level_arg ) : log_NOTICE );
if( !args_info.foreground_given ) {
openlogtosyslog( CMDLINE_PARSER_PACKAGE,
args_info.syslog_facility_given ?
- log_str_to_syslog_facility( args_info.syslog_facility_arg ) : LOG_DAEMON,
+ log_str_to_syslog_facility( args_info.syslog_facility_arg ) : log_DAEMON,
args_info.syslog_level_given ?
- log_str_to_level( args_info.syslog_level_arg ) : LOG_NOTICE );
+ log_str_to_level( args_info.syslog_level_arg ) : log_NOTICE );
memset( &daemon_params, 0, sizeof( daemon_params ) );
daemon_params.daemon_name = CMDLINE_PARSER_PACKAGE;
@@ -111,7 +111,7 @@ int main( int argc, char *argv[] ) {
}
}
- LOG( LOG_NOTICE, "Started %s daemon", CMDLINE_PARSER_PACKAGE );
+ LOG( log_NOTICE, "Started %s daemon", CMDLINE_PARSER_PACKAGE );
while( ( sig != SIGTERM ) && ( sig != SIGINT ) && ( sig != -1 ) ) {
sig = signal_suspend( 60, &error );
switch( sig ) {
@@ -122,12 +122,12 @@ int main( int argc, char *argv[] ) {
break;
case SIGHUP:
- LOG( LOG_NOTICE, "Rereading configuration" );
+ LOG( log_NOTICE, "Rereading configuration" );
break;
case SIGTERM:
case SIGINT:
- LOG( LOG_NOTICE, "Got termination signal, shutting down the daemon" );
+ LOG( log_NOTICE, "Got termination signal, shutting down the daemon" );
break;
case SIGUSR1:
@@ -137,13 +137,13 @@ int main( int argc, char *argv[] ) {
break;
default:
- LOG( LOG_ERR, "Unexpected signal '%s' (%s, %d)",
+ LOG( log_ERR, "Unexpected signal '%s' (%s, %d)",
signal_get_long_name( sig ),
signal_get_short_name( sig ),
sig );
}
}
- LOG( LOG_NOTICE, "Stopped %s daemon", CMDLINE_PARSER_PACKAGE );
+ LOG( log_NOTICE, "Stopped %s daemon", CMDLINE_PARSER_PACKAGE );
if( !args_info.foreground_given ) {
cmdline_parser_free( &args_info );