watchcatd-1.2.1/0000755001177500117750000000000011233356164014473 5ustar lua.osslua.oss00000000000000watchcatd-1.2.1/tester/0000755001177500117750000000000011227344155016001 5ustar lua.osslua.oss00000000000000watchcatd-1.2.1/tester/confs/0000755001177500117750000000000011227344155017111 5ustar lua.osslua.oss00000000000000watchcatd-1.2.1/tester/confs/nouser.conf0000644001177500117750000000047311053071476021277 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = foo master_debug_level = 32767 slave_debug_level = 32767 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/pidfile.conf0000644001177500117750000000052411053071476021375 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 master_pid_file = /foo/bar slave_debug_level = 32767 slave_device = /tmp slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/device.conf0000644001177500117750000000047111053071476021221 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 slave_debug_level = 32767 slave_device = /foo/bar slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/slave_debughigh.conf0000644001177500117750000000050311053071476023076 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 slave_debug_level = 2343435456 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/slave_debuglow.conf0000644001177500117750000000050411053071476022761 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 slave_debug_level = -2343435456 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/debughigh.conf0000644001177500117750000000050311053071476021704 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 2343435456 slave_debug_level = 32767 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/noprio.conf0000644001177500117750000000047511053071476021274 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = user = nobody master_debug_level = 32767 slave_debug_level = 32767 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/max_connections.conf0000644001177500117750000000047011053071476023150 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 slave_debug_level = 32767 slave_device = /tmp slave_max_connections = 123456 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/debuglow.conf0000644001177500117750000000050411053071476021567 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = -2343435456 slave_debug_level = 32767 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 2 watchcatd-1.2.1/tester/confs/max_connections_per_pid.conf0000644001177500117750000000047111053071476024653 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 slave_debug_level = 32767 slave_device = /tmp slave_max_connections = 100 slave_max_connections_per_pid = -1234 watchcatd-1.2.1/tester/cattester.c0000644001177500117750000003413011053071476020144 0ustar lua.osslua.oss00000000000000/* ** $Id: cattester.c 1654 2006-05-29 18:18:02Z andre $ ** cattester - Watchcat Tester ** See copyright notice in watchcatd distro's COPYRIGHT file */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define NCHILDREN 5 static volatile sig_atomic_t dead_child_count; static volatile sig_atomic_t sig_usr1_count; static int fds[NCHILDREN][2]; static void dream(int sec) { while ((sec = sleep(sec)) > 0) ; } static void exec_master(char *rconf) { char real_path[256]; char master[256]; char conf[256]; assert(getcwd(conf, sizeof(conf))); strcat(conf, "/"); strcat(conf, rconf); assert(getcwd(real_path, sizeof(real_path))); *strrchr(real_path, '/') = '\0'; /* real_path/.. */ sprintf(master, "%s/catmaster", real_path); assert(execl(master, master, "-Xf", conf, "-p", real_path, NULL) == 0); } static void sig_usr1(int sig) { sig_usr1_count++; } static void test_lib_use(void) { int cat; struct sigaction act, oact; sig_usr1_count = 0; /* Handle SIGUSR1. */ act.sa_handler = sig_usr1; sigemptyset(&act.sa_mask); act.sa_flags = 0; assert(sigaction(SIGUSR1, &act, &oact) == 0); /* Test normal use. */ cat = cat_open1(5, SIGUSR1, "sample"); assert(cat >= 0); dream(2); assert(cat_heartbeat(cat) == 0); dream(2); assert(cat_heartbeat(cat) == 0); dream(3); assert(cat_close(cat) == 0); /* Test valid use. */ cat = cat_open1(5, SIGUSR1, "123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890" "123456789012345678901234567890123456789012345678901234567890"); assert(cat >= 0); assert(cat_close(cat) == 0); cat = cat_open1(5, SIGUSR1, NULL); assert(cat >= 0); assert(cat_close(cat) == 0); cat = cat_open1(5, SIGUSR1, ""); assert(cat >= 0); assert(cat_close(cat) == 0); cat = cat_open1(5, SIGUSR1, "sácánágem\n\0test"); assert(cat >= 0); assert(cat_heartbeat(cat) == 0); dream(2); assert(cat_heartbeat(cat) == 0); dream(2); assert(cat_heartbeat(cat) == 0); assert(cat_heartbeat(cat) == 0); dream(3); assert(cat_heartbeat(cat) == 0); assert(cat_heartbeat(cat) == 0); assert(cat_close(cat) == 0); /* Teste invalid use. */ assert(cat_heartbeat(cat) == -1); assert(errno == EBADF); assert(cat_close(cat) == -1); assert(errno == EBADF); assert(cat_open1(0, SIGUSR1, NULL) == -1); /* Invalid timeout. */ assert(errno == EPERM); assert(cat_open1(10, 1024, NULL) == -1); /* Invalid signal. */ assert(errno == EPERM); /* Restore SIGUSR1 handler. */ assert(sigaction(SIGUSR1, &oact, NULL) == 0); assert(sig_usr1_count == 0); } static void TELL_WAIT(void) { int i; for (i = 0; i < NCHILDREN; i++) assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds[i]) == 0); } static void TELL_PARENT(int i) { assert(write(fds[i][1], "c", 1) == 1); } static void WAIT_PARENT(int i) { char c; assert(read(fds[i][1], &c, 1) == 1); assert(c == 'p'); } static void TELL_CHILDREN(void) { int i; for (i = 0; i < NCHILDREN; i++) assert(write(fds[i][0], "p", 1) == 1); } static void WAIT_CHILDREN(void) { char c; int i, n, count = NCHILDREN; fd_set rset, saved_set; FD_ZERO(&saved_set); for (i = 0; i < NCHILDREN; i++) FD_SET(fds[i][0], &saved_set); while (count > 0) { rset = saved_set; n = select(fds[NCHILDREN-1][0] + 1, &rset, NULL, NULL, NULL); if (n == -1) { if (errno == EINTR) continue; perror("select"); exit(errno); } for (i = 0; i < NCHILDREN; i++) if (FD_ISSET(fds[i][0], &rset)) { assert(read(fds[i][0], &c, 1) == 1); assert(c == 'c'); FD_CLR(fds[i][0], &saved_set); } count -= n; } } static void sig_chld(int sig) { pid_t pid; int status; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) dead_child_count++; } static void test_max_conections(void) { int i; pid_t daemon_pid; struct sigaction act, oact; dead_child_count = 0; /* Handle SIGCHLD. */ act.sa_handler = sig_chld; sigemptyset(&act.sa_mask); act.sa_flags = 0; assert(sigaction(SIGCHLD, &act, &oact) == 0); daemon_pid = fork(); assert(daemon_pid >= 0); if (daemon_pid == 0) { /* Son. */ exec_master("test_max_conections.conf"); } dream(3); /* Test global max conections and max conections by pid. */ TELL_WAIT(); for (i = 0; i < NCHILDREN; i++) { pid_t pid = fork(); assert(pid != -1); if (pid == 0) { /* Son. */ int cat; cat = cat_open1(20, SIGKILL, NULL); assert(cat >= 0); assert(cat_open1(10, SIGKILL, "explode the cat") >= 0); assert(cat_open() == -1); TELL_PARENT(i); WAIT_PARENT(i); while (1) { /* Try produce a SIGPIPE. If this occurs is a BUG! */ cat_open(); /* Complicate the life of watchcatd. */ assert(cat_heartbeat(cat) == 0); } /* NOTREACHED */ } } WAIT_CHILDREN(); assert(cat_open1(10, SIGKILL, NULL) == -1); TELL_CHILDREN(); dream(11); assert(kill(daemon_pid, SIGTERM) == 0); dream(3); /* Restore SIGCHLD handler. */ assert(sigaction(SIGCHLD, &oact, NULL) == 0); assert(dead_child_count == NCHILDREN + 1); } static void test_configuration_parser(void) { pid_t chld_pid; int status; char path[256]; struct dirent *d; DIR *dp; dp = opendir("confs"); assert(dp != NULL); while ((d = readdir(dp)) != NULL) { if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0 || strcmp(d->d_name, "CVS") == 0) continue; assert(snprintf(path, sizeof path,"confs/%s", d->d_name) < sizeof path); chld_pid = fork(); assert(chld_pid >= 0); if (chld_pid == 0) /* child */ exec_master(path); /* parent */ waitpid(chld_pid, &status, 0); if (WIFEXITED(&status)) { assert(WEXITSTATUS(&status) != 0); assert(WIFSIGNALED(&status) == 0); } } closedir(dp); } static int timediff(struct timeval tv1, struct timeval tv2) { return (tv1.tv_sec - tv2.tv_sec) * 1000 + (tv1.tv_usec - tv2.tv_usec) / 1000; } static void test_timeout(void) { int i, cat, ntmouts; int tmouts[5] = { 5, 10, 15, 30, 60 }; sigset_t newmask, oldmask; struct sigaction act, oact; struct timeval tv_now, tv_sig; sig_usr1_count = 0; /* Block all signals except SIGUSR1 */ sigfillset(&newmask); sigdelset(&newmask, SIGUSR1); assert(sigprocmask(SIG_BLOCK, &newmask, &oldmask) == 0); act.sa_handler = sig_usr1; sigemptyset(&act.sa_mask); act.sa_flags = 0; assert(sigaction(SIGUSR1, &act, &oact) == 0); ntmouts = sizeof tmouts; for (i = 0; i < ntmouts; i++) { cat = cat_open1(tmouts[i], SIGUSR1, "timeout"); assert(gettimeofday(&tv_now, NULL) == 0); assert(cat >= 0); pause(); /* we got a SIGUSR1 */ assert(gettimeofday(&tv_sig, NULL) == 0); assert(cat_close(cat) == 0); assert(timediff(tv_sig, tv_now) <= 500); } /* Restore old mask and SIGUSR1 handler. */ assert(sigprocmask(SIG_SETMASK, &oldmask, NULL) == 0); assert(sigaction(SIGUSR1, &oact, NULL) == 0); assert(ntmouts == sig_usr1_count); } static ssize_t safe_write(int fd, const void *buf, size_t count) { struct sigaction act, oact; ssize_t r; int e, s; /* Ignore SIGPIPE. */ act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); act.sa_flags = 0; while ((s = sigaction(SIGPIPE, &act, &oact)) == -1 && errno == EINTR) ; if (s != 0) return -1; do { r = write(fd, buf, count); } while(r == -1 && errno == EINTR); e = errno; /* Restore SIGPIPE handler. */ while ((s = sigaction(SIGPIPE, &oact, NULL)) == -1 && errno == EINTR) if (s != 0) abort(); errno = e; return r; } static ssize_t safe_read(int fd, void *buf, size_t count) { ssize_t r; do { r = read(fd, buf, count); } while(r == -1 && errno == EINTR); return r; } static int connect_to_cat(void) { int sockfd; socklen_t len; struct sockaddr_un sun; assert((sockfd = socket(PF_UNIX, SOCK_STREAM, 0)) > 0); memset(&sun, 0, sizeof sun); sun.sun_family = PF_UNIX; strncpy(sun.sun_path, "/tmp/watchcat", sizeof(sun.sun_path) - 1); sun.sun_path[sizeof(sun.sun_path) - 1] = '\0'; len = sizeof(sun.sun_family) + strlen(sun.sun_path); assert(connect(sockfd, (struct sockaddr *)&sun, len) == 0); return sockfd; } static void test_bad_conections(void) { int n, r, sockfd; char sendbuf[128], recvbuf[128]; char bigbuf[1024]; FILE *fp; /* * Header with typos */ sockfd = connect_to_cat(); n = snprintf(sendbuf, sizeof sendbuf, "vesrion: 1\ntmout: %i\nsignal: %i\n\n", 15, SIGURG); assert(n > 0 && n < sizeof sendbuf); memset(recvbuf, 0, sizeof recvbuf); assert((r = safe_write(sockfd, sendbuf, n)) == n); assert((r = safe_read(sockfd, recvbuf, sizeof recvbuf)) != -1); assert(strcmp(recvbuf, "error\n") == 0); /* * Missing version on header. */ sockfd = connect_to_cat(); n = snprintf(sendbuf, sizeof sendbuf, "timeout: %i\nsignal: %i\n\n", 15, SIGURG); assert(n > 0 && n < sizeof sendbuf); memset(recvbuf, 0, sizeof recvbuf); assert((r = safe_write(sockfd, sendbuf, n)) == n); assert((r = safe_read(sockfd, recvbuf, sizeof recvbuf)) != -1); assert(strcmp(recvbuf, "error\n") == 0); /* * Missing `\n'. */ sockfd = connect_to_cat(); n = snprintf(sendbuf, sizeof sendbuf, "version: 1\ntimeout: %i\nsignal: %i\n", 15, SIGKILL); assert(n > 0 && n < sizeof sendbuf); memset(recvbuf, 0, sizeof recvbuf); assert((r = safe_write(sockfd, sendbuf, n)) == n); assert((r = safe_read(sockfd, recvbuf, sizeof recvbuf)) != -1); assert(strcmp(recvbuf, "timeout\n") == 0); /* * Sending big random data. */ #define RANDOM_DATA "asdçlasfgklwcvrvmfnbflbmf.blg.pwoefievggfçvl,z\asdfçldfm.bmvdbnxvx//gf;f;d.vdfvw;dfçwepqeweldklfgdfmçblfbçgmblçg,bvlxcvbxncvdfkvjfkglçfgjfkgfgjsdlfklsdgçfgkfsglfdbv,dfblçdvwieporeirwopeturiotyer89t0345u34iotu438t9023ruweiruseofijeriogyiwooo13112po4j23opurrgpgh9tu8-e0gek vlksdskdqweopdkiweopf ,vowmwcwecvojmvl mwcvwimecpowmca\niopwdmcposmczxpcm\t\n\tndfosdkfsdçlcm,sdçlksçmtçkdçsvglsdfm,vçldfmvçlam,dç\açldkfsdçfksdvfçdlvgkfvvsaqçksçdkwef,wcvçvltmobhpms^sdf Ç bdfvdfvsac*DQWD&#r28ery68787687686*&$% %&S$A%S4%4567clsdaçckdcçdlskcvdsç,vdsssssgfdsgfdgçlfkkkkasdsd,dfd,gmmg,fmgf,gmflgkfjsdklfkdlfkdlfkdsfcsdmcknaqkwlqeqwprpé2-39123904320r23kqasod=q=-+_{{}{`````AS''''''''ASDFASF SDCLÇSDKCSDÇLVKSÇDVL ÀW feÈRGFvs ËFGSDF ADLÇ ASLDKÇSDFDSFDSFMDS,FMKDLFJJIOOPBVJFBVDFVNDFJVNNNASJDANSDPÉRQWOERPQWER,.;Q.,M, .mwefwelkrjfqwqoeiqwoireiouiyidmandçv,s" #define NRAND sizeof(RANDOM_DATA) sockfd = connect_to_cat(); memset(recvbuf, 0, sizeof recvbuf); assert((r = safe_write(sockfd, RANDOM_DATA, NRAND)) == NRAND); assert((r = safe_read(sockfd, recvbuf, sizeof recvbuf)) != -1); assert(strcmp(recvbuf, "error\n") == 0); /* * Sending binary data. */ assert((fp = fopen("/bin/sh", "r")) != NULL); assert(fread(sendbuf, sizeof sendbuf, 1, fp) == 1); n = sizeof(sendbuf); sockfd = connect_to_cat(); memset(recvbuf, 0, sizeof recvbuf); assert((r = safe_write(sockfd, sendbuf, n)) == n); assert((r = safe_read(sockfd, recvbuf, sizeof recvbuf)) != -1); assert(strcmp(recvbuf, "error\n") == 0); /* * Sending a big line. */ #define LONG_INFO "asdaskdjlskdslackwdaclkwdac,waokfwedkowedsaxcld,scaslckaadcmsdkvnsdsdcksdjclksmcskldcsdkcsdlaasksdfklasdflkawefowifpwiftaasdqwr" sockfd = connect_to_cat(); n = snprintf(bigbuf, sizeof bigbuf, "version: 1\ntimeout: %i\nsignal: %i\ninfo: %s\n\n", 15, SIGKILL, LONG_INFO); assert(n > 0 && n < sizeof bigbuf); memset(recvbuf, 0, sizeof recvbuf); assert((r = safe_write(sockfd, bigbuf, n)) == n); assert((r = safe_read(sockfd, recvbuf, sizeof recvbuf)) != -1); assert(strcmp(recvbuf, "error\n") == 0); } static void test_child_all(void) { int N = 5; /* Repeat all tests N times. */ while (N--) { int T = 10; while (T--) { pid_t pid = fork(); assert(pid >= 0); if (pid == 0) { /* Son. */ test_lib_use(); test_timeout(); test_bad_conections(); exit(0); } } dream(60); } } int main(void) { struct sigaction act, oact; pid_t daemon_pid; struct sched_param sp; printf("This will take a long time...\n"); cat_set_device("/tmp/watchcat"); test_configuration_parser(); test_max_conections(); /* Ignore SIGCHLD. */ act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); act.sa_flags = 0; assert(sigaction(SIGCHLD, &act, &oact) == 0); daemon_pid = fork(); assert(daemon_pid >= 0); if (daemon_pid == 0) { /* Son. */ exec_master("test_general.conf"); } dream(3); test_child_all(); sp.sched_priority = 99; assert(sched_setscheduler(0, SCHED_RR, &sp) == 0); test_child_all(); assert(kill(daemon_pid, SIGTERM) == 0); dream(3); assert(unlink("/tmp/watchcat") == 0); /* Restore SIGCHLD handler. */ assert(sigaction(SIGCHLD, &oact, NULL) == 0); return 0; } watchcatd-1.2.1/tester/test_general.conf0000644001177500117750000000053111053071476021323 0ustar lua.osslua.oss00000000000000# Test for: # - "almost usual" configuration; # - general tests. realtime = true priority = 1 user = nobody master_debug_level = 32767 master_pid_file = /tmp slave_debug_level = 32767 slave_device = /tmp/watchcat slave_max_connections = 100 slave_max_connections_per_pid = 1 watchcatd-1.2.1/tester/test_max_conections.conf0000644001177500117750000000103211053071476022714 0ustar lua.osslua.oss00000000000000# Test for: # - max conections; # - max conections by pid; # - parse configuration; # - not usual configuration. realtime = false priority = 20 #user = Idonotexist # comment. user = nobody # comment. master_debug_level =32767 master_pid_file = /tmp/tester.pid slave_debug_level = 32767 slave_device = /tmp/watchcat slave_max_connections= 10 slave_max_connections_per_pid=2 # blah watchcatd-1.2.1/tester/Makefile0000644001177500117750000000014011053071476017434 0ustar lua.osslua.oss00000000000000all: gcc -Wall -c cattester.c -I ../libwcat gcc -o cattester cattester.o -L ../libwcat -lwcat watchcatd-1.2.1/master.h0000644001177500117750000000065111053071476016141 0ustar lua.osslua.oss00000000000000/* ** $Id: master.h 1654 2006-05-29 18:18:02Z andre $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #ifndef MASTER_H #define MASTER_H #define FROM_SLAVE_TO_MASTER_FD 3 #define SOCKET_LISTENER_FD 4 #define MSG_KILL 0 #define MSG_LOG 1 struct kill_msg { int fd; pid_t pid; int signal; }; struct log_msg { int priority; int length; }; #endif /* MASTER_H */ watchcatd-1.2.1/watchcatd.c0000644001177500117750000000031111053071476016574 0ustar lua.osslua.oss00000000000000/* ** $Id: watchcatd.c 1654 2006-05-29 18:18:02Z andre $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #include "watchcatd.h" WATCHCAT_GLOBAL_CONF GLOBAL_CONF; watchcatd-1.2.1/ChangeLog0000644001177500117750000000055711053071476016254 0ustar lua.osslua.oss00000000000000### Version 1.1 Added status to watchcatd. See wcatstat script. Marco Molinaro contributed with a preliminary code. Solved the problem that catslave work chrooted and can't to open a new socket to syslogd after it restarts. Solution: catslave send the log message to catmaster, that calls syslog. ### Version 1.0 Initial version. watchcatd-1.2.1/watchcatd.h0000644001177500117750000000124011053071476016603 0ustar lua.osslua.oss00000000000000/* ** $Id: watchcatd.h 1654 2006-05-29 18:18:02Z andre $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #ifndef WATCHCATD_H #define WATCHCATD_H typedef struct { /* Common settings. */ int realtime_mode; int priority; char user[256]; /* Master settings only. */ struct { int debug_level; char pid_file[256]; } master; /* Slave settings only. */ struct { int debug_level; char device[256]; int max_conections; int max_conections_per_pid; } slave; } WATCHCAT_GLOBAL_CONF; extern WATCHCAT_GLOBAL_CONF GLOBAL_CONF; #endif /* WATCHCATD_H */ watchcatd-1.2.1/slave.h0000644001177500117750000000031611053071476015756 0ustar lua.osslua.oss00000000000000/* ** $Id: slave.h 1654 2006-05-29 18:18:02Z andre $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #ifndef SLAVE_H #define SLAVE_H /* EMPTY */ #endif /* SLAVE_H */ watchcatd-1.2.1/watchcatd.init0000755001177500117750000000236111053071476017327 0ustar lua.osslua.oss00000000000000#!/bin/sh # # $Id: watchcatd.init 1654 2006-05-29 18:18:02Z andre $ # # chkconfig: 12345 02 98 # description: Software watchcat, but less drastic than the usual solutions. # # processname: watchcatd # config: /etc/watchcatd.conf # config: /etc/sysconfig/watchcatd # MASTER_PROG=/usr/lib/watchcatd/catmaster CONFIG_FILE=/etc/watchcatd.conf SYSCONFIG_FILE=/etc/sysconfig/watchcatd # Source function library. . /etc/rc.d/init.d/functions [ -x ${MASTER_PROG} -a -e ${CONFIG_FILE} ] || exit 0 OPTIONS="" if [ -f ${SYSCONFIG_FILE} ]; then . ${SYSCONFIG_FILE} fi # See how we were called. case "${1}" in start) gprintf "Starting watchcatd: " daemon /usr/lib/watchcatd/catmaster ${OPTIONS} && touch /var/lock/subsys/watchcatd echo ;; stop) gprintf "Stopping watchcatd: " killproc catmaster rm -f /var/lock/subsys/watchcatd echo ;; restart|reload) $0 stop $0 start ;; status) echo "Watchcatd status:" /usr/sbin/wcatstat if [ "$?" != "0" ]; then echo -n "Watchcatd is *not* running" if [ -f "/var/lock/subsys/watchcatd" ]; then echo " but /var/lock/subsys/watchcatd still exists." else echo "." fi fi ;; *) gprintf "Usage: watchcatd {start|stop|restart|reload|status}\n" exit 1 ;; esac exit 0 watchcatd-1.2.1/COPYRIGHT0000644001177500117750000000077011053071476015772 0ustar lua.osslua.oss00000000000000watchcatd license ----------------- watchcatd is licensed under the GNU General Public License (GPL). This means that watchcatd is a free software and can be used for both academic and commercial purposes at absolutely no cost. For details and rationale, see http://www.gnu.org/copyleft/ . =============================================================================== Copyright (c) 2004 Digirati. =============================================================================== (end of COPYRIGHT) watchcatd-1.2.1/loadconf.h0000644001177500117750000000034611053071476016434 0ustar lua.osslua.oss00000000000000/* ** $Id: loadconf.h 1654 2006-05-29 18:18:02Z andre $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #ifndef LOADCONF_H #define LOADCONF_H void load_conf(char *); #endif /* LOADCONF_H */ watchcatd-1.2.1/utils.c0000644001177500117750000000657411055253376016016 0ustar lua.osslua.oss00000000000000/* ** $Id: utils.c 2698 2008-08-27 14:03:38Z andre.dig $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #include #include #include #include #include #include #include #include #include #include #include #include #include "utils.h" extern char **environ; /* You don't have to call _myassert directly, use the myassert macro. * The return mean nothing, it only prevents warnings. * The library client musts define mysyslog and mysyslog can't call myassert * or myassert_sys! */ int _myassert(char *exp, char *filename, int line, const char *func) { mysyslog(LOG_ALERT, "FATAL ERROR, source_filename=`%s', " "line=%i, function=%s assertion=`%s'", filename, line, func, exp); exit(1); return 0; } /* You don't have to call _myassert_sys directly, use the myassert_sys macro. * The return mean nothing, it only prevents warnings. * The library client musts define mysyslog and mysyslog can't call myassert * or myassert_sys! */ int _myassert_sys(char *exp, char *filename, int line, const char *func) { int e = errno; mysyslog(LOG_ALERT, "FATAL ERROR, source_filename=`%s', " "line=%i, function=%s assertion=`%s' errno=%i, strerror=`%s'", filename, line, func, exp, e, strerror(e)); exit(e); return 0; } int is_fd_open(int fd) { struct stat dummy; return fstat(fd, &dummy) == 0; } struct env_list { char *name; char *val; }; void restrict_env(void) { int i; char *envp; char *allowed_env[] = { "TZ" }; #define NALLOWED (sizeof(allowed_env)/sizeof(char *)) struct env_list newenv[NALLOWED]; for (i = 0; i < NALLOWED; i++) { envp = getenv(allowed_env[i]); newenv[i].name = (envp ? strdup(allowed_env[i]) : NULL); newenv[i].val = (envp ? strdup(envp) : NULL); } environ = NULL; for (i = 0; i < NALLOWED; i++) if (newenv[i].name != NULL) setenv(newenv[i].name, newenv[i].val, 1); setenv("PATH", "/bin/:/usr/bin/", 1); free(envp); envp = NULL; } /* These are all protections inherited across a fork and shared in watchcat's * process group. * The protect_process_group function must be called when watchcatd master * is starting. */ void protect_process_group(int nodaemon, int priority) { struct sched_param sp; signal(SIGPIPE, SIG_IGN); sp.sched_priority = priority; myassert_sys(sched_setscheduler(0, SCHED_RR, &sp) == 0); restrict_env(); if (nodaemon) { myassert_sys(chdir("/") == 0); myassert_sys(setpgid(0, 0) == 0); return; } myassert_sys(daemon(0, 0) == 0); } void drop_privileges(char *user) { struct passwd *pw; myassert_sys(pw = getpwnam(user)); /* Chroot */ myassert_sys(chroot(pw->pw_dir) == 0); myassert_sys(chdir("/") == 0); /* Drop privileges */ myassert_sys(initgroups(user, pw->pw_gid) == 0); myassert_sys(setgid(pw->pw_gid) == 0); myassert_sys(setuid(pw->pw_uid) == 0); myassert(seteuid(0) == -1 && setegid(0) == -1); } /* These are all protections doesn't inherited across a fork. * The protect_daemon function must be called when daemon is starting. */ void protect_daemon(int realtime) { if (realtime) myassert_sys(mlockall(MCL_CURRENT | MCL_FUTURE) == 0); } watchcatd-1.2.1/utils.h0000644001177500117750000000170611055262332016003 0ustar lua.osslua.oss00000000000000/* ** $Id: utils.h 2699 2008-08-27 15:02:49Z andre.dig $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #ifndef UTILS_H #define UTILS_H #include #ifndef __ASSERT_FUNCTION #ifdef __PRETTY_FUNCTION__ #define __ASSERT_FUNCTION __PRETTY_FUNCTION__ #else #define __ASSERT_FUNCTION __func__ #endif #endif #define myassert(exp) \ ((void) ((exp) ? 0 : _myassert( \ #exp, __FILE__, __LINE__, __ASSERT_FUNCTION))) #define myassert_sys(exp) \ ((void) ((exp) ? 0 : _myassert_sys( \ #exp, __FILE__, __LINE__, __ASSERT_FUNCTION))) int _myassert(char *exp, char *filename, int line, const char *func); int _myassert_sys(char *exp, char *filename, int line, const char *func); extern void mysyslog(int priority, const char *format, ...); int is_fd_open(int fd); void protect_process_group(int nodaemon, int priority); void protect_daemon(int realtime); void drop_privileges(char *user); #endif /* UTILS_H */ watchcatd-1.2.1/master.c0000644001177500117750000003061711055262332016134 0ustar lua.osslua.oss00000000000000/* ** $Id: master.c 2699 2008-08-27 15:02:49Z andre.dig $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "master.h" #include "utils.h" #include "watchcatd.h" #include "loadconf.h" /* DEBUG_LEVEL * Bit Description Volume * 0 Security. low * 1 Kill send. moderate/high * 2 Kill fail. low * 3 Children sock. low * 4 Children die. low * 5 Children finished. low */ #define BUG_SECURITY 1 #define BUG_KILL_SEND 2 #define BUG_KILL_FAIL 4 #define BUG_CHILD_SOCK 8 #define BUG_CHILD_DIE 16 #define BUG_CHILD_END 32 /* Alias for commonly used and miscellaneous configuration parameters. * These values need to be treated as constants! */ static int DEBUG_LEVEL = 1023; #ifdef WCAT_PREFIX static char EXEC_SLAVE[256] = WCAT_PREFIX "/lib/watchcatd"; #else static char EXEC_SLAVE[256] = "/usr/lib/watchcatd"; #endif static int LISTENER; static int CHILD_COUNT; static int FINISHING; #define DEFAULT_CONFIG_FILE "/etc/watchcatd.conf" /* NOTE, only assert can be used in mysyslog! */ void mysyslog(int priority, const char *format, ...) { va_list ap; openlog("cat/master", LOG_NDELAY | LOG_PID, LOG_DAEMON); va_start(ap, format); vsyslog(priority, format, ap); va_end(ap); closelog(); } static void mykill(int fd, pid_t pid, int sig) { if (pid <= 1 || pid == getpid()) { if (DEBUG_LEVEL & BUG_SECURITY) mysyslog(LOG_ERR, "SECURITY invalid pid to kill, fd=%i, pid=%i, " "mypid=%i", fd, pid, getpid()); return; } if (kill(pid, SIGKILL)) { if (DEBUG_LEVEL & BUG_KILL_FAIL) mysyslog(LOG_ERR, "KILL FAILED, fd=%i, pid=%i, signal=%i, " "errno=%i, strerror=`%s'", fd, pid, sig, errno, strerror(errno)); return; } if (DEBUG_LEVEL & BUG_KILL_SEND) mysyslog(LOG_ERR, "KILL sent, fd=%i, pid=%i, signal=%i", fd, pid, sig); } static void myread(int fd, void *buf, size_t count, jmp_buf env) { ssize_t r; ssize_t remaining = count; do { r = read(fd, (char *)buf + count - remaining, remaining); remaining -= r > 0 ? r : 0; } while (r > 0 && remaining > 0); if (r > 0 && remaining == 0) return; if (r < 0 && (DEBUG_LEVEL & BUG_CHILD_SOCK)) mysyslog(LOG_ERR, "SOCK read FAIL, fd=%i", fd); longjmp(env, 1); } static void child_read(int fd, short event, void *arg) { jmp_buf env; if (setjmp(env) == 0) { int type; myread(fd, &type, sizeof(type), env); switch (type) { case MSG_KILL: { struct kill_msg msg; myread(fd, &msg, sizeof(msg), env); mykill(msg.fd, msg.pid, msg.signal); break; } case MSG_LOG: { struct log_msg msg; char buf[128]; const int size = sizeof(buf); myread(fd, &msg, sizeof(msg), env); myassert(msg.length < size); myread(fd, buf, msg.length, env); buf[msg.length] = '\0'; openlog("cat/slave", LOG_NDELAY | LOG_PID, LOG_DAEMON); syslog(msg.priority, "%s", buf); closelog(); break; } default: myassert(0); } } else { struct event *ev = arg; event_del(ev); free(ev); myassert_sys(close(fd) == 0); } } static void chfdn(int oldfd, int newfd) { if (oldfd == newfd) return; myassert(!is_fd_open(newfd)); myassert_sys(dup2(oldfd, newfd) == newfd); myassert_sys(close(oldfd) == 0); } /* CAUTION: exec_on_slave only can be called on master's children! * This function doesn't return. * * */ static void exec_on_slave(int sfd, int slistener) { struct stat st; /* Control and socket fds. */ myassert_sys(close(FROM_SLAVE_TO_MASTER_FD) == 0); myassert_sys(close(SOCKET_LISTENER_FD) == 0); chfdn(sfd, FROM_SLAVE_TO_MASTER_FD); chfdn(slistener, SOCKET_LISTENER_FD); if (lstat(EXEC_SLAVE, &st) == 0 && S_ISREG(st.st_mode) && (st.st_mode & S_IXUSR)) { myassert_sys(execl(EXEC_SLAVE, EXEC_SLAVE, NULL) == 0); } mysyslog(LOG_ERR, "File `%s' doesn't exist or denied access or it's a " "simbolic link", EXEC_SLAVE); exit(0); } static void create_a_slave(void) { static int spare = 10; static time_t t = 0; int socks[2]; int mfd; /* Alias for master fd. */ int sfd; /* Alias for slave fd. */ int slistener; pid_t pid; struct event *evchild; int i; i = time(NULL); if (i != t) { t = i; spare = 10; } if (spare <= 0) { myassert(spare == 0); mysyslog(LOG_ERR, "The catslave is dying very fast, " "aborting the catmaster..."); exit(1); } spare--; myassert_sys(socketpair(PF_UNIX, SOCK_STREAM, 0, socks) == 0); mfd = socks[0]; sfd = socks[1]; myassert_sys(fcntl(mfd, F_SETFD, FD_CLOEXEC) == 0); /* Slave's copy from LISTENER */ slistener = dup(LISTENER); myassert(slistener >= 0); i = 3; do { pid = fork(); if (pid < 0) sleep(1); i--; } while (pid < 0 && i > 0); myassert(pid >= 0); if (pid == 0) exec_on_slave(sfd, slistener); /* Child. */ /* Father. */ CHILD_COUNT++; myassert_sys(close(sfd) == 0); myassert_sys(close(slistener) == 0); /* Pass configuration. */ myassert_sys(write(mfd, &GLOBAL_CONF, sizeof(GLOBAL_CONF)) == sizeof(GLOBAL_CONF)); /* Monitor requests to send signals. */ evchild = malloc(sizeof(struct event)); myassert(evchild); event_set(evchild, mfd, EV_READ | EV_PERSIST, child_read, evchild); event_add(evchild, NULL); } static int process_slave_exit(pid_t pid, int status) { if (DEBUG_LEVEL & BUG_CHILD_END) mysyslog(LOG_NOTICE, "CHILDREN ended, pid=%i, status=%i", pid, status); if (WIFEXITED(status)) { int exit_status = WEXITSTATUS(status); if (exit_status) { if (DEBUG_LEVEL & BUG_CHILD_DIE) { mysyslog(LOG_ERR, "CHILDREN unexpected DEATH, pid=%i, " "exit_status=%i", pid, exit_status); } create_a_slave(); return 1; } return 0; } myassert(WIFSIGNALED(status)); mysyslog(LOG_ERR, "CHILDREN unexpected DEATH by signal, pid=%i, signal=%i", pid, WTERMSIG(status)); create_a_slave(); return 1; } static void sigchld_cb(int fd, short event, void *arg) { pid_t pid; do { int status; pid = waitpid(-1, &status, WNOHANG); if (pid > 0) if (!process_slave_exit(pid, status)) CHILD_COUNT--; } while (pid > 0); myassert_sys(pid == 0 || errno == ECHILD); myassert(CHILD_COUNT >= 0); if (CHILD_COUNT > 0) return; if (FINISHING) { event_del((struct event *)arg); myassert(FINISHING == 1); return; } mysyslog(LOG_ALERT, "Something unexpected happened. " "I am not finishing, but I am without children. " "I go to initiate a son, but this problem must be investigated!"); create_a_slave(); } static void sigterm_cb(int fd, short event, void *arg) { FINISHING++; unlink(GLOBAL_CONF.master.pid_file); myassert_sys(kill(0, SIGTERM) == 0); } static int create_pid_file(char *filename) { FILE *file; struct stat st; if (lstat(filename, &st) == 0) { pid_t pid; if (!S_ISREG(st.st_mode)) { mysyslog(LOG_ERR, "The pid file already exists and it is not a " "regular file, filename=`%s'", filename); return 0; } file = fopen(filename, "r+"); myassert(file); fscanf(file, "%i", &pid); fclose(file); if (kill(pid, 0) == 0) { mysyslog(LOG_ERR, "Already there is a watchcatd running, pid=%i, " "filename=%s", pid, filename); return 0; } } file = fopen(filename, "w"); myassert(file); fprintf(file, "%i\n", getpid()); fclose(file); return 1; } static int work(int nodaemon) { struct event signal_chld; struct event signal_term; int sock; struct sockaddr_un addr; char *dev; /* Global alias settings. */ DEBUG_LEVEL = GLOBAL_CONF.master.debug_level; /* Protections. */ protect_process_group(nodaemon, GLOBAL_CONF.priority); protect_daemon(GLOBAL_CONF.realtime_mode); if (!create_pid_file(GLOBAL_CONF.master.pid_file)) return 1; /* Listener. */ sock = socket(PF_UNIX, SOCK_STREAM, 0); myassert(sock >= 0); dev = GLOBAL_CONF.slave.device; unlink(dev); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, dev, sizeof(addr.sun_path)-1); addr.sun_path[sizeof(addr.sun_path)-1] = '\0'; myassert_sys(bind(sock, (struct sockaddr *)&addr, SUN_LEN(&addr)) == 0); myassert_sys(listen(sock, 5) == 0); myassert_sys(chmod(dev, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == 0); myassert_sys(fcntl(sock, F_SETFD, FD_CLOEXEC) == 0); LISTENER = sock; /* Events. */ event_init(); event_set(&signal_chld, SIGCHLD, EV_SIGNAL | EV_PERSIST, sigchld_cb, &signal_chld); event_add(&signal_chld, NULL); event_set(&signal_term, SIGTERM, EV_SIGNAL, sigterm_cb, &signal_term); event_add(&signal_term, NULL); create_a_slave(); mysyslog(LOG_INFO, "watchcatd started"); event_dispatch(); mysyslog(LOG_INFO, "watchcatd finished"); /* The kernel will make all housekeeping. */ return 0; } /*** Before of change to daemon mode ***/ static void usage(FILE *fp) { fprintf(fp, "Usage: watchcatd [options]\n" "Options:\n" " -h, --help Show this message.\n" " -f, --config-file Choose an alternate configuration file.\n" ); } static void myclosefrom(int from) { struct rlimit rl; int i; /* The code below is not perfect, but it is well reasonable. * Sample problem: dup2(0, rl.rlim_max + 1000); */ assert(getrlimit(RLIMIT_NOFILE, &rl) == 0); for (i = from; i < rl.rlim_max; i++) close(i); } int main(int argc, char **argv) { int opt; char config_file[256] = DEFAULT_CONFIG_FILE; char *optstr = "f:hp:X"; int nodaemon = 0; int filedes[2]; struct option longopts[] = { {"config-file", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {"exec-path", required_argument, NULL, 'p'}, {"dont-detach", no_argument, NULL, 'X'}, }; myclosefrom(3); if (geteuid()) { fprintf(stderr, "Only root can start this service\n"); return 1; } /* Reserve fd positions. */ myassert_sys(pipe(filedes) == 0); myassert(filedes[0] == FROM_SLAVE_TO_MASTER_FD); myassert_sys(fcntl(filedes[0], F_SETFD, FD_CLOEXEC) == 0); myassert(filedes[1] == SOCKET_LISTENER_FD); myassert_sys(fcntl(filedes[1], F_SETFD, FD_CLOEXEC) == 0); while ((opt = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) { switch(opt) { case 'f': assert(strlen(optarg) < sizeof(config_file)); strcpy(config_file, optarg); break; case 'h': usage(stdout); return 0; case 'p': assert(strlen(optarg) < sizeof(EXEC_SLAVE)); strcpy(EXEC_SLAVE, optarg); break; case 'X': nodaemon = 1; break; case '?': usage(stderr); return 1; default: fprintf(stderr, "watchcatd: error handling command line flags.\n"); return 1; } } load_conf(config_file); assert(strlen(EXEC_SLAVE) + strlen("/catslave") < sizeof(EXEC_SLAVE)); strcat(EXEC_SLAVE, "/catslave"); return work(nodaemon); } watchcatd-1.2.1/loadconf.c0000644001177500117750000001645711055330365016436 0ustar lua.osslua.oss00000000000000/* ** $Id: loadconf.c 2703 2008-08-27 20:27:34Z andre.dig $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #include #include #include #ifdef __GLIBC__ #include #endif #include #include #include #include #include #include "loadconf.h" #include "watchcatd.h" #define DEFAULT_PID_FILE "/var/run/catmaster.pid" #define DEFAULT_DEVICE "/var/run/watchcat.socket" static int handle_master_debug_level(char *val, int *mod) { int n = atoi(val); if (n < 0 || n > 32767) return EINVAL; GLOBAL_CONF.master.debug_level = n; *mod = 1; return 0; } static int handle_priority(char *val, int *mod) { int n = atoi(val); if (n <= 0 || n >= 100) return EINVAL; GLOBAL_CONF.priority = n; *mod = 1; return 0; } static int handle_realtime(char *val, int *mod) { int n; if (strcmp(val, "true") == 0) n = 1; else if (strcmp(val, "false") == 0) n = 0; else return EINVAL; GLOBAL_CONF.realtime_mode = n; *mod = 1; return 0; } static int handle_user(char *val, int *mod) { if (strlen(val) >= sizeof GLOBAL_CONF.user) return ENAMETOOLONG; if (getpwnam(val) == NULL) { if (errno == 0 || errno == EBADF || errno == ESRCH) return EINVAL; /* user not found */ else return errno; } strcpy(GLOBAL_CONF.user, val); *mod = 1; return 0; } static int handle_slave_debug_level(char *val, int *mod) { int n; n = atoi(val); if (n < 0 || n > 32767) return EINVAL; GLOBAL_CONF.slave.debug_level = n; *mod = 1; return 0; } #define S_ISFTYPE(mode, type) (((mode) & S_IFMT) == (type)) static int test_path_and_stat(char *dest, int size, char *def, int type, char *val, int *mod) { char *end_val; int r, len; struct stat st; if (*val != '/') return EINVAL; len = strlen(val); if (len >= size) return ENAMETOOLONG; end_val = alloca(size); strcpy(end_val, val); if (lstat(end_val, &st) == -1) { char *p; if (errno != ENOENT) return errno; while (end_val[1] == '/') end_val++; p = strrchr(end_val, '/'); assert(p); /* If there is no file, check if the base directory exists. */ if (p > end_val) { *p = '\0'; if (lstat(end_val, &st) == -1) return errno == ENOENT ? ENOENT : EINVAL; if (!S_ISDIR(st.st_mode)) return EINVAL; *p = '/'; } strcpy(dest, end_val); *mod = 1; return 0; } if (S_ISDIR(st.st_mode)) { char *p; while (len > 0 && end_val[len - 1] == '/') { len--; end_val[len] = '\0'; } p = strrchr(def, '/'); assert(p); if (size <= len + strlen(p)) return ENAMETOOLONG; strcat(end_val, p); r = lstat(end_val, &st); if ((r == 0 || errno != ENOENT) && (r == -1 || !S_ISFTYPE(st.st_mode, type))) { return EINVAL; } } else if (!S_ISFTYPE(st.st_mode, type)) return EINVAL; strcpy(dest, end_val); *mod = 1; return 0; } static int handle_master_pid_file(char *val, int *mod) { return test_path_and_stat(GLOBAL_CONF.master.pid_file, sizeof(GLOBAL_CONF.master.pid_file), DEFAULT_PID_FILE, S_IFREG, val, mod); } static int handle_slave_device(char *val, int *mod) { return test_path_and_stat(GLOBAL_CONF.slave.device, sizeof(GLOBAL_CONF.slave.device), DEFAULT_DEVICE, S_IFSOCK, val, mod); } #define MAX_CONN (64 * 1024) static int handle_slave_max_connections(char *val, int *mod) { int n = atoi(val); if (n < 1 || n > MAX_CONN) return EINVAL; GLOBAL_CONF.slave.max_conections = n; *mod = 1; return 0; } static int handle_slave_max_per_pid(char *val, int *mod) { int n = atoi(val); if (n < 0 || n > MAX_CONN) return EINVAL; GLOBAL_CONF.slave.max_conections_per_pid = n; *mod = 1; return 0; } /* Config Engine */ typedef int (*VALUE_HANDLER)(char *, int *); typedef struct { char var[128]; VALUE_HANDLER handler; char defval[128]; } PARM; static PARM CONF_PARMS[] = { /* var handler defval */ {"realtime", handle_realtime, "true"}, {"priority", handle_priority, "1"}, {"user", handle_user, "nobody"}, {"master_debug_level", handle_master_debug_level, "1023"}, {"master_pid_file", handle_master_pid_file, DEFAULT_PID_FILE}, {"slave_debug_level", handle_slave_debug_level, "1023"}, {"slave_device", handle_slave_device, DEFAULT_DEVICE}, {"slave_max_connections", handle_slave_max_connections, "128"}, {"slave_max_connections_per_pid", handle_slave_max_per_pid, "2"}, }; #define NPARMS (sizeof(CONF_PARMS)/sizeof(PARM)) #define MAX_LINELEN 1024 typedef int MODIFIED[NPARMS]; static void store_config_parm(char *var, char *val, MODIFIED mod) { int i; for (i = 0; i < NPARMS; i++) if (strcmp(var, CONF_PARMS[i].var) == 0) { int err = CONF_PARMS[i].handler(val, &mod[i]); if (err != 0) { fprintf(stderr, "%s(= `%s'): %s\n", var, val, strerror(err)); exit(err); } return; } fprintf(stderr, "Unknown parameter: `%s'\n", var); exit(EINVAL); } static void set_defaults(MODIFIED mod) { int i; for (i = 0; i < NPARMS; i++) if (!mod[i]) { PARM *parm = &CONF_PARMS[i]; int err = parm->handler(parm->defval, &mod[i]); if (err != 0) { fprintf(stderr, "%s(= `%s'): %s\n", parm->var, parm->defval, strerror(err)); exit(err); } } } void load_conf(char *filename) { int err; char line[MAX_LINELEN]; char *varp, *valp; char *endvar, *endval; FILE *fp; MODIFIED mod; fp = fopen(filename, "r"); if (fp == NULL) { perror("fopen"); exit(errno); } memset(mod, 0, sizeof(mod)); err = 0; while (fgets(line, sizeof(line), fp) != NULL && ferror(fp) == 0) { varp = line; while (isspace(*varp)) varp++; if (*varp == '#' || *varp == '\0') /* comment or empty line */ continue; valp = strchr(line, '='); if (valp == NULL) { fclose(fp); fprintf(stderr, "Invalid line: `%s'\n", line); exit(EINVAL); } endvar = valp - 1; valp++; while (isspace(*endvar)) endvar--; *(endvar+1) = '\0'; while (isspace(*valp)) valp++; endval = strchr(valp, '#'); if (endval == NULL) endval = valp + strlen(valp); endval--; while (isspace(*endval)) endval--; *(endval+1) = '\0'; store_config_parm(varp, valp, mod); } set_defaults(mod); fclose(fp); } watchcatd-1.2.1/watchcatd.prod.conf0000644001177500117750000000070211055330365020243 0ustar lua.osslua.oss00000000000000# $Id: watchcatd.prod.conf 2703 2008-08-27 20:27:34Z andre.dig $ # # Global # realtime = true priority = 1 user = watchcat # # Master # master_debug_level = 61 master_pid_file = /var/run/catmaster.pid # # Slave # slave_debug_level = 472 slave_device = /var/run/watchcat.socket slave_max_connections = 1014 # 1k (connections) - 10 (internal use) slave_max_connections_per_pid = 1 watchcatd-1.2.1/wcatstat0000755001177500117750000000266011055330365016254 0ustar lua.osslua.oss00000000000000#!/usr/bin/perl ## $Id: wcatstat 2703 2008-08-27 20:27:34Z andre.dig $ ## watchcatd - Watchcat Daemon ## See copyright notice in distro's COPYRIGHT file use warnings; use strict; use Socket; sub print_cat (\%) { my ($cat) = @_; print($$ == $cat->{pid} ? '*' : ''); print($cat->{fd}, ':', $cat->{status}, ':', $cat->{version}, ':', $cat->{timeout}, ':', $cat->{pid}, ':', $cat->{uid}, ':', $cat->{signal}, ':', $cat->{info}, "\n"); } # # Main code. # $< == 0 or die "Only the super user can execute this script\n"; socket(WCAT, PF_UNIX, SOCK_STREAM, 0); connect(WCAT, sockaddr_un("/var/run/watchcat.socket")) or die "Can't connect to watchcatd: $!\n"; send(WCAT, "version: 1\ncommand: stat\n\n", 0) or die "Error: $!\n"; my %cat; my $i = 0; while() { my ($field_name, $field_value) = /^([^:]+):\s*([^\n]*)$/; if (not defined $field_name) { $_ eq "connect\n" and die "Too many connections\n"; $_ eq "\n" or die "Invalid format, line: `$_'\n"; last; } if ($field_name eq "block") { if ($i == 0) { print("\nfd:status:version:timeout:pid:uid:signal:info\n"); } else { print_cat(%cat); %cat = (); } $i++; next; } if ($i > 0) { $cat{$field_name} = $field_value; next; } print "${field_name}: $field_value\n"; } close WCAT; print_cat(%cat) if $i > 0; print("\n"); watchcatd-1.2.1/watchcatd.80000644001177500117750000000234211055330365016524 0ustar lua.osslua.oss00000000000000.\" $Id: watchcatd.8 2703 2008-08-27 20:27:34Z andre.dig $ .TH WATCHCATD 8 "January 2004" WATCHCATD "System Administration" .SH NAME watchcatd \- process monitoring daemon .SH SYNOPSIS .B watchcatd [-fhpX] [-f .I filename .B ] [-p .I pathname .B ] .SH DESCRIPTION .B watchcatd is a background daemon which monitors registered processes, killing them in case they lock up. As a secondary use, .B watchcatd can be set up to work as a timer. .SH OPTIONS .IP "-f, --config-file filename" Use the alternate system wide .I filename instead of .IR /etc/watchcatd.conf . It must be an absolute path. .IP "-h, --help" Display an usage message .IP "-p, --exec-path" Use a alternate absolute path to exec childrens. Useful for debugging purposes. .IP "-X, --dont-detach" Don't detach from the console. Useful for debugging purposes. .SH FILES .I /etc/watchcatd.conf .RS The system wide configuration file. See .BR watchcatd.conf (5) for further details. .RE .I /var/run/watchcat.socket .RS The watchcat device. .SH BUGS The current version doesn't support thread registry, only process registry to service. .SH AUTHORS .na .nf Michel Machado Andre Nathan .SH "SEE ALSO" .BR watchcatd.conf (5), .BR watchdog (8). watchcatd-1.2.1/slave.c0000644001177500117750000005245311145357051015760 0ustar lua.osslua.oss00000000000000/* ** $Id: slave.c 2829 2009-02-13 20:55:03Z andre.dig $ ** watchcatd - Watchcat Daemon ** See copyright notice in distro's COPYRIGHT file */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "slave.h" #include "master.h" #include "utils.h" #include "watchcatd.h" /* WARNING TO THE CODE WRITERS * Subtle protection * * The watchcat slave do just a read per fd returned by select. In addition, * the read is done with a small buffer. Don't forget this when editing the * code. * * Without this protection, a client can send much data to a cat and harm * the "timeout chronometer"'s precision. */ /* DEBUG_LEVEL * Bit Description Volume * 0 Create / finish a cat. high * 1 Parser header. high * 2 Body. high * 3 Timeout. low * 4 Security. low * 5 BIT FREE. - * 6 Critical fail. low * 7 Warnings. low/moderate * 8 Connection. low/moderate * 9 Connection OK. high * 10 Security fire. high */ #define BUG_CREATE_DROP 1 #define BUG_PARSER 2 #define BUG_BODY 4 #define BUG_TIMEOUT 8 #define BUG_SECURITY 16 #define BUG_CRITICAL_FAIL 64 #define BUG_WARNING 128 #define BUG_CONNECTION 256 #define BUG_CONNECTION_OK 512 #define BUG_SECURITY_FIRE 1024 /* Alias for configuration items very used and miscellaneous. * These values need to be treated as constants! */ static int DEBUG_LEVEL = 2047; static int CAT_MAXCAT = 1; /* (struct cat).status values */ #define CAT_PARSING 0 #define CAT_WORKING 1 #define CMD_NIL 0 #define CMD_STAT 1 struct cat { LIST_ENTRY(cat) cats; int status; int fd; /* Cat fd. */ char *buf; /* Buffer for header parser. */ int pos; /* End of buf. */ int version; /* Protocol version. */ int timeout; /* Timeout in seconds. */ pid_t pid; /* Client's PID. */ uid_t uid; /* Client's UID. */ int signal; /* Signal to send on timeout. */ char info[128]; /* A string to insert in log on timeout. */ int cmd; /* Command. */ struct event event; /* libevent's struct for event handler. */ }; struct stats { unsigned int total_cat; /* Number of cats created so far. */ unsigned int total_kill; /* Number of kills. */ }; /* Globals */ static LIST_HEAD(catlisthead, cat) CATS; static int CAT_COUNT; static struct stats STATS; /* NOTE, only assert can be used in write_to_master! */ void write_to_master(const void *buf, size_t count) { size_t r; do { r = write(FROM_SLAVE_TO_MASTER_FD, buf, count); } while(r == -1 && errno == EINTR); assert(r > 0); assert(r == count); } /* NOTE, only assert can be used in mysyslog! */ void mysyslog(int priority, const char *format, ...) { char buf[128]; const int size = sizeof(buf); const int type = MSG_LOG; struct log_msg msg; va_list ap; int len; va_start(ap, format); len = vsnprintf(buf, size, format, ap); va_end(ap); assert(len > 0); len = (len < size) ? len : (size - 1); msg.priority = priority; msg.length = len; write_to_master(&type, sizeof(type)); write_to_master(&msg, sizeof(msg)); write_to_master(buf, len); } void mywrite(int fd, const void *buf, size_t count) { ssize_t r; do { r = write(fd, buf, count); } while(r == -1 && errno == EINTR); /* Debug purpose. DON'T enable in production environment! */ #if 0 myassert_sys(r > 0); myassert(r == count); #endif } static void myclose(int fd) { int r = close(fd); if (r && DEBUG_LEVEL & BUG_WARNING) mysyslog(LOG_WARNING, "close FAIL, fd=%i, errno=%i, strerror=`%s'", fd, errno, strerror(errno)); } #define BUFSIZE 128 /* The msg parameter is only returned to client, before close fd, when * cat->status == CAT_PARSING. */ static void cat_finish(struct cat *cat, char *msg) { int fd; myassert(cat->status == CAT_PARSING || cat->status == CAT_WORKING); fd = cat->fd; if (cat->status == CAT_PARSING) { char *buf = cat->buf; int count = snprintf(buf, BUFSIZE, "%s\n", msg); myassert(count > 0 && count < BUFSIZE); mywrite(fd, buf, count); free(buf); cat->buf = NULL; } CAT_COUNT--; myclose(fd); LIST_REMOVE(cat, cats); free(cat); if (DEBUG_LEVEL & BUG_CREATE_DROP) mysyslog(LOG_INFO, "DROP fd=%i, CAT_COUNT=%i, msg=`%s'", fd, CAT_COUNT, msg); } static void cat_ev_header_read(int fd, short event, void *arg); static void cat_ev_body_read(int fd, short event, void *arg); static struct cat *cat_create(int fd, pid_t pid, uid_t uid) { struct cat *cat; cat = calloc(1, sizeof(struct cat)); if (cat == NULL) { if (DEBUG_LEVEL & BUG_CRITICAL_FAIL) mysyslog(LOG_CRIT, "FAIL out of memory, fd=%i", fd); return NULL; } cat->buf = malloc(BUFSIZE); if (cat->buf == NULL) { if (DEBUG_LEVEL & BUG_CRITICAL_FAIL) mysyslog(LOG_CRIT, "FAIL out of memory, fd=%i, pid=%i", fd, pid); free(cat); return NULL; } LIST_INSERT_HEAD(&CATS, cat, cats); cat->status = CAT_PARSING; cat->fd = fd; cat->timeout = 60; cat->pid = pid; cat->uid = uid; cat->signal = SIGKILL; cat->info[0] = '\0'; cat->cmd = CMD_NIL; CAT_COUNT++; if ((DEBUG_LEVEL & BUG_SECURITY) && STATS.total_cat == (unsigned int) -1) mysyslog(LOG_INFO, "TOTAL_CAT limit reached, count restarted"); STATS.total_cat++; if (DEBUG_LEVEL & BUG_CREATE_DROP) mysyslog(LOG_INFO, "CREATE fd=%i, CAT_COUNT=%i", fd, CAT_COUNT); return cat; } static void command_stat(struct cat *cat) { struct cat *curr; int fd = cat->fd; char buf[128]; const int size = sizeof(buf); int buf_len; buf_len = snprintf(buf, size, "total_cat: %u\ntotal_kill: %u\n", STATS.total_cat, STATS.total_kill); mywrite(fd, buf, buf_len); for (curr = CATS.lh_first; curr != NULL; curr = curr->cats.le_next) { buf_len = snprintf(buf, size, "block:\nstatus: %i\nfd: %i\nversion: %i\n" "timeout: %i\npid: %i\nuid: %i\n", curr->status, curr->fd, curr->version, curr->timeout, curr->pid, curr->uid); mywrite(fd, buf, buf_len); buf_len = snprintf(buf, size, "signal: %i\ninfo: ", curr->signal); mywrite(fd, buf, buf_len); mywrite(fd, curr->info, strlen(curr->info)); mywrite(fd, "\n", 1); } mywrite(fd, "\n", 1); } static char *clean_in_place(char *s) { char *ns = s; char *end; myassert(s); if (!*s) return s; while (isspace(*ns)) ns++; end = ns; while (*end) end++; end--; while (isspace(*end)) end--; *(end + 1) = '\0'; return ns; } /* ATENTION: the strings field_name and field_value can to be modified! */ static int cat_eval_field(struct cat *cat, char *field_name, char *field_value) { int fd = cat->fd; field_name = clean_in_place(field_name); field_value = clean_in_place(field_value); if (strcmp(field_name, "version") == 0) { cat->version = atoi(field_value); } else if (strcmp(field_name, "timeout") == 0) { cat->timeout = atoi(field_value); } else if (strcmp(field_name, "signal") == 0) { cat->signal = atoi(field_value); } else if (strcmp(field_name, "info") == 0) { char *p = cat->info; strncpy(p, field_value, sizeof(cat->info)-1); p[sizeof(cat->info)-1] = '\0'; for (; *p; p++) if (!isprint(*p)) *p = '_'; } else if (strcmp(field_name, "command") == 0) { if (cat->uid) { if (DEBUG_LEVEL & BUG_SECURITY) mysyslog(LOG_ERR, "SECURITY command field requires super user, " "pid=%i, uid=%i", cat->pid, cat->uid); return 1; } if (strcmp(field_value, "stat") == 0) { cat->cmd = CMD_STAT; } else { if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER command=`%s' unknown, fd=%i", field_value, fd); return 1; } } else { if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER field_name=`%s' unknown, fd=%i", field_name, fd); return 1; } if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_INFO, "PARSER fd=%i, field_name=`%s' field_value=`%s'", fd, field_name, field_value); return 0; } static int cat_process_header(struct cat *cat) { int version = cat->version; int timeout = cat->timeout; int signal = cat->signal; pid_t pid = cat->pid; uid_t uid = cat->uid; int fd = cat->fd; const char *info = cat->info; int cmd = cat->cmd; myassert(cat->status == CAT_PARSING); if (cmd == CMD_NIL) { struct event *ev; struct timeval tm; if (version != 1 || timeout < 5 || signal < 1 || signal > 64 || pid <= 1) { if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER header FAIL, fd=%i, version=%i, " "timeout=%i, pid=%i, uid=%i, signal=%i, info=`%s'", fd, version, timeout, pid, uid, signal, info); return 1; } ev = &cat->event; tm.tv_sec = timeout; tm.tv_usec = 0; event_del(ev); event_set(ev, fd, EV_READ, cat_ev_body_read, cat); event_add(ev, &tm); mywrite(fd, "ok\n", 3); } else { myassert(cat->cmd == CMD_STAT); } cat->status = CAT_WORKING; free(cat->buf); cat->buf = NULL; if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_INFO, "PARSER header OK, fd=%i, version=%i, " "timeout=%i, pid=%i, uid=%i, signal=%i, info=`%s'", fd, version, timeout, pid, uid, signal, info); return 0; } /* Returns zero on success and 1 on fail. */ static int cat_parser(struct cat *cat) { int fd = cat->fd; char *buf = cat->buf; int pos = cat->pos; char *nl_start; char *fld_start; int len; int count; myassert(cat->status == CAT_PARSING); len = BUFSIZE - pos - 1; count = read(fd, buf + pos, len); if (count < 0) { if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER read FAIL, fd=%i, " "result=%i, errno=%i, strerror=`%s'", fd, count, errno, strerror(errno)); return 1; } if (count == 0) { if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER socket closed, fd=%i", fd); return 1; } buf[pos + count] = '\0'; /* Eliminate big lines. */ nl_start = strchr(buf, '\n'); if (nl_start == NULL) { if (count < len) { cat->pos += count; return 0; } if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER big line, fd=%i, line=`%s'", fd, buf); return 1; } /* Parser fields. */ fld_start = buf; while (nl_start) { char *colon_start; if (fld_start == nl_start) { /* End of header. */ return cat_process_header(cat); } colon_start = strchr(fld_start, ':'); if (colon_start == NULL) { if (DEBUG_LEVEL & BUG_PARSER) mysyslog(LOG_ERR, "PARSER invalid line, fd=%i", fd); return 1; } *colon_start = '\0'; *nl_start = '\0'; if (cat_eval_field(cat, fld_start, colon_start + 1)) return 1; fld_start = nl_start + 1; nl_start = strchr(fld_start, '\n'); } cat->pos = pos + count - (fld_start - buf) / sizeof(char); memmove(buf, fld_start, cat->pos); return 0; } static void cat_ev_header_read(int fd, short event, void *arg) { struct cat *cat = arg; myassert(cat->status == CAT_PARSING); if (event & EV_READ) { if (cat_parser(cat)) { event_del(&cat->event); cat_finish(cat, "error"); return; } if (cat->status == CAT_WORKING) { if (cat->cmd == CMD_STAT) { command_stat(cat); event_del(&cat->event); cat_finish(cat, "stat"); } return; } if (!(event & EV_TIMEOUT)) { return; } } /* Timeout on header parsing. */ myassert(event & EV_TIMEOUT); if (DEBUG_LEVEL & BUG_TIMEOUT) mysyslog(LOG_ERR, "TIMEOUT on header parsing, pid=%i", cat->pid); cat_finish(cat, "timeout"); } static void mykill(int fd, pid_t pid, int sig) { struct kill_msg msg; const int type = MSG_KILL; msg.fd = fd; msg.pid = pid; msg.signal = sig; write_to_master(&type, sizeof(type)); write_to_master(&msg, sizeof(msg)); } static int cat_ev_body_read_with_ret(int fd, short event, void *arg) { struct cat *cat = arg; myassert(cat->status == CAT_WORKING); if (event & EV_READ) { char buf[BUFSIZE]; int count = read(fd, buf, sizeof(buf)); if (count > 0) { struct timeval tm; if (DEBUG_LEVEL & BUG_BODY) mysyslog(LOG_INFO, "BODY heart beat, fd=%i", fd); tm.tv_sec = cat->timeout; tm.tv_usec = 0; event_add(&cat->event, &tm); return 0; } if (count < 0) { if (DEBUG_LEVEL & BUG_BODY) mysyslog(LOG_ERR, "BODY read FAIL, fd=%i, result=%i, errno=%i, " "strerror=`%s'", fd, count, errno, strerror(errno)); cat_finish(cat, "end_error"); return 1; } cat_finish(cat, "end"); return 1; } /* Cat's timeout. */ myassert(event & EV_TIMEOUT); if (DEBUG_LEVEL & BUG_TIMEOUT) mysyslog(LOG_ERR, "TIMEOUT, pid=%i, uid=%i, signal=%i, timeout=%i, " "info=`%s'", cat->pid, cat->uid, cat->signal, cat->timeout, cat->info); mykill(fd, cat->pid, cat->signal); cat_finish(cat, "timeout"); if ((DEBUG_LEVEL & BUG_SECURITY) && STATS.total_kill == (unsigned int) -1) mysyslog(LOG_INFO, "TOTAL_KILL limit reached, count restarted"); STATS.total_kill++; return 1; } static void cat_ev_body_read(int fd, short event, void *arg) { cat_ev_body_read_with_ret(fd, event, arg); } static int cat_conn_per_pid_limit(int conn, pid_t pid, int limit) { int count = CAT_COUNT; int can = limit; struct cat *cat; myassert(limit >= 0); if (limit == 0 || can > count) return 0; for (cat = CATS.lh_first; cat != NULL && can <= count; cat = cat->cats.le_next) { if (cat->pid == pid) { struct event *ev = &cat->event; if (ev->ev_flags & EVLIST_ACTIVE) { event_del(ev); if (cat_ev_body_read_with_ret(ev->ev_fd, ev->ev_res, ev->ev_arg)) return 0; } can--; if (can <= 0) break; } count--; } return can < 1; } static pid_t get_pid_from_fd(int fd, uid_t *uid) { #if defined(SO_PEERCRED) /* Tested on Linux */ struct ucred crd; socklen_t cl = sizeof(crd); if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &crd, &cl)) { if (DEBUG_LEVEL & BUG_SECURITY) mysyslog(LOG_ERR, "SECURITY get credentials FAILED, fd=%i, " "errno=%i, strerror=`%s'", fd, errno, strerror(errno)); return -1; } if (crd.pid > 1) { if (DEBUG_LEVEL & BUG_SECURITY_FIRE) mysyslog(LOG_INFO, "SECURITY fd=%i, peer's data: pid=%i, uid=%i, " "gid=%i", fd, crd.pid, crd.uid, crd.gid); if (uid) *uid = crd.uid; return crd.pid; } if (DEBUG_LEVEL & BUG_SECURITY) mysyslog(LOG_ERR, "SECURITY invalid pid, fd=%i, pid=%i, uid=%i, gid=%i", fd, crd.pid, crd.uid, crd.gid); return -1; #elif defined(SCM_CREDS) /* Tested on FreeBSD */ char buf; ssize_t r; struct msghdr msg; struct iovec iov; struct cmsgcred *crd; union { struct cmsghdr hdr; /* for alignment */ char crd[CMSG_SPACE(sizeof(struct cmsgcred))]; } cmsg; iov.iov_base = &buf; iov.iov_len = 1; memset(&msg, 0, sizeof(msg)); msg.msg_iov = &iov; msg.msg_iovlen = 1; memset(&cmsg, 0, sizeof(cmsg)); msg.msg_control = (caddr_t)&cmsg; msg.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred)); do { r = recvmsg(fd, &msg, 0); } while(r == -1 && errno == EINTR); myassert(cmsg.hdr.cmsg_len == CMSG_LEN(sizeof(struct cmsgcred))); myassert(cmsg.hdr.cmsg_type == SCM_CREDS); crd = (struct cmsgcred *)CMSG_DATA(&cmsg.hdr); if (crd->cmcred_pid > 1) { if (DEBUG_LEVEL & BUG_SECURITY_FIRE) mysyslog(LOG_INFO, "SECURITY fd=%i, peer's data: pid=%i, uid=%i, " "gid=%i", fd, crd->cmcred_pid, crd->cmcred_uid, crd->cmcred_gid); if (uid) *uid = crd->cmcred_uid; return crd->cmcred_pid; } if (DEBUG_LEVEL & BUG_SECURITY) mysyslog(LOG_ERR, "SECURITY invalid pid, fd=%i, pid=%i, uid=%i, gid=%i", fd, crd->cmcred_pid, crd->cmcred_uid, crd->cmcred_gid); #endif return -1; } static void listen_read(int fd, short event, void *arg) { /* New connection. */ struct sockaddr_un addr; socklen_t addr_len = sizeof(addr); int conn = accept(fd, (struct sockaddr *)&addr, &addr_len); pid_t pid; uid_t uid; struct cat *cat; myassert(conn >= 0); myassert_sys(fcntl(conn, F_SETFD, FD_CLOEXEC) == 0); if (CAT_COUNT >= CAT_MAXCAT) { myassert(CAT_COUNT == CAT_MAXCAT); if (DEBUG_LEVEL & BUG_CONNECTION) mysyslog(LOG_ERR, "CONNECT FAIL, too many conections, " "CAT_MAXCAT=%i", CAT_MAXCAT); } else if ((pid = get_pid_from_fd(conn, &uid)) < 0) { if (DEBUG_LEVEL & BUG_CONNECTION) mysyslog(LOG_ERR, "CONNECT FAIL, pid for conn=%i unknown", conn); } else if (cat_conn_per_pid_limit(conn, pid, GLOBAL_CONF.slave.max_conections_per_pid)) { if (DEBUG_LEVEL & BUG_CONNECTION) mysyslog(LOG_ERR, "CONNECT FAIL, max_conections_per_pid=%i, " "pid=%i, uid=%i", GLOBAL_CONF.slave.max_conections_per_pid, pid, uid); } else if ((cat = cat_create(conn, pid, uid)) == NULL) { if (DEBUG_LEVEL & BUG_CONNECTION) mysyslog(LOG_ERR, "CONNECT FAIL, cat_create returned error, " "conn=%i, pid=%i, uid=%i", conn, pid, uid); } else { struct event *ev; struct timeval tm = {5, 0}; myassert(cat); ev = &cat->event; event_set(ev, conn, EV_READ | EV_PERSIST, cat_ev_header_read, cat); event_add(ev, &tm); if (DEBUG_LEVEL & BUG_CONNECTION_OK) mysyslog(LOG_INFO, "CONNECT OK, conn=%i", conn); return; } /* Fail. */ mywrite(conn, "connect\n", 8); myclose(conn); } static void sigterm_cb(int fd, short event, void *arg) { exit(0); } static void work(void) { struct event ev_listen_read; struct event ev_signal_term; event_init(); event_set(&ev_listen_read, SOCKET_LISTENER_FD, EV_READ | EV_PERSIST, listen_read, &ev_listen_read); event_add(&ev_listen_read, NULL); event_set(&ev_signal_term, SIGTERM, EV_SIGNAL, sigterm_cb, &ev_signal_term); event_add(&ev_signal_term, NULL); event_dispatch(); } int main(void) { struct rlimit rlim; /* Close-on-exec. */ myassert_sys(fcntl(FROM_SLAVE_TO_MASTER_FD, F_SETFD, FD_CLOEXEC) == 0); myassert_sys(fcntl(SOCKET_LISTENER_FD, F_SETFD, FD_CLOEXEC) == 0); /* Get GLOBAL_CONF. */ myassert_sys(read(FROM_SLAVE_TO_MASTER_FD, &GLOBAL_CONF, sizeof(GLOBAL_CONF)) == sizeof(GLOBAL_CONF)); DEBUG_LEVEL = GLOBAL_CONF.slave.debug_level; CAT_MAXCAT = GLOBAL_CONF.slave.max_conections; LIST_INIT(&CATS); /* RLIMIT restrictions. */ myassert_sys(getrlimit(RLIMIT_NOFILE, &rlim) == 0); if (rlim.rlim_cur < GLOBAL_CONF.slave.max_conections + 10) { /* * Set new file descriptor limits: * - std{in,out,err}; * - parent<->child socket; * - listen socket; * - five eventual fds (just do be safe). */ rlim.rlim_cur = GLOBAL_CONF.slave.max_conections + 10; if (rlim.rlim_cur > rlim.rlim_max) { rlim.rlim_max = rlim.rlim_cur; mysyslog(LOG_WARNING, "Changing file descriptor hard limit to %i", (int)rlim.rlim_max); } myassert_sys(setrlimit(RLIMIT_NOFILE, &rlim) == 0); } protect_daemon(GLOBAL_CONF.realtime_mode); drop_privileges(GLOBAL_CONF.user); work(); /* The kernel will make all housekeeping. */ return 0; } watchcatd-1.2.1/TODO0000644001177500117750000000174311145357121015164 0ustar lua.osslua.oss00000000000000### Version 1.3 @ Permitir reload da configuração. Estratégia: o master reler a configuração comparando os valores atuais e atualizando, se necessário, a estrutura de configuração global dele. Se houver alguma novidade que precise ser passada para o filho passar para o processo de reload descrito asseguir. Desabilitar o tratamento de um novo reload até segunda ordem. Forkar um novo filho, ele irá remover o soket antigo e fazer o bind/listen para esse. Esse é o único momento que pode haver perda de conexão. Esse novo filho já irá assumir todas as conexões novas com a configuração nova. Com um novo filho trabalhando, enviar um SIGHUP para o primeiro para avisar que quando encerrarem as conexões pendendes que encerre suas atividades. Com a morte do primeiro filho concluída, basta reativar o tratamento de reload. Um complicador para o master, além de implementar o processo já comentado acima, é, durante a existência de dois filhos, ler os dois pipes dos filhos com select. watchcatd-1.2.1/Makefile0000644001177500117750000000364111145357316016141 0ustar lua.osslua.oss00000000000000PKGNAME= watchcatd PKGVERSION= 1.2.1 PREFIX ?= /usr/local CFLAGS += -O2 -Wall -pedantic -L$(PREFIX)/lib -I$(PREFIX)/include -DWCAT_PREFIX=\"$(PREFIX)\" #CFLAGS += -O2 -Wall -pedantic -L$(PREFIX)/lib -I$(PREFIX)/include -DWCAT_PREFIX=\"$(PREFIX)\" -ggdb all: catmaster catslave catmaster: utils.o master.o loadconf.o watchcatd.o $(CC) utils.o master.o loadconf.o watchcatd.o -levent -o catmaster $(CFLAGS) catslave: utils.o slave.o watchcatd.o $(CC) utils.o slave.o watchcatd.o -levent -o catslave $(CFLAGS) watchcatd.o: watchcatd.h watchcatd.c $(CC) -c watchcatd.c $(CFLAGS) master.o: master.h utils.h watchcatd.h loadconf.h master.c $(CC) -c master.c $(CFLAGS) slave.o: slave.h master.h utils.h watchcatd.h slave.c $(CC) -c slave.c $(CFLAGS) utils.o: utils.h utils.c $(CC) -c utils.c $(CFLAGS) loadconf.o: loadconf.h loadconf.c $(CC) -c loadconf.c $(CFLAGS) install: strip catmaster catslave install -d $(PREFIX)/lib/watchcatd install -d $(PREFIX)/man/man5 install -d $(PREFIX)/man/man8 install -m0755 catmaster $(PREFIX)/lib/watchcatd install -m0755 catslave $(PREFIX)/lib/watchcatd install -m0600 watchcatd.prod.conf /etc/watchcatd.conf install -m0644 watchcatd.8 $(PREFIX)/man/man8/ install -m0644 watchcatd.conf.5 $(PREFIX)/man/man5/ clean: rm -f *.o *.c~ *.h~ *.conf~ *.[0-9]~ catmaster catslave rm -f COPYRIGHT~ TODO~ Makefile~ *.init~ $(PKGNAME)-$(PKGVERSION).tar.bz2 if [ `basename ${PWD}` != "$(PKGNAME)-$(PKGVERSION)" ]; then \ rm -rf ../$(PKGNAME)-$(PKGVERSION); \ fi rpm: clean if [ `basename ${PWD}` != "$(PKGNAME)-$(PKGVERSION)" ]; then \ cp -a . ../$(PKGNAME)-$(PKGVERSION); \ fi tar -jcC .. --exclude .svn --exclude libwcat --exclude tester -f $(PKGNAME)-$(PKGVERSION).tar.bz2 $(PKGNAME)-$(PKGVERSION) rpm -ta $(PKGNAME)-$(PKGVERSION).tar.bz2 rm -rf $(PKGNAME)-$(PKGVERSION).tar.bz2 if [ `basename ${PWD}` != "$(PKGNAME)-$(PKGVERSION)" ]; then \ rm -rf ../$(PKGNAME)-$(PKGVERSION); \ fi watchcatd-1.2.1/watchcatd.spec0000644001177500117750000000614011145360002017276 0ustar lua.osslua.oss00000000000000# $Id: watchcatd.spec 2831 2009-02-13 21:02:56Z andre.dig $ %define name watchcatd %define version 1.2.1 %define release 1mdv Summary: Software watchdog, but less drastic than the usual solutions Name: %name Version: %version Release: %release License: GPL Group: System/Servers URL: http://oss.digirati.com.br/watchcatd/ # Please add comment with the right url/downloadpage. Source0: %name-%version.tar.bz2 BuildRoot: %_tmppath/%name-buildroot PreReq: rpm-helper %description watchcatd is a software service that monitors processes. A bug or malicious attacks to machine can lock up a process, leading to a deadlock or an unexpected condition. If a monitored process locks up, it is killed. On an alternate setup, watchcatd can be configured to work as a timer. %prep %setup -q %build export CFLAGS="%{optflags}" export PREFIX="/usr" %make %install %__rm -rf %buildroot install -d %{buildroot}%{_sbindir} install -d %{buildroot}%{_libdir}/watchcatd install -d %{buildroot}%{_sysconfdir}/init.d install -d %{buildroot}%{_mandir}/man{5,8} install -d %{buildroot}%{_docdir}/watchcatd install -m0750 catmaster %{buildroot}%{_libdir}/watchcatd install -m0750 catslave %{buildroot}%{_libdir}/watchcatd install -m0700 wcatstat %{buildroot}%{_sbindir}/wcatstat install -m0700 watchcatd.init %{buildroot}%{_sysconfdir}/init.d/watchcatd install -m0600 watchcatd.prod.conf %{buildroot}%{_sysconfdir}/watchcatd.conf install -m0644 watchcatd.8 %{buildroot}%{_mandir}/man8/ install -m0644 watchcatd.conf.5 %{buildroot}%{_mandir}/man5/ %pre %_pre_useradd watchcat /var/lib/watchcat /sbin/nologin install -m0700 -d /var/lib/watchcat chown root:root /var/lib/watchcat %post %_post_service watchcatd %preun %_preun_service watchcatd %postun if [ "$1" = "0" ]; then %_postun_userdel watchcat %__rm -rf /var/lib/watchcat fi %clean %__rm -rf %buildroot %files %defattr(-,root,root) %{_sbindir}/wcatstat %{_libdir}/watchcatd/catmaster %{_libdir}/watchcatd/catslave %config(noreplace) %{_sysconfdir}/init.d/watchcatd %config(noreplace) %{_sysconfdir}/watchcatd.conf %{_mandir}/man8/%name.8* %{_mandir}/man5/%name.conf.5* %doc COPYRIGHT ChangeLog TODO %changelog * Fri Feb 13 2009 Andre Nathan 1.2.1-1mdv - Version 1.2.1. * Wed Aug 27 2008 Andre Nathan 1.2-1mdk - Version 1.2. * Mon Apr 30 2004 Andre Nathan 1.1-3mdk - %_preun_service shall be executed during upgrades. * Mon Apr 19 2004 Andre Nathan 1.1-2mdk - Fix some bugs. * Fri Apr 09 2004 Andre Nathan 1.1-1mdk - Watchcatd 1.1 * Thu Feb 05 2004 Andre Nathan 1.0-2 - Export CFLAGS before building; - Fix typo in changelog. * Mon Feb 02 2004 Michel Machado 1.0-1 - Adjust version and watchcat user; - Restrict mode access for files; - Add COPYRIGHT. * Wed Jan 21 2004 Andre Nathan 0.0-2 - Add watchcatd user and macros for turning the service on. * Wed Jan 14 2004 Andre Nathan 0.0-1 - First version. watchcatd-1.2.1/LICENSE0000644001177500117750000004310310641012126015466 0ustar lua.osslua.oss00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. watchcatd-1.2.1/watchcatd.conf.50000644001177500117750000000704611233356132017451 0ustar lua.osslua.oss00000000000000.\" $Id: watchcatd.conf.5 1654 2006-05-29 18:18:02Z andre $ .TH WATCHCATD.CONF 5 "January 2004" WATCHCATD.CONF "System Administration" .SH NAME watchcatd.conf \- configuration file for .BR watchcatd (8) .SH DESCRIPTION This file holds all configuartion information for the .BR watchcat (8) daemon. Each option must be written on a line by itself. Comments start with a '#' and go up to the end of the line. Blank spaces and empty lines are ignored. .SH OPTIONS The following options are available: .SS Global options This section affects .BR watchcatd (8) as a whole. .TP .BR realtime " = <" true "|" false ">" Turns real-time mode on or off. On real-time mode, .BR watchcatd (8) will lock itself into memory so it is never swapped out. .TP .BR priority " = <" "schedule priority" ">" Set the schedule priority for realtime mode. This option has no effect if .BR realtime " is set to" .IR false . .TP .BR user " = <" username ">" Defines the name of the unprivileged user .BR watchcatd (8) will run as. This users's home directory will be used for chroot and all groups will be applied. .SS Master section This section defines options that affect the master process of .BR watchcatd "(8) ." .TP .BR master_debug_level " = <" "debug level" ">" Sets the debug level for the master process. This can be the sum of zero or more of the values below, resulting in a number between 0 and 63. .P .RS .IR "1" " Security logs (low volume)" .RE .RS .IR "2" " Sent signal logs (moderate to high volume)" .RE .RS .IR "4" " Failure to send signal logs (low volume)" .RE .RS .IR "8" " Failure on socket read logs (low volume)" .RE .RS .IR "16" " Child death logs (low volume)" .RE .RS .IR "32" " Child finishing logs (low volume)" .RE .TP .BR master_pid_file " = <" "file name" ">" The file where the server writes its process ID in, or the directory where it will be crested. .SS Slave section This section defines options that affect the slave process of .BR watchcatd "(8) ." .TP .BR slave_debug_level " = <" "debug level" ">" Sets the debug level for the slave process. This can be the sum of zero or more of the values below, resulting in a number between 0 and 2015. .P .RS .IR "1" " Creation/termination of a cat process logs (high" volume) .RE .RS .IR "2" " Header parsing error logs (high volume)" .RE .RS .IR "4" " Communication failure with an existing cat. Basically" this means socket errors (high volume) .RE .RS .IR "8" " Communication timeout logs (low volume)" .RE .RS .IR "16" " Security logs (low volume)" .RE .RS .IR "64" " Critical failure logs (low volume)" .RE .RS .IR "128" " Warning logs (low to moderate volume)" .RE .RS .IR "256" " Connection attempt logs (low to moderate volume)" .RE .RS .IR "512" " Successful connection logs (high volume)" .RE .RS .IR "1024" " Successful fetching of Process ID logs (high volume)" .RE .P .RS .RI "Note that the value " 32 " currently has no use." .RE .TP .BR slave_device " = <" device ">" Defines the absolute path for the watchcat device. .TP .BR slave_max_connections " = <" "max. connections" ">" Defines the maximum number of client connections that the slave will handle. .TP .BR slave_max_connections_per_pid " = <" "max. per pid" ">" Defines the maximum number of connections per client that the slave will handle. Use zero for unlimited. .SH EXAMPLE There's a complete example configuration file in /etc/watchcatd.conf. It is included with this package. .SH FILES .I /etc/watchcatd.conf .RS The .BR watchcatd (8) configuration file .fi .SH "SEE ALSO" .BR watchcatd "(8)