init.d/wdmd | 7 ++
src/main.c | 2
wdmd/main.c | 142 ++++++++++++++++++++++++++++++++----------------------------
3 files changed, 84 insertions(+), 67 deletions(-)
New commits:
commit ae407deb9c64ba4c1d3dfcb58d993050d64c314e
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jan 13 17:08:01 2012 +0000
wdmd: make socket group ownership configurable
diff --git a/init.d/wdmd b/init.d/wdmd
index 1adb03a..a952976 100644
--- a/init.d/wdmd
+++ b/init.d/wdmd
@@ -25,6 +25,11 @@ prog="wdmd"
lockfile="/var/run/$prog/$prog.pid"
exec="/usr/sbin/$prog"
+WDMDGROUP="sanlock"
+WDMDOPTS="-G $WDMDGROUP"
+
+[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
start() {
[ -x $exec ] || exit 5
@@ -34,7 +39,7 @@ start() {
fi
echo -n $"Starting $prog: "
- daemon $prog
+ daemon $prog $WDMDOPTS
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
diff --git a/src/main.c b/src/main.c
index f77bf3a..0e47b2e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1272,7 +1272,7 @@ static int group_to_gid(char *arg)
gr = getgrnam(arg);
if (gr == NULL) {
log_error("group '%s' not found, "
- "using uid: %i", arg, DEFAULT_SOCKET_UID);
+ "using uid: %i", arg, DEFAULT_SOCKET_GID);
return DEFAULT_SOCKET_GID;
}
diff --git a/wdmd/main.c b/wdmd/main.c
index 924bb86..4c19fc7 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -13,6 +13,7 @@
#include <getopt.h>
#include <stdint.h>
#include <stddef.h>
+#include <grp.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
@@ -46,11 +47,15 @@
#define DEFAULT_FIRE_TIMEOUT 60
#define DEFAULT_HIGH_PRIORITY 1
+#define DEFAULT_SOCKET_GID 0
+#define DEFAULT_SOCKET_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
+
static int test_interval = DEFAULT_TEST_INTERVAL;
static int fire_timeout = DEFAULT_FIRE_TIMEOUT;
static int high_priority = DEFAULT_HIGH_PRIORITY;
static int daemon_quit;
static int daemon_debug;
+static int socket_gid;
static time_t last_keepalive;
static char lockfile_path[PATH_MAX];
static int dev_fd;
@@ -327,7 +332,14 @@ static int setup_listener_socket(int *listener_socket)
return rv;
}
- rv = fchmod(s, 666);
+ rv = chmod(addr.sun_path, DEFAULT_SOCKET_MODE);
+ if (rv < 0) {
+ rv = -errno;
+ close(s);
+ return rv;
+ }
+
+ rv = chown(addr.sun_path, -1, socket_gid);
if (rv < 0) {
rv = -errno;
close(s);
@@ -872,6 +884,20 @@ static void setup_priority(void)
}
}
+static int group_to_gid(char *arg)
+{
+ struct group *gr;
+
+ gr = getgrnam(arg);
+ if (gr == NULL) {
+ log_error("group '%s' not found, "
+ "using uid: %i", arg, DEFAULT_SOCKET_GID);
+ return DEFAULT_SOCKET_GID;
+ }
+
+ return gr->gr_gid;
+}
+
static void print_usage_and_exit(int status)
{
printf("Usage:\n");
@@ -881,6 +907,7 @@ static void print_usage_and_exit(int status)
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);
+ printf("-G <groupname> group ownership for the socket\n");
exit(status);
}
@@ -922,7 +949,8 @@ int main(int argc, char *argv[])
{0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hVDH:", long_options, &option_index);
+ c = getopt_long(argc, argv, "hVDH:G:",
+ long_options, &option_index);
if (c == -1)
break;
@@ -936,6 +964,9 @@ int main(int argc, char *argv[])
case 'D':
daemon_debug = 1;
break;
+ case 'G':
+ socket_gid = group_to_gid(optarg);
+ break;
case 'H':
high_priority = atoi(optarg);
break;
commit 6240b410f38b20a3cb02c1004bd040b956637041
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jan 13 17:08:00 2012 +0000
wdmd: use getopt to parse the command line
diff --git a/wdmd/main.c b/wdmd/main.c
index b3e9d67..924bb86 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <getopt.h>
#include <stdint.h>
#include <stddef.h>
#include <fcntl.h>
@@ -39,6 +40,8 @@
#define GNUC_UNUSED __attribute__((__unused__))
#endif
+#define RELEASE_VERSION "1.8"
+
#define DEFAULT_TEST_INTERVAL 10
#define DEFAULT_FIRE_TIMEOUT 60
#define DEFAULT_HIGH_PRIORITY 1
@@ -869,15 +872,25 @@ static void setup_priority(void)
}
}
-static void print_usage(void)
+static void print_usage_and_exit(int status)
{
printf("Usage:\n");
printf("wdmd [options]\n\n");
- printf("version print version\n");
- printf("help print usage\n");
+ printf("--version, -V print version\n");
+ printf("--help, -h 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);
+ exit(status);
+}
+
+static void print_version_and_exit(void)
+{
+ printf("wdmd version %s tests_built%s%s%s\n", RELEASE_VERSION,
+ scripts_built ? scripts_built : "",
+ client_built ? client_built : "",
+ files_built ? files_built : "");
+ exit(0);
}
/* If wdmd exits abnormally, /dev/watchdog will eventually fire, and clients
@@ -888,14 +901,9 @@ static void print_usage(void)
would be for wdmd to fail starting if it found a pid file left over from
its previous run. */
-#define RELEASE_VERSION "1.8"
-
int main(int argc, char *argv[])
{
- char optchar;
- char *optionarg;
- char *p;
- int i, rv;
+ int rv;
/*
* TODO:
@@ -904,61 +912,34 @@ int main(int argc, char *argv[])
* -f <num> enable test files (1 yes, 0 no, default ...)
*/
- if ((argc > 1) &&
- !strcmp(argv[1], "version")) {
- printf("wdmd version %s tests_built%s%s%s\n", RELEASE_VERSION,
- scripts_built ? scripts_built : "",
- client_built ? client_built : "",
- files_built ? files_built : "");
- return 0;
- }
-
- if ((argc > 1) &&
- (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") ||
!strcmp(argv[1], "-h"))) {
- print_usage();
- 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;
+ while (1) {
+ int c;
+ int option_index = 0;
+
+ static struct option long_options[] = {
+ {"help", no_argument, 0, 'h' },
+ {"version", no_argument, 0, 'V' },
+ {0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "hVDH:", long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_usage_and_exit(0);
+ break;
+ case 'V':
+ print_version_and_exit();
+ break;
+ case 'D':
+ daemon_debug = 1;
+ break;
+ case 'H':
+ high_priority = atoi(optarg);
+ break;
+ }
}
if (!daemon_debug) {