summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2015-06-01 14:14:36 -0500
committerDavid Teigland <teigland@redhat.com>2015-06-15 16:50:55 -0500
commitbde489d1abdefc026b4bb80cf23535c3be08393c (patch)
treeec90ffa4ee7d5fd806d94fa3f05aa0f86cd50142
parent5efd5a63059e714e82c46708081163002661fd1f (diff)
downloadlvm2-bde489d1abdefc026b4bb80cf23535c3be08393c.tar.gz
lvmlockd: fix syslog option
Use standard syslog level names as option args to specify the level at which to send to syslog.
-rw-r--r--daemons/lvmlockd/lvmlockd-core.c77
1 files changed, 63 insertions, 14 deletions
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index e29f94969..a1eecfa02 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -243,11 +243,12 @@ static int worker_wake; /* wake the thread without adding work *
*/
#define LOG_LINE_SIZE 256
#define LOG_DUMP_SIZE DUMP_BUF_SIZE
+#define LOG_SYSLOG_PRIO LOG_WARNING
static char log_dump[LOG_DUMP_SIZE];
static unsigned int log_point;
static unsigned int log_wrap;
static pthread_mutex_t log_mutex;
-static int syslog_priority = LOG_WARNING;
+static int syslog_priority = LOG_SYSLOG_PRIO;
/*
* Structure pools to avoid repeated malloc/free.
@@ -279,6 +280,50 @@ static int add_lock_action(struct action *act);
static int str_to_lm(const char *str);
static void clear_lockspace_inactive(char *name);
+static int _syslog_name_to_num(const char *name)
+{
+ if (!strcmp(name, "emerg"))
+ return LOG_EMERG;
+ if (!strcmp(name, "alert"))
+ return LOG_ALERT;
+ if (!strcmp(name, "crit"))
+ return LOG_CRIT;
+ if (!strcmp(name, "err") || !strcmp(name, "error"))
+ return LOG_ERR;
+ if (!strcmp(name, "warning") || !strcmp(name, "warn"))
+ return LOG_WARNING;
+ if (!strcmp(name, "notice"))
+ return LOG_NOTICE;
+ if (!strcmp(name, "info"))
+ return LOG_INFO;
+ if (!strcmp(name, "debug"))
+ return LOG_DEBUG;
+ return LOG_WARNING;
+}
+
+static const char *_syslog_num_to_name(int num)
+{
+ switch (num) {
+ case LOG_EMERG:
+ return "emerg";
+ case LOG_ALERT:
+ return "alert";
+ case LOG_CRIT:
+ return "crit";
+ case LOG_ERR:
+ return "err";
+ case LOG_WARNING:
+ return "warning";
+ case LOG_NOTICE:
+ return "notice";
+ case LOG_INFO:
+ return "info";
+ case LOG_DEBUG:
+ return "debug";
+ }
+ return "unknown";
+}
+
static uint64_t monotime(void)
{
struct timespec ts;
@@ -5401,8 +5446,8 @@ static void usage(char *prog, FILE *file)
fprintf(file, " Set path to the pid file. [%s]\n", LVMLOCKD_PIDFILE);
fprintf(file, " --socket-path | -s <path>\n");
fprintf(file, " Set path to the socket to listen on. [%s]\n", LVMLOCKD_SOCKET);
- fprintf(file, " --log-config | -l <str>\n");
- fprintf(file, " Set log config.\n");
+ fprintf(file, " --syslog-priority | -S err|warning|debug\n");
+ fprintf(file, " Write log messages from this level up to syslog. [%s]\n", _syslog_num_to_name(LOG_SYSLOG_PRIO));
fprintf(file, " --gl-type | -g <str>\n");
fprintf(file, " Set global lock type to be dlm|sanlock.\n");
fprintf(file, " --host-id | -i <num>\n");
@@ -5427,17 +5472,18 @@ int main(int argc, char *argv[])
ds.name = "lvmlockd";
static struct option long_options[] = {
- {"help", no_argument, 0, 'h' },
- {"version", no_argument, 0, 'V' },
- {"test", no_argument, 0, 'T' },
- {"foreground", no_argument, 0, 'f' },
- {"daemon-debug",no_argument, 0, 'D' },
- {"pid-file", required_argument, 0, 'p' },
- {"socket-path", required_argument, 0, 's' },
- {"gl-type", required_argument, 0, 'g' },
- {"host-id", required_argument, 0, 'i' },
- {"host-id-file",required_argument, 0, 'F' },
- {"adopt", required_argument, 0, 'A' },
+ {"help", no_argument, 0, 'h' },
+ {"version", no_argument, 0, 'V' },
+ {"test", no_argument, 0, 'T' },
+ {"foreground", no_argument, 0, 'f' },
+ {"daemon-debug", no_argument, 0, 'D' },
+ {"pid-file", required_argument, 0, 'p' },
+ {"socket-path", required_argument, 0, 's' },
+ {"gl-type", required_argument, 0, 'g' },
+ {"host-id", required_argument, 0, 'i' },
+ {"host-id-file", required_argument, 0, 'F' },
+ {"adopt", required_argument, 0, 'A' },
+ {"syslog-priority", required_argument, 0, 'S' },
{0, 0, 0, 0 }
};
@@ -5496,6 +5542,9 @@ int main(int argc, char *argv[])
case 'A':
adopt_opt = atoi(optarg);
break;
+ case 'S':
+ syslog_priority = _syslog_name_to_num(optarg);
+ break;
case '?':
default:
usage(argv[0], stdout);