Compare commits

..

No commits in common. "master" and "1.0.0" have entirely different histories.

17 changed files with 243 additions and 316 deletions

10
README
View File

@ -1,10 +1,8 @@
daemonitor daemonitor
======================================================================== ==============================================================================
Copyright: ©20072012, Güralp Systems Limited (c)2007, Laurence Withers, <l@lwithers.me.uk>.
Author: Laurence Withers <lwithers@guralp.com> Released under the GNU GPLv3. See file COPYING or
License: GPLv3 http://www.gnu.org/copyleft/gpl.html for details.
See file COPYING for detail license information.
Really Quick Instructions Really Quick Instructions
------------------------- -------------------------

7
config
View File

@ -1,9 +1,10 @@
# daemonitor/config # daemonitor/config
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: syntax=sh:expandtab:ts=4:sw=4 # vim: syntax=sh:expandtab:ts=4:sw=4
# #
# Copyright: ©20072012, Güralp Systems Limited # (c)2007, Laurence Withers, <l@lwithers.me.uk>.
# Author: Laurence Withers <lwithers@guralp.com> # Released under the GNU GPLv3. See file COPYING or
# License: GPLv3 # http://www.gnu.org/copyleft/gpl.html for details.
# #
# This file contains options used to build daemonitor. # This file contains options used to build daemonitor.

15
make.sh
View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/sh
# daemonitor/make.sh # daemonitor/make.sh
# #
# Copyright: ©20072012, Güralp Systems Limited # (c)2006-2007, Laurence Withers, <l@lwithers.me.uk>.
# Author: Laurence Withers <lwithers@guralp.com> # Released under the GNU GPLv3. See file COPYING or
# License: GPLv3 # http://www.gnu.org/copyleft/gpl.html for details.
# #
@ -15,19 +15,19 @@ then
echo "Configuration file not found???" echo "Configuration file not found???"
exit 1 exit 1
fi fi
source "./config" # don't fail on error, since last command in config might return false source "config" # don't fail on error, since last command in config might return false
# Get version information # Get version information
source "./version" || exit 1 source version || exit 1
VERSION="${VERMAJOR}.${VERMINOR}.${VERMICRO}" VERSION="${VERMAJOR}.${VERMINOR}.${VERMICRO}"
# Get standard functions # Get standard functions
[ -z "${VERBOSE}" ] && VERBOSE="0" [ -z "${VERBOSE}" ] && VERBOSE="0"
source "./scripts/functions.sh" || exit 1 source scripts/functions.sh || exit 1
# List of directories which will be emptied by clean. # List of directories which will be emptied by clean.
@ -292,4 +292,5 @@ done
exit 0 exit 0
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4 # vim: expandtab:ts=4:sw=4

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/sh
# daemonitor/test.sh # daemonitor/test.sh
# #
# Copyright: ©20072012, Güralp Systems Limited # (c)2007, Laurence Withers, <l@lwithers.me.uk>.
# Author: Laurence Withers <lwithers@guralp.com> # Released under the GNU GPLv3. See file COPYING or
# License: GPLv3 # http://www.gnu.org/copyleft/gpl.html for details.
# #
# Running this script on its own will display a summary of all the # Running this script on its own will display a summary of all the
@ -21,7 +21,12 @@ run_test() {
return 1 return 1
fi fi
LD_LIBRARY_PATH="obj:${LD_LIBRARY_PATH}" "${EXE}" "$@" || return 1 if [ $# -eq 0 ]
then
LD_LIBRARY_PATH="obj" ${EXE} || return 1
else
LD_LIBRARY_PATH="obj" ${EXE} "$*" || return 1
fi
return 0 return 0
} }
@ -33,15 +38,14 @@ print_tests() {
echo "---------------------------------------------------------------------" echo "---------------------------------------------------------------------"
for EXE in obj/tests/* for EXE in obj/tests/*
do do
[ -x "${EXE}" ] || continue [ -x ${EXE} ] || continue
NAME="$(echo "${EXE}" | sed 's,obj/tests/,,')" NAME=$(echo ${EXE} | sed 's,obj/tests/,,')
echo -ne "${NAME}\t" echo -ne "${NAME}\t"
LD_LIBRARY_PATH="obj:${LD_LIBRARY_PATH}" "${EXE}" --print-summary LD_LIBRARY_PATH="obj" ${EXE} --print-summary
done done
} }
# Main script # Main script
if [ $# -eq 0 ] if [ $# -eq 0 ]
then then
@ -49,6 +53,7 @@ then
exit 0 exit 0
fi fi
run_test "$@" run_test $*
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4 # vim: expandtab:ts=4:sw=4

1
scripts/.gitignore vendored
View File

@ -7,7 +7,6 @@ build.docs.none
build.files.none build.files.none
build.firmware.gpasm build.firmware.gpasm
build.firmware.sdcc build.firmware.sdcc
build.header.c
build.lib.c build.lib.c
build.lib.c++ build.lib.c++
build.make.none build.make.none

View File

@ -1,8 +1,8 @@
# daemonitor/scripts/functions.sh # daemonitor/scripts/functions.sh
# #
# Copyright: ©20072012, Güralp Systems Limited # (c)2007, Laurence Withers, <l@lwithers.me.uk>.
# Author: Laurence Withers, <lwithers@guralp.com> # Released under the GNU GPLv3. See file COPYING or
# License: GPLv3 # http://www.gnu.org/copyleft/gpl.html for details.
# #
# Common functions # Common functions
@ -63,4 +63,5 @@ do_cmd_redir() {
fi fi
} }
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4 # vim: expandtab:ts=4:sw=4

View File

@ -1,8 +1,8 @@
# daemonitor/scripts/paths # daemonitor/scripts/paths
# #
# Copyright: ©20072012, Güralp Systems Limited # (c)2007, Laurence Withers, <l@lwithers.me.uk>.
# Author: Laurence Withers, <lwithers@guralp.com> # Released under the GNU GPLv3. See file COPYING or
# License: GPLv3 # http://www.gnu.org/copyleft/gpl.html for details.
# #
# Default path setup. Not meant for editing; use environment variables # Default path setup. Not meant for editing; use environment variables
# to override values if needed. # to override values if needed.
@ -60,4 +60,5 @@ fi
[ -z "${WEBDIR}" ] && WEBDIR="${SRVDIR}/http" [ -z "${WEBDIR}" ] && WEBDIR="${SRVDIR}/http"
[ -z "${CGIDIR}" ] && CGIDIR="${WEBDIR}/cgi-bin" [ -z "${CGIDIR}" ] && CGIDIR="${WEBDIR}/cgi-bin"
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: syntax=sh:expandtab:ts=4:sw=4 # vim: syntax=sh:expandtab:ts=4:sw=4

View File

@ -1,9 +1,9 @@
/* daemonitor/src/daemonitor/200_log.c /* daemonitor/src/daemonitor/200_log.c
* *
* Copyright: ©20072012, Laurence Withers. * (c)2007, Laurence Withers, <l@lwithers.me.uk>.
* Author: Laurence Withers <l@lwithers.me.uk> * Released under the GNU GPLv3. See file COPYING or
* License: GPLv3 * http://www.gnu.org/copyleft/gpl.html for details.
*/ */
@ -161,7 +161,7 @@ void log_func_syslog(int level, const char* fmt, ...)
/* log to syslog */ /* log to syslog */
va_start(va, fmt); va_start(va, fmt);
vsyslog(level, fmt, va); syslog(level, fmt, va);
va_end(va); va_end(va);
} }
@ -170,25 +170,16 @@ void log_func_syslog(int level, const char* fmt, ...)
/* log_destination_set() /* log_destination_set()
* Set `log_func' function pointer. * Set `log_func' function pointer.
*/ */
void void log_destination_set(enum log_destination_t dest)
log_destination_set(enum log_destination_t dest)
{ {
switch(dest) { switch(dest) {
case log_destination_stdout: case log_destination_stdout:
log_func_fd = dup(STDOUT_FILENO); log_func_fd = STDOUT_FILENO;
if(log_func_fd == -1) {
printf("dup() failed: %m.");
exit(1);
}
log_func = log_func_file; log_func = log_func_file;
break; break;
case log_destination_stderr: case log_destination_stderr:
log_func_fd = dup(STDERR_FILENO); log_func_fd = STDERR_FILENO;
if(log_func_fd == -1) {
fprintf(stderr, "dup() failed: %m.");
exit(1);
}
log_func = log_func_file; log_func = log_func_file;
break; break;
@ -219,5 +210,6 @@ int log_destination_set_file(const char* filename)
/* options for text editors /* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4 vim: expandtab:ts=4:sw=4
*/ */

160
src/daemonitor/400_daemon.c Normal file
View File

@ -0,0 +1,160 @@
/* daemonitor/src/daemonitor/400_daemon.c
*
* (c)2007, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv3. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
/* DAEMON ROUTINES ********************************************************************************
*
* This file provides the daemonise() routine, which makes the process a daemon (fork() + setsid()
* so that the process lives in the background, also opens /dev/console). It also provides the
* close_file_descriptors() routine, which clears all file descriptors but 0, 1 and 2.
*/
/* PUBLIC API ************************************************************************************/
/* daemonise()
* Performs a fork() and setsid() so that the process lives in the background. It closes stdin,
* stdout and stderr and opens /dev/null and/or /dev/console instead, as appropriate. On error,
* this function exits the program.
*/
void daemonise(void);
/* close_file_descriptors()
* Closes all file descriptors but stdin, stdout and stderr. Should be called whether we are
* daemonising or not.
*/
void close_file_descriptors(void);
/* IMPLEMENTATION ********************************************************************************/
void daemonise(void)
{
int fd;
pid_t pid;
/* close stdin and reopen it as /dev/null */
TEMP_FAILURE_RETRY( close(STDIN_FILENO) );
fd = open("/dev/null", O_RDONLY);
switch(fd) {
case -1:
LOG(LOG_CRIT, "Could not open `/dev/null' (%m).");
exit(1);
case STDIN_FILENO:
break;
default:
LOG(LOG_CRIT, "Opened `/dev/null' for stdin, but got file descriptor %d instead.", fd);
exit(1);
}
/* close stdout and reopen it as /dev/console if possible, or /dev/null if not */
TEMP_FAILURE_RETRY( close(STDOUT_FILENO) );
fd = open("/dev/console", O_WRONLY | O_NOCTTY);
if(fd == -1) {
LOG(LOG_WARNING, "Could not open `/dev/console' for stdout (%m).");
fd = open("/dev/null", O_WRONLY);
}
switch(fd) {
case -1:
LOG(LOG_CRIT, "Could not open `/dev/null' (%m).");
exit(1);
case STDOUT_FILENO:
break;
default:
LOG(LOG_CRIT, "Opened `/dev/null' for stdout, but got file descriptor %d instead.", fd);
exit(1);
}
/* close stderr and reopen it as /dev/console if possible, or /dev/null if not */
TEMP_FAILURE_RETRY( close(STDERR_FILENO) );
fd = open("/dev/console", O_WRONLY | O_NOCTTY);
if(fd == -1) {
LOG(LOG_WARNING, "Could not open `/dev/console' for stderr (%m).");
/* force fd closed again, in case glibc kindly connected it to syslog for us */
TEMP_FAILURE_RETRY( close(STDERR_FILENO) );
fd = open("/dev/null", O_WRONLY);
}
switch(fd) {
case -1:
LOG(LOG_CRIT, "Could not open `/dev/null' (%m).");
exit(1);
case STDERR_FILENO:
break;
default:
LOG(LOG_CRIT, "Opened `/dev/null' for stderr, but got file descriptor %d instead.", fd);
exit(1);
}
/* daemonise */
pid = fork();
if(pid == (pid_t)-1) {
LOG(LOG_CRIT, "Could not fork daemonised process (%m).");
exit(1);
}
if(pid) {
/* parent */
_exit(0); /* don't call atexit() et al. in parent */
}
setsid();
LOG(LOG_NOTICE, "Daemonised, PID %lu.", (unsigned long)getpid());
}
/* close_file_descriptors()
* Adapted from libgslutil (GPL-3).
*/
void close_file_descriptors(void)
{
DIR* d;
struct dirent* de;
int i, end, dfd;
d = opendir("/proc/self/fd");
if(!d) {
/* backup method */
for(i = STDERR_FILENO + 1, end = getdtablesize(); i < end; ++i) {
close(i);
}
return;
}
dfd = dirfd(d);
while( (de = readdir(d)) ) {
if(de->d_name[0] == '.') continue;
i = strtol(de->d_name, 0, 10);
if(i == dfd) continue; /* skip file descriptor associated with `DIR* d' */
if(i <= STDERR_FILENO) continue; /* leave stdin, stdout, stderr alone */
TEMP_FAILURE_RETRY( close(i) );
}
closedir(d);
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4
*/

View File

@ -1,9 +1,9 @@
/* daemonitor/src/daemonitor/600_run_program.c /* daemonitor/src/daemonitor/600_run_program.c
* *
* Copyright: ©20072012, Laurence Withers. * (c)2007, Laurence Withers, <l@lwithers.me.uk>.
* Author: Laurence Withers <l@lwithers.me.uk> * Released under the GNU GPLv3. See file COPYING or
* License: GPLv3 * http://www.gnu.org/copyleft/gpl.html for details.
*/ */
@ -45,8 +45,8 @@ volatile int sigterm_received = 0;
/* close_file_descriptors() /* close_file_descriptors()
* Closes all file descriptors but stdin, stdout and stderr (which it leaves * Closes all file descriptors but stdin, stdout and stderr. Should be called whether we are
* unchanged). * daemonising or not.
*/ */
void close_file_descriptors(void); void close_file_descriptors(void);
@ -56,38 +56,6 @@ void close_file_descriptors(void);
/* close_file_descriptors()
* Adapted from libgslutil (GPL-3).
*/
void
close_file_descriptors(void)
{
DIR* d;
struct dirent* de;
int i, end, dfd;
d = opendir("/proc/self/fd");
if(!d) {
/* backup method */
for(i = STDERR_FILENO + 1, end = getdtablesize(); i < end; ++i) {
close(i);
}
return;
}
dfd = dirfd(d);
while( (de = readdir(d)) ) {
if(de->d_name[0] == '.') continue;
i = strtol(de->d_name, 0, 10);
if(i == dfd) continue; /* skip file descriptor associated with `DIR* d' */
if(i <= STDERR_FILENO) continue; /* leave stdin, stdout, stderr alone */
TEMP_FAILURE_RETRY( close(i) );
}
closedir(d);
}
/* crash() /* crash()
* Crash the program. This is better than just calling exit() because it doesn't clean up. We * Crash the program. This is better than just calling exit() because it doesn't clean up. We
* should leave our PID file lying around to look like we crashed. This function is paranoid. * should leave our PID file lying around to look like we crashed. This function is paranoid.
@ -145,8 +113,6 @@ void run_program(const char* exe_path, char** argv)
/* child -- execute new process */ /* child -- execute new process */
if(pid == 0) { if(pid == 0) {
close_file_descriptors();
/* clear the child's signal mask */ /* clear the child's signal mask */
sigemptyset(&ss); sigemptyset(&ss);
sigprocmask(SIG_SETMASK, &ss, 0); sigprocmask(SIG_SETMASK, &ss, 0);
@ -237,5 +203,6 @@ void run_program(const char* exe_path, char** argv)
/* options for text editors /* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4 vim: expandtab:ts=4:sw=4
*/ */

View File

@ -1,9 +1,9 @@
/* daemonitor/src/daemonitor/700_signal.c /* daemonitor/src/daemonitor/700_signal.c
* *
* Copyright: ©20072012, Laurence Withers. * (c)2007, Laurence Withers, <l@lwithers.me.uk>.
* Author: Laurence Withers <l@lwithers.me.uk> * Released under the GNU GPLv3. See file COPYING or
* License: GPLv3 * http://www.gnu.org/copyleft/gpl.html for details.
*/ */
@ -45,7 +45,7 @@ void sigterm_handler(int signum __attribute__((unused)))
/* uck -- we can't call exit() because it's not async-signal-safe, so we must call _exit() and /* uck -- we can't call exit() because it's not async-signal-safe, so we must call _exit() and
* clean up manually, with no logging */ * clean up manually, with no logging */
unlink(pidfile_filename); unlink(pidfile_filename);
_exit(0); exit(0);
} }
@ -72,9 +72,8 @@ void signal_setup(void)
sigdelset(&ss, SIGSEGV); sigdelset(&ss, SIGSEGV);
sigdelset(&ss, SIGBUS); sigdelset(&ss, SIGBUS);
/* we'd like to deal with SIGTERM/SIGINT specially */ /* we'd like to deal with SIGTERM specially */
sigdelset(&ss, SIGTERM); sigdelset(&ss, SIGTERM);
sigdelset(&ss, SIGINT);
/* don't block SIGCHLD or wait(2) won't work */ /* don't block SIGCHLD or wait(2) won't work */
sigdelset(&ss, SIGCHLD); sigdelset(&ss, SIGCHLD);
@ -91,10 +90,9 @@ void signal_setup(void)
sigaction(SIGBUS, &sa, 0); sigaction(SIGBUS, &sa, 0);
sigaction(SIGCHLD, &sa, 0); sigaction(SIGCHLD, &sa, 0);
/* install our own handler for SIGTERM/SIGINT */ /* install our own handler for SIGTERM */
sa.sa_handler = sigterm_handler; sa.sa_handler = sigterm_handler;
sigaction(SIGTERM, &sa, 0); sigaction(SIGTERM, &sa, 0);
sigaction(SIGINT, &sa, 0);
} }

View File

@ -1,186 +0,0 @@
/* daemonitor/src/daemonitor/800_checks.c
*
* Copyright: ©2012, Laurence Withers.
* Author: Laurence Withers <l@lwithers.me.uk>
* License: GPLv3
*/
/* RESPAWN CHECKS **************************************************************
*
* This file implements functionality for various checks that may be carried
* out whenever the child process needs to be respawned. An arbitrary number of
* checks may be registered; if any single check fails, the entire test counts
* as failing. The result of the checks is found by calling run_checks().
*
* A failed check will log details at LOG_NOTICE (or above).
*/
/* PUBLIC API *****************************************************************/
/* check_command_register()
* cmd: A command (passed to system(3)) to run. If it exits with code 0, the
* check passes.
*/
void check_command_register(const char* cmd);
/* check_file_register()
* path: A file to test. If it exists, the check passes.
*/
void check_file_register(const char* cmd);
/* run_checks()
* Returns 0 if all checks succeeded (including when none are registered) and
* non-0 if any check failed.
*/
int run_checks(void);
/* IMPLEMENTATION *************************************************************/
enum check_type {
check_type_command,
check_type_file,
};
/* struct check
* check_head
* A linked list of the checks that are to be run.
*/
struct check {
enum check_type type;
/* can be the argument for system(3) or the path to check for a file */
const char* arg;
/* linked list structure */
struct check* next;
};
struct check* check_head = 0;
/* check_generic_register()
* Instantiates a struct check and adds it to the list at check_head.
*/
void
check_generic_register(enum check_type type, const char* arg)
{
struct check* c;
c = malloc(sizeof(*c));
c->type = type;
c->arg = arg;
c->next = check_head;
check_head = c;
}
void
check_command_register(const char* cmd)
{
check_generic_register(check_type_command, cmd);
}
int
check_command_run(const struct check* iter)
{
int ret;
ret = system(iter->arg);
if(ret == -1) {
LOG(LOG_ERR, "Unable to run check command \"%s\": %m.", iter->arg);
return 0; /* don't exit just because system(3) failed */
}
if(WIFSIGNALED(ret)) {
LOG(LOG_WARNING, "Check command \"%s\" killed by signal (%s). Exiting.",
iter->arg, strsignal(WTERMSIG(ret)));
return -1;
}
if(!WIFEXITED(ret)) {
LOG(LOG_WARNING, "Unrecognised exit code 0x%X from check command "
"\"%s\".", ret, iter->arg);
return 0;
}
if(WEXITSTATUS(ret)) {
LOG(LOG_NOTICE, "Check command \"%s\" signalled failure (exit code "
"%d). Exiting.", iter->arg, WEXITSTATUS(ret));
return -1;
}
return 0;
}
void
check_file_register(const char* path)
{
check_generic_register(check_type_file, path);
}
int
check_file_run(const struct check* iter)
{
int ret;
ret = access(iter->arg, F_OK);
if(ret) {
LOG(LOG_NOTICE, "Check file \"%s\" does not exist. Exiting.",
iter->arg);
return -1;
}
return 0;
}
int
run_checks(void)
{
const struct check* iter;
for(iter = check_head; iter; iter = iter->next) {
switch(iter->type) {
case check_type_command:
if(check_command_run(iter)) return -1;
break;
case check_type_file:
if(check_file_run(iter)) return -1;
break;
}
}
return 0;
}
/* options for text editors
vim: expandtab:ts=4:sw=4
*/

View File

@ -1,9 +1,9 @@
/* daemonitor/src/daemonitor/999_main.c /* daemonitor/src/daemonitor/999_main.c
* *
* Copyright: ©20072012, Laurence Withers. * (c)2007, Laurence Withers, <l@lwithers.me.uk>.
* Author: Laurence Withers <l@lwithers.me.uk> * Released under the GNU GPLv3. See file COPYING or
* License: GPLv3 * http://www.gnu.org/copyleft/gpl.html for details.
*/ */
@ -37,10 +37,6 @@ void usage(void)
" " DEFAULT_RESTART_INTERVAL_S "). May be 0 to restart immediately.\n" " " DEFAULT_RESTART_INTERVAL_S "). May be 0 to restart immediately.\n"
" -E, --environment <path> Name of file containing environment variables for\n" " -E, --environment <path> Name of file containing environment variables for\n"
" child process, one NAME=VALUE entry per line.\n" " child process, one NAME=VALUE entry per line.\n"
" -C, --check-command <cmd> Runs <cmd> via /bin/sh before restarting a service\n"
" that has exited. Stops if <cmd> fails.\n"
" -F, --check-file <path> Checks that <path> exists before restarting a service\n"
" that has exited. Stops if it does not exist.\n"
"", stderr); "", stderr);
} }
@ -57,8 +53,6 @@ struct option options[] = {
{ "pidfile", required_argument, 0, 'p' }, { "pidfile", required_argument, 0, 'p' },
{ "restart-interval", required_argument, 0, 'R' }, { "restart-interval", required_argument, 0, 'R' },
{ "environment", required_argument, 0, 'E' }, { "environment", required_argument, 0, 'E' },
{ "check-command", required_argument, 0, 'C' },
{ "check-file", required_argument, 0, 'F' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -67,7 +61,7 @@ struct option options[] = {
/* optstr /* optstr
* The list of short commandline options for getopt(3). Sorted alphabetically, lowercase first. * The list of short commandline options for getopt(3). Sorted alphabetically, lowercase first.
*/ */
const char* optstr = "dhl:p:C:E:F:R:V"; const char* optstr = "dhl:p:E:R:V";
@ -79,7 +73,7 @@ int main(int argc, char* argv[])
{ {
char* endp; char* endp;
const char* log_argument = 0, * pidfile_argument = 0, * restart_argument = 0; const char* log_argument = 0, * pidfile_argument = 0, * restart_argument = 0;
int do_daemon = 0, restart_interval = DEFAULT_RESTART_INTERVAL; int daemon = 0, restart_interval = DEFAULT_RESTART_INTERVAL;
/* safety */ /* safety */
close_file_descriptors(); /* leaves stdout etc. open */ close_file_descriptors(); /* leaves stdout etc. open */
@ -91,13 +85,11 @@ int main(int argc, char* argv[])
case '?': LOG_ANYWHERE("Invalid commandline options."); return 1; case '?': LOG_ANYWHERE("Invalid commandline options."); return 1;
case 'h': usage(); return 1; case 'h': usage(); return 1;
case 'V': fputs("daemonitor " VERSION "\n", stderr); return 1; case 'V': fputs("daemonitor " VERSION "\n", stderr); return 1;
case 'd': ++do_daemon; break; case 'd': ++daemon; break;
case 'l': log_argument = optarg; break; case 'l': log_argument = optarg; break;
case 'p': pidfile_argument = optarg; break; case 'p': pidfile_argument = optarg; break;
case 'R': restart_argument = optarg; break; case 'R': restart_argument = optarg; break;
case 'E': set_environment_file(optarg); break; case 'E': set_environment_file(optarg); break;
case 'C': check_command_register(optarg); break;
case 'F': check_file_register(optarg); break;
} }
} }
opts_done: opts_done:
@ -136,12 +128,7 @@ int main(int argc, char* argv[])
if(load_child_environ()) return 1; if(load_child_environ()) return 1;
/* daemonise? */ /* daemonise? */
if(do_daemon) { if(daemon) daemonise();
if(daemon(0, 0)) {
LOG(LOG_CRIT, "daemon() failed: %m.");
return 1;
}
}
/* write a PID file */ /* write a PID file */
if(pidfile_argument) { if(pidfile_argument) {
@ -163,8 +150,6 @@ int main(int argc, char* argv[])
LOG(LOG_NOTICE, "Sleeping for %d seconds.", restart_interval); LOG(LOG_NOTICE, "Sleeping for %d seconds.", restart_interval);
safe_sleep_fixed(restart_interval, 0); safe_sleep_fixed(restart_interval, 0);
} }
if(run_checks()) return 0;
} }
return 0; return 0;
@ -173,5 +158,6 @@ int main(int argc, char* argv[])
/* options for text editors /* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4 vim: expandtab:ts=4:sw=4
*/ */

View File

@ -6,7 +6,7 @@
if [ -z ${daemonitor_BUILT} ] if [ -z ${daemonitor_BUILT} ]
then then
daemonitor="obj/daemonitor" daemonitor="obj/daemonitor"
EXTRAS="-std=gnu99 -D_GNU_SOURCE -DAPP_NAME=\"daemonitor\"" EXTRAS="-D_GNU_SOURCE"
echo "Building application ${daemonitor}..." echo "Building application ${daemonitor}..."
@ -37,4 +37,5 @@ then
fi fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: syntax=sh:expandtab:ts=4:sw=4 # vim: syntax=sh:expandtab:ts=4:sw=4

View File

@ -8,4 +8,5 @@ echo "Installing binaries into '${SBINDIR}'"
install_file "${daemonitor}" "${SBINDIR}" 0755 || return 1 install_file "${daemonitor}" "${SBINDIR}" 0755 || return 1
print_success "Done" print_success "Done"
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: syntax=sh:expandtab:ts=4:sw=4 # vim: syntax=sh:expandtab:ts=4:sw=4

View File

@ -14,4 +14,5 @@ then
MONOLITHIC_DOC="${MONOLITHIC_DOC} ${SRC}" MONOLITHIC_DOC="${MONOLITHIC_DOC} ${SRC}"
fi fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: syntax=sh:expandtab:ts=4:sw=4 # vim: syntax=sh:expandtab:ts=4:sw=4

View File

@ -1,8 +1,8 @@
# daemonitor/version # daemonitor/version
# #
# Copyright: ©20072012, Güralp Systems Limited # (c)2007, Laurence Withers, <l@lwithers.me.uk>.
# Author: Laurence Withers <lwithers@guralp.com> # Released under the GNU GPLv3. See file COPYING or
# License: GPLv3 # http://www.gnu.org/copyleft/gpl.html for details.
# #
@ -11,6 +11,7 @@
# expected to be in 'major.minor.micro' format. # expected to be in 'major.minor.micro' format.
VERMAJOR=1 VERMAJOR=1
VERMINOR=0 VERMINOR=0
VERMICRO=3 VERMICRO=0
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4:syntax=sh # vim: expandtab:ts=4:sw=4:syntax=sh