init.d/sanlock | 8 +++ init.d/wdmd | 8 +++ src/Makefile | 30 +++++++------ src/client_msg.c | 7 --- src/lockfile.c | 10 ++++ src/main.c | 22 --------- src/sanlock.8 | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ src/sanlock_internal.h | 2 wdmd/Makefile | 34 +++++++------- wdmd/client.c | 7 --- wdmd/main.c | 61 ++++++++++++++++++++++---- wdmd/wdmd.8 | 74 ++++++++++++++++++++++++++++++++ wdmd/wdmd_internal.h | 2 13 files changed, 301 insertions(+), 76 deletions(-)
New commits: commit aebd65aa012ab07234e83a784902927852ddb741 Author: David Teigland teigland@redhat.com Date: Tue Aug 2 16:24:56 2011 -0500
sanlock/wdmd: improve mkdir of run dir
suggested by Dan Walsh
diff --git a/init.d/sanlock b/init.d/sanlock index e245e98..74df2c9 100644 --- a/init.d/sanlock +++ b/init.d/sanlock @@ -29,8 +29,13 @@ exec="/usr/sbin/$prog"
start() { [ -x $exec ] || exit 5 + + if [ ! -d /var/run/$prog ]; then + mkdir -p /var/run/$prog + [ -x /usr/sbin/restorecon ] && restorecon /var/run/$prog + fi + echo -n $"Starting $prog: " - mkdir -p /var/run/$prog daemon $prog daemon $SANLOCKOPTS retval=$? echo diff --git a/init.d/wdmd b/init.d/wdmd index 9b7c2b7..1adb03a 100644 --- a/init.d/wdmd +++ b/init.d/wdmd @@ -27,8 +27,13 @@ exec="/usr/sbin/$prog"
start() { [ -x $exec ] || exit 5 + + if [ ! -d /var/run/$prog ]; then + mkdir -p /var/run/$prog + [ -x /usr/sbin/restorecon ] && restorecon /var/run/$prog + fi + echo -n $"Starting $prog: " - mkdir -p /var/run/$prog daemon $prog retval=$? echo
commit 0195f36b4069e0e4bcf158cfd4b0190b4f73a40f Author: David Teigland teigland@redhat.com Date: Tue Aug 2 16:16:42 2011 -0500
sanlock: add man page
diff --git a/src/Makefile b/src/Makefile index 7f703ac..66d5fcd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,14 +5,12 @@ # of the GNU General Public License v.2.
CMD_TARGET = sanlock - LIB_TARGET = libsanlock - HEADER_TARGET = sanlock.h sanlock_rv.h sanlock_resource.h sanlock_admin.h sanlock_direct.h +MAN_TARGET = sanlock.8
SOMAJOR=1 SOMINOR=0 - SHLIB_TARGET = $(LIB_TARGET).so.$(SOMAJOR).$(SOMINOR)
CMD_SOURCE = \ @@ -81,16 +79,20 @@ clean:
INSTALL=$(shell which install)
-CMD_BINDIR=/usr/sbin -LIB_LIBDIR=/usr/lib64 -HEADER_DIR=/usr/include +DESTDIR= +BINDIR=/usr/sbin +LIBDIR=/usr/lib64 +HEADIR=/usr/include +MANDIR=/usr/share/man
.PHONY: install install: all - mkdir -p $(DESTDIR)/$(CMD_BINDIR) - mkdir -p $(DESTDIR)/$(LIB_LIBDIR) - mkdir -p $(DESTDIR)/$(HEADER_DIR) - $(INSTALL) -c -m 755 $(CMD_TARGET) $(DESTDIR)/$(CMD_BINDIR) - $(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIB_LIBDIR) - cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIB_LIBDIR) - $(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADER_DIR) + $(INSTALL) -d $(DESTDIR)/$(BINDIR) + $(INSTALL) -d $(DESTDIR)/$(LIBDIR) + $(INSTALL) -d $(DESTDIR)/$(HEADIR) + $(INSTALL) -d $(DESTDIR)/$(MANDIR) + $(INSTALL) -c -m 755 $(CMD_TARGET) $(DESTDIR)/$(BINDIR) + $(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIBDIR) + cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIBDIR) + $(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADIR) + $(INSTALL) $(MAN_TARGET) ${DESTDIR}/${MANDIR}/man8 diff --git a/src/sanlock.8 b/src/sanlock.8 new file mode 100644 index 0000000..b7405cf --- /dev/null +++ b/src/sanlock.8 @@ -0,0 +1,112 @@ +.TH SANLOCK 8 2011-08-02 + +.SH NAME +sanlock - shared storage lock manager + +.SH SYNOPSIS +.B sanlock +[COMMAND] [ACTION] [OPTIONS] + +.SH DESCRIPTION + +The sanlock daemon manages leases for applications running on a cluster of +hosts with shared storage. All lease management and coordination is done +through reading and writing blocks on the shared storage. Two basic types +of leases are used, each based on a different algorithm: + +"delta leases" are slow to acquire and demand regular i/o to shared +storage. sanlock only uses them internally to hold a lease on its +"host_id" (an integer host identifier from 1-2000). They simply prevent +two hosts from using the same host identifier. They also serve in a +limited way as host "liveness" indicators since they are renewed. + +"paxos leases" are generally fast to acquire and sanlock makes them +available to applications as "general purpose" resource leases. The disk +paxos algorithm uses host_id's internally, and does not work if different +hosts use the same host_id. So the delta leases provide unique host_id's +for implementing paxos leases. + +Before sanlock can be used, the user must assign each host an identifier, +or "host_id", which is an integer value between 1 and 2000. Two hosts +should not be given the same host_id. + +sanlock views a pool of storage as a "lockspace". Each distinct pool of +storage, e.g. from different sources, would typically be defined as a +separate lockspace, with a separate lockspace name. + +A part of this storage space must be reserved and initialized for sanlock +to store delta leases. Each host that wants to use the lockspace must +first acquire a delta lease on its host_id number within the lockspace. +(See the add_lockspace action/api.) These delta leases prevent two hosts +from using the same host_id, and allow hosts to detect which other hosts +are currently using the lockspace. The space required for 2000 delta +leases in the lockspace (for all possible host_id's) is 1GB for storage +with 512 byte sectors, or 8GB for storage with 4k sectors. + +Example: + +1. Create storage pools and reserve and initialize host_id leases +.br +two different LUNs on a SAN: /dev/sdb, /dev/sdc +.br +vgcreate pool1 /dev/sdb +.br +vgcreate pool2 /dev/sdc +.br +lvcreate -n hostid_leases -L 1GB pool1 +.br +lvcreate -n hostid_leases -L 1GB pool2 +.br +sanlock direct init -s lockspace1:0:/dev/pool1/hostid_leases:0 +.br +sanlock direct init -s lockspace2:0:/dev/pool2/hostid_leases:0 +.br + +2. Start the sanlock daemon on each host +.br +sanlock daemon +.br + +3. Add each lockspace to be used +.br +host1: +.br +sanlock client add_lockspace -s lockspace1:1:/dev/pool1/hostid_leases:0 +.br +sanlock client add_lockspace -s lockspace2:1:/dev/pool2/hostid_leases:0 +.br +host2: +.br +sanlock client add_lockspace -s lockspace1:2:/dev/pool1/hostid_leases:0 +.br +sanlock client add_lockspace -s lockspace2:2:/dev/pool2/hostid_leases:0 +.br + +4. Applications can now reserve/initialize space for resource leases, and +then acquire the leases as they need to access the resources. + + + +sanlock is a multi purpose binary, with three top level commands: + +.TP +.B daemon +start daemon + +.TP +.B client +send request to daemon (default command if none given) + +.TP +.B direct +access storage directly (no coordination with daemon) + +.SS client actions + +.SS direct actions + +.SH OPTIONS + +.SH SEE ALSO +.BR wdmd (8) +
commit 77817f3c61b136ac972e041b4adfe7efc28cfa04 Author: David Teigland teigland@redhat.com Date: Tue Aug 2 14:39:38 2011 -0500
sanlock: pid and sock file changes
/var/run/sanlock/sanlock.pid /var/run/sanlock/sanlock.sock (. instead of _)
and mkdir /var/run/sanlock from init script also
diff --git a/init.d/sanlock b/init.d/sanlock index d46dcef..e245e98 100644 --- a/init.d/sanlock +++ b/init.d/sanlock @@ -22,7 +22,7 @@ . /etc/rc.d/init.d/functions
prog="sanlock" -lockfile="/var/run/sanlock/$prog.pid" +lockfile="/var/run/$prog/$prog.pid" exec="/usr/sbin/$prog"
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog @@ -30,6 +30,7 @@ exec="/usr/sbin/$prog" start() { [ -x $exec ] || exit 5 echo -n $"Starting $prog: " + mkdir -p /var/run/$prog daemon $prog daemon $SANLOCKOPTS retval=$? echo diff --git a/src/lockfile.c b/src/lockfile.c index 034fc45..860c4de 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -20,6 +20,7 @@ #include <syslog.h> #include <sys/types.h> #include <sys/time.h> +#include <sys/stat.h>
#include "sanlock_internal.h" #include "log.h" @@ -30,8 +31,17 @@ int lockfile(const char *dir, const char *name) char path[PATH_MAX]; char buf[16]; struct flock lock; + mode_t old_umask; int fd, rv;
+ old_umask = umask(0022); + rv = mkdir(SANLK_RUN_DIR, 0777); + if (rv < 0 && errno != EEXIST) { + umask(old_umask); + return rv; + } + umask(old_umask); + snprintf(path, PATH_MAX, "%s/%s", dir, name);
fd = open(path, O_CREAT|O_WRONLY|O_CLOEXEC, 0666); diff --git a/src/main.c b/src/main.c index 0754cba..309d242 100644 --- a/src/main.c +++ b/src/main.c @@ -2063,22 +2063,6 @@ static void sigterm_handler(int sig GNUC_UNUSED) external_shutdown = 1; }
-static int make_dirs(void) -{ - mode_t old_umask; - int rv; - - old_umask = umask(0022); - rv = mkdir(SANLK_RUN_DIR, 0777); - if (rv < 0 && errno != EEXIST) - goto out; - - rv = 0; - out: - umask(old_umask); - return rv; -} - static void setup_priority(void) { struct sched_param sched_param; @@ -2139,10 +2123,6 @@ static int do_daemon(void) if (rv < 0) return rv;
- rv = make_dirs(); - if (rv < 0) - return rv; - fd = lockfile(SANLK_RUN_DIR, SANLK_LOCKFILE_NAME); if (fd < 0) return fd; diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h index cb7cf60..b25a8eb 100644 --- a/src/sanlock_internal.h +++ b/src/sanlock_internal.h @@ -47,7 +47,7 @@
#define SANLK_RUN_DIR "/var/run/sanlock" #define SANLK_LOG_DIR "/var/log" -#define SANLK_SOCKET_NAME "sanlock_sock" +#define SANLK_SOCKET_NAME "sanlock.sock" #define SANLK_LOGFILE_NAME "sanlock.log" #define SANLK_LOCKFILE_NAME "sanlock.pid"
commit a784a2a1cc19290454c6ee27dfe5a9cac1545c19 Author: David Teigland teigland@redhat.com Date: Tue Aug 2 14:28:43 2011 -0500
sanlock: add explicit -luuid
diff --git a/src/Makefile b/src/Makefile index 9491ce1..7f703ac 100644 --- a/src/Makefile +++ b/src/Makefile @@ -61,7 +61,7 @@ CFLAGS += -D_GNU_SOURCE -g \ -fasynchronous-unwind-tables \ -fdiagnostics-show-option
-CMD_LDFLAGS = -lpthread -lrt -laio -lblkid -lsanlock -L../wdmd -lwdmd +CMD_LDFLAGS = -lpthread -luuid -lrt -laio -lblkid -lsanlock -L../wdmd -lwdmd LIB_LDFLAGS = -lpthread -lrt -laio -lblkid -L../wdmd -lwdmd
commit d5c963a4e71714fa17ad7e216df50aff92258dfe Author: David Teigland teigland@redhat.com Date: Tue Aug 2 14:21:44 2011 -0500
sanlock: tidy sun_addr snprintf
diff --git a/src/client_msg.c b/src/client_msg.c index 11d5ab5..28c0374 100644 --- a/src/client_msg.c +++ b/src/client_msg.c @@ -33,13 +33,10 @@
static int get_socket_address(struct sockaddr_un *addr) { - char path[PATH_MAX]; - - snprintf(path, PATH_MAX, "%s/%s", SANLK_RUN_DIR, SANLK_SOCKET_NAME); - memset(addr, 0, sizeof(struct sockaddr_un)); addr->sun_family = AF_LOCAL; - strncpy(addr->sun_path, path, sizeof(addr->sun_path) - 1); + snprintf(addr->sun_path, sizeof(addr->sun_path) - 1, "%s/%s", + SANLK_RUN_DIR, SANLK_SOCKET_NAME); return 0; }
commit 3b42a648ac1a1e1e041bb33995c893a7210c9d19 Author: David Teigland teigland@redhat.com Date: Tue Aug 2 14:19:40 2011 -0500
sanlock: use accept4 with SOCK_NONBLOCK
to avoid theoretical cases where accept could block
diff --git a/src/main.c b/src/main.c index 667149b..0754cba 100644 --- a/src/main.c +++ b/src/main.c @@ -2033,7 +2033,7 @@ static void process_listener(int ci GNUC_UNUSED) int fd; int on = 1;
- fd = accept(client[ci].fd, NULL, NULL); + fd = accept4(client[ci].fd, NULL, NULL, SOCK_NONBLOCK); if (fd < 0) return;
commit f37fa70ff24c5aa87012ce0f4d4a54bd086c58e6 Author: David Teigland teigland@redhat.com Date: Tue Aug 2 14:15:53 2011 -0500
wdmd: disable test scripts
until we're ready to really test and use it
diff --git a/wdmd/Makefile b/wdmd/Makefile index a35bcfb..bc30c32 100644 --- a/wdmd/Makefile +++ b/wdmd/Makefile @@ -39,8 +39,7 @@ CFLAGS += -D_GNU_SOURCE -g \ -Wp,-D_FORTIFY_SOURCE=2 \ -fexceptions \ -fasynchronous-unwind-tables \ - -fdiagnostics-show-option \ - -DTEST_SCRIPTS + -fdiagnostics-show-option
CMD_LDFLAGS = -lwdmd TEST_LDFLAGS = -lwdmd
commit f6a95179d9f73e11070bd8667226944c2b6f567b Author: David Teigland teigland@redhat.com Date: Tue Aug 2 14:02:34 2011 -0500
wdmd: add man page
diff --git a/wdmd/Makefile b/wdmd/Makefile index 65d767f..a35bcfb 100644 --- a/wdmd/Makefile +++ b/wdmd/Makefile @@ -5,17 +5,15 @@ # of the GNU General Public License v.2.
CMD_TARGET = wdmd - LIB_TARGET = libwdmd - HEADER_TARGET = wdmd.h +MAN_TARGET = wdmd.8 +TEST_TARGET = wdmd_client
SOMAJOR=1 SOMINOR=0 - SHLIB_TARGET = $(LIB_TARGET).so.$(SOMAJOR).$(SOMINOR)
-TEST_TARGET = wdmd_client
CMD_SOURCE = main.c
@@ -67,17 +65,20 @@ clean:
INSTALL=$(shell which install)
-CMD_BINDIR=/usr/sbin -LIB_LIBDIR=/usr/lib64 -HEADER_DIR=/usr/include +DESTDIR= +BINDIR=/usr/sbin +LIBDIR=/usr/lib64 +HEADIR=/usr/include +MANDIR=/usr/share/man/
.PHONY: install install: all - mkdir -p $(DESTDIR)/$(CMD_BINDIR) - mkdir -p $(DESTDIR)/$(LIB_LIBDIR) - mkdir -p $(DESTDIR)/$(HEADER_DIR) - $(INSTALL) -c -m 755 $(CMD_TARGET) $(DESTDIR)/$(CMD_BINDIR) - $(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIB_LIBDIR) - cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIB_LIBDIR) - cp -a $(LIB_TARGET).so.$(SOMAJOR) $(DESTDIR)/$(LIB_LIBDIR) - $(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADER_DIR) + mkdir -p $(DESTDIR)/$(BINDIR) + mkdir -p $(DESTDIR)/$(LIBDIR) + mkdir -p $(DESTDIR)/$(HEADIR) + $(INSTALL) -c -m 755 $(CMD_TARGET) $(DESTDIR)/$(BINDIR) + $(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIBDIR) + cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIBDIR) + cp -a $(LIB_TARGET).so.$(SOMAJOR) $(DESTDIR)/$(LIBDIR) + $(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADIR) + install $(MAN_TARGET) ${DESTDIR}/${MANDIR}/man8 diff --git a/wdmd/wdmd.8 b/wdmd/wdmd.8 new file mode 100644 index 0000000..2df7297 --- /dev/null +++ b/wdmd/wdmd.8 @@ -0,0 +1,74 @@ +.TH WDMD 8 2011-08-01 + +.SH NAME +wdmd - watchdog multiplexing daemon + +.SH SYNOPSIS +.B wdmd +[OPTIONS] + +.SH DESCRIPTION + +This daemon opens /dev/watchdog and allows multiple independent sources to +detmermine whether each KEEPALIVE is done. Every test interval (10 +seconds), the daemon tests each source. If any test fails, the KEEPALIVE +is not done. In a standard configuration, the watchdog timer will reset +the system if no KEEPALIVE is done for 60 seconds ("fire timeout"). This +means that if single test fails 5-6 times in row, the watchdog will fire +and reset the system. With multiple test sources, fewer separate failures +back to back can also cause a reset, e.g. + +T seconds, P pass, F fail +.br +T00: test1 P, test2 P, test3 P: KEEPALIVE done +.br +T10: test1 F, test2 F, test3 P: KEEPALIVE skipped +.br +T20: test1 F, test2 P, test3 P: KEEPALIVE skipped +.br +T30: test1 P, test2 F, test3 P: KEEPALIVE skipped +.br +T40: test1 P, test2 P, test3 F: KEEPALIVE skipped +.br +T50: test1 F, test2 F, test3 P: KEEPALIVE skipped +.br +T60: test1 P, test2 F, test3 P: KEEPALIVE skipped +.br +T60: watchdog fires, system resets + +(Depending on timings, the system may be reset sometime shortly before +T60, and the tests at T60 would not be run.) + +A crucial aspect to the design and function of wdmd is that if any single +source does not pass tests for the fire timeout, the watchdog is +guaranteed to fire, regardless of whether other sources on the system have +passed or failed. A spurious reset due to the combined effects of +multiple failing tests as shown above, is an accepted side effect. + +wdmd will exit if a watchdog driver is not loaded. + +wdmd cannot be used on the system with any other program that needs to +open /dev/watchdog, e.g. watchdog(8). + +.SS Test Source: clients + +Using libwdmd, programs connect to wdmd via a unix socket, and send +regular messages to wdmd to update an expiry time for their connection. +Every test interval, wdmd will check if the expiry time for a connection +has been reached. If so, the test for that client fails. + +(Other test sources such as scripts executed each test interval may be +added in the future.) + +.SH OPTIONS +.TP +.B -D +Enable debugging to stderr and don't fork. + +.TP +.BI -H " num" +Enable (1) or disable (0) high priority features such as realtime +scheduling priority and mlockall. +.br +Default 1. +
commit f27d35af2e2e065c214b19d1aca3244ea203be00 Author: David Teigland teigland@redhat.com Date: Tue Aug 2 13:01:45 2011 -0500
wdmd: pid and sock file changes
/var/run/wdmd/wdmd.pid /var/run/wdmd/wdmd.sock (. instead of _)
and mkdir /var/run/wdmd from init script also
diff --git a/init.d/wdmd b/init.d/wdmd index c6902ac..9b7c2b7 100644 --- a/init.d/wdmd +++ b/init.d/wdmd @@ -22,12 +22,13 @@ . /etc/rc.d/init.d/functions
prog="wdmd" -lockfile="/var/run/wdmd/$prog.pid" +lockfile="/var/run/$prog/$prog.pid" exec="/usr/sbin/$prog"
start() { [ -x $exec ] || exit 5 echo -n $"Starting $prog: " + mkdir -p /var/run/$prog daemon $prog retval=$? echo diff --git a/wdmd/main.c b/wdmd/main.c index 412be83..25c6781 100644 --- a/wdmd/main.c +++ b/wdmd/main.c @@ -48,10 +48,6 @@ static time_t last_keepalive; static char lockfile_path[PATH_MAX]; static int dev_fd;
-#define WDMD_RUN_DIR "/var/run/wdmd" -#define FILES_DIR "/var/run/wdmd/test_files" -#define SCRIPTS_DIR "/etc/wdmd/test_scripts" - struct script_status { int pid; char path[PATH_MAX]; @@ -379,6 +375,7 @@ static int active_clients(void)
#ifdef TEST_FILES +#define FILES_DIR "/var/run/wdmd/test_files" const char *files_built = " files"; static DIR *files_dir;
@@ -464,6 +461,7 @@ static int test_files(void) { return 0; }
#ifdef TEST_SCRIPTS +#define SCRIPTS_DIR "/etc/wdmd/test_scripts" static DIR *scripts_dir; const char *scripts_built = " scripts";
@@ -781,8 +779,10 @@ static int lockfile(void)
old_umask = umask(0022); rv = mkdir(WDMD_RUN_DIR, 0777); - if (rv < 0 && errno != EEXIST) + if (rv < 0 && errno != EEXIST) { + umask(old_umask); return rv; + } umask(old_umask);
sprintf(lockfile_path, "%s/wdmd.pid", WDMD_RUN_DIR); diff --git a/wdmd/wdmd_internal.h b/wdmd/wdmd_internal.h index 4ace3cf..584b833 100644 --- a/wdmd/wdmd_internal.h +++ b/wdmd/wdmd_internal.h @@ -14,7 +14,7 @@ #endif
#define WDMD_RUN_DIR "/var/run/wdmd" -#define WDMD_SOCKET_NAME "wdmd_sock" +#define WDMD_SOCKET_NAME "wdmd.sock"
enum { CMD_REGISTER = 1,
commit 516c0384627466c1454affdfe997e53fad7faeaf Author: David Teigland teigland@redhat.com Date: Tue Aug 2 12:40:43 2011 -0500
wdmd: tidy sun_addr snprintf
diff --git a/wdmd/client.c b/wdmd/client.c index b46da96..6a459ae 100644 --- a/wdmd/client.c +++ b/wdmd/client.c @@ -24,13 +24,10 @@
int get_socket_address(struct sockaddr_un *addr) { - char path[PATH_MAX]; - - snprintf(path, PATH_MAX, "%s/%s", WDMD_RUN_DIR, WDMD_SOCKET_NAME); - memset(addr, 0, sizeof(struct sockaddr_un)); addr->sun_family = AF_LOCAL; - strncpy(addr->sun_path, path, sizeof(addr->sun_path) - 1); + snprintf(addr->sun_path, sizeof(addr->sun_path) - 1, "%s/%s", + WDMD_RUN_DIR, WDMD_SOCKET_NAME); return 0; }
commit 273387bded88dd2c78d7777cf1d023c3150d7e4e Author: David Teigland teigland@redhat.com Date: Tue Aug 2 12:32:45 2011 -0500
wdmd: use accept4 with SOCK_NONBLOCK
to avoid theoretical cases where accept could block
diff --git a/wdmd/main.c b/wdmd/main.c index 82c170d..412be83 100644 --- a/wdmd/main.c +++ b/wdmd/main.c @@ -275,9 +275,9 @@ static void process_listener(int ci) int fd; int on = 1;
- fd = accept(client[ci].fd, NULL, NULL); + fd = accept4(client[ci].fd, NULL, NULL, SOCK_NONBLOCK); if (fd < 0) - return; + return;
setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
commit 2f05b4fbedfa04e0cdaed004eec74375dd178548 Author: David Teigland teigland@redhat.com Date: Mon Aug 1 12:56:31 2011 -0500
wdmd: add option for high priority
-H 0 to disable high priority features
diff --git a/wdmd/main.c b/wdmd/main.c index e024c82..82c170d 100644 --- a/wdmd/main.c +++ b/wdmd/main.c @@ -863,6 +863,8 @@ static void print_usage(void) printf("version print version\n"); printf("help print usage\n"); printf("-D debug: no fork and print all logging to stderr\n"); + printf("-H <num> use high priority features (1 yes, 0 no, default %d)\n", + DEFAULT_HIGH_PRIORITY); }
/* If wdmd exits abnormally, /dev/watchdog will eventually fire, and clients @@ -877,11 +879,13 @@ static void print_usage(void)
int main(int argc, char *argv[]) { - int rv; + char optchar; + char *optionarg; + char *p; + int i, rv;
/* - * TODO: real option parsing, including - * -h <num> use high priority features (1 yes, 0 no, default 1) + * TODO: * -c <num> enable test clients (1 yes, 0 no, default ...) * -s <num> enable test scripts (1 yes, 0 no, default ...) * -f <num> enable test files (1 yes, 0 no, default ...) @@ -902,6 +906,43 @@ int main(int argc, char *argv[]) return 0; }
+ for (i = 1; i < argc; ) { + p = argv[i]; + + if ((p[0] != '-') || (strlen(p) != 2)) { + fprintf(stderr, "unknown option %s\n", p); + fprintf(stderr, "space required before option value\n"); + exit(EXIT_FAILURE); + } + + optchar = p[1]; + i++; + + /* the only option that does not have optionarg */ + if (optchar == 'D') { + daemon_debug = 1; + continue; + } + + if (i >= argc) { + fprintf(stderr, "option '%c' requires arg\n", optchar); + exit(EXIT_FAILURE); + } + + optionarg = argv[i]; + + switch (optchar) { + case 'H': + high_priority = atoi(optionarg); + break; + default: + fprintf(stderr, "unknown option: %c\n", optchar); + exit(EXIT_FAILURE); + } + + i++; + } + if ((argc > 1) && !strcmp(argv[1], "-D")) { daemon_debug = 1;
sanlock-devel@lists.fedorahosted.org