src/cmd.c | 16 ++++++
src/main.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++
src/sanlock.conf | 40 +++++++++++++++
src/sanlock_internal.h | 1
4 files changed, 184 insertions(+)
New commits:
commit 055825d7fe7feb51aa3e9fcf6ccd0c57a9d800ce
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Jun 12 15:42:35 2015 -0500
sanlock: add a config file
sanlock will now read settings from /etc/sanlock/sanlock.conf
when started. These settings are overriden by the same thing
set on the command line.
Also, display more daemon settings from 'sanlock status -D'
diff --git a/src/cmd.c b/src/cmd.c
index d61937c..93387c0 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -2055,6 +2055,14 @@ static int print_state_daemon(char *str)
snprintf(str, SANLK_STATE_MAXSTR-1,
"our_host_name=%s "
+ "use_watchdog=%d "
+ "high_priority=%d "
+ "mlock_level=%d "
+ "quiet_fail=%d "
+ "debug_renew=%d "
+ "gid=%d "
+ "uid=%d "
+ "sh_retries=%d "
"use_aio=%d "
"kill_grace_seconds=%d "
"helper_pid=%d "
@@ -2067,6 +2075,14 @@ static int print_state_daemon(char *str)
"version_hex=%08x "
"smproto_hex=%08x",
our_host_name_global,
+ com.use_watchdog,
+ com.high_priority,
+ com.mlock_level,
+ com.quiet_fail,
+ com.debug_renew,
+ com.gid,
+ com.uid,
+ com.sh_retries,
main_task.use_aio,
kill_grace_seconds,
helper_pid,
diff --git a/src/main.c b/src/main.c
index 4e203eb..8a2fc7a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2229,6 +2229,126 @@ static int read_command_line(int argc, char *argv[])
return 0;
}
+#define MAX_CONF_LINE 128
+
+static void get_val_int(char *line, int *val_out)
+{
+ char key[MAX_CONF_LINE];
+ char val[MAX_CONF_LINE];
+ int rv;
+
+ rv = sscanf(line, "%[^=]=%s", key, val);
+ if (rv != 2)
+ return;
+
+ *val_out = atoi(val);
+}
+
+static void get_val_str(char *line, char *val_out)
+{
+ char key[MAX_CONF_LINE];
+ char val[MAX_CONF_LINE];
+ int rv;
+
+ rv = sscanf(line, "%[^=]=%s", key, val);
+ if (rv != 2)
+ return;
+
+ strcpy(val_out, val);
+}
+
+static void read_config_file(void)
+{
+ FILE *file;
+ struct stat buf;
+ char line[MAX_CONF_LINE];
+ char str[MAX_CONF_LINE];
+ int i, val;
+
+ if (stat(SANLK_CONF_PATH, &buf) < 0) {
+ if (errno != ENOENT)
+ log_error("%s stat failed: %d", SANLK_CONF_PATH, errno);
+ return;
+ }
+
+ file = fopen(SANLK_CONF_PATH, "r");
+ if (!file)
+ return;
+
+ while (fgets(line, MAX_CONF_LINE, file)) {
+ if (line[0] == '#')
+ continue;
+ if (line[0] == '\n')
+ continue;
+
+ memset(str, 0, sizeof(str));
+
+ for (i = 0; i < MAX_CONF_LINE; i++) {
+ if (line[i] == ' ')
+ break;
+ if (line[i] == '=')
+ break;
+ if (line[i] == '\0')
+ break;
+ if (line[i] == '\n')
+ break;
+ if (line[i] == '\t')
+ break;
+ str[i] = line[i];
+ }
+
+ if (!strcmp(str, "quiet_fail")) {
+ get_val_int(line, &val);
+ com.quiet_fail = val;
+
+ } else if (!strcmp(str, "debug_renew")) {
+ get_val_int(line, &val);
+ com.debug_renew = val;
+
+ } else if (!strcmp(str, "logfile_priority")) {
+ get_val_int(line, &val);
+ log_logfile_priority = val;
+
+ } else if (!strcmp(str, "syslog_priority")) {
+ get_val_int(line, &val);
+ log_syslog_priority = val;
+
+ } else if (!strcmp(str, "use_watchdog")) {
+ get_val_int(line, &val);
+ com.use_watchdog = val;
+
+ } else if (!strcmp(str, "high_priority")) {
+ get_val_int(line, &val);
+ com.high_priority = val;
+
+ } else if (!strcmp(str, "mlock_level")) {
+ get_val_int(line, &val);
+ com.mlock_level = val;
+
+ } else if (!strcmp(str, "sh_retries")) {
+ get_val_int(line, &val);
+ com.sh_retries = val;
+
+ } else if (!strcmp(str, "uname")) {
+ memset(str, 0, sizeof(str));
+ get_val_str(line, str);
+ com.uid = user_to_uid(str);
+
+ } else if (!strcmp(str, "gname")) {
+ memset(str, 0, sizeof(str));
+ get_val_str(line, str);
+ com.gid = group_to_gid(str);
+
+ } else if (!strcmp(str, "our_host_name")) {
+ memset(str, 0, sizeof(str));
+ get_val_str(line, str);
+ strncpy(com.our_host_name, str, NAME_ID_SIZE);
+ }
+ }
+
+ fclose(file);
+}
+
/* only used by do_client */
static char *lsf_to_str(uint32_t flags)
{
@@ -3083,6 +3203,13 @@ int main(int argc, char *argv[])
memset(&main_task, 0, sizeof(main_task));
+ /*
+ * read_config_file() overrides com default settings,
+ * read_command_line() overrides com default settings and
+ * config file settings.
+ */
+ read_config_file();
+
rv = read_command_line(argc, argv);
if (rv < 0)
goto out;
diff --git a/src/sanlock.conf b/src/sanlock.conf
new file mode 100644
index 0000000..06b8647
--- /dev/null
+++ b/src/sanlock.conf
@@ -0,0 +1,40 @@
+# sanlock config file
+#
+# Values set here can be overriden on the command line.
+# See 'man sanlock' and 'sanlock -h' for more information.
+#
+# Example settings:
+#
+# quiet_fail = 0
+# command line: -Q 0|1
+#
+# debug_renew = 0
+# command line: -R 0|1
+#
+# logfile_priority = 3
+# command line: -L 3
+#
+# syslog_priority = 3
+# command line: -S 3
+#
+# use_watchdog = 1
+# command line: -w 1
+#
+# high_priority = 1
+# command line: -h 1
+#
+# mlock_level = 1
+# command line: -l 1
+#
+# sh_retries = 8
+# command line: n/a
+#
+# uname = sanlock
+# command line: -U <name>
+#
+# gname = sanlock
+# command line: -G <name>
+#
+# our_host_name = <str>
+# command line: -e <str>
+
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 475af18..9df82f3 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -46,6 +46,7 @@
#define SANLK_LOG_DIR "/var/log"
#define SANLK_LOGFILE_NAME "sanlock.log"
#define SANLK_LOCKFILE_NAME "sanlock.pid"
+#define SANLK_CONF_PATH "/etc/sanlock/sanlock.conf"
#define DAEMON_NAME "sanlock"