netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [ulogd patch 0/3] improve ulogd command line
@ 2013-01-19  9:50 Eric Leblond
  2013-01-19  9:50 ` [PATCH 1/3] ulogd: add -v option to display message on stderr Eric Leblond
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Leblond @ 2013-01-19  9:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: eric


Hello,

This little patchset adds some options to ulogd. First one is '-v'
which sends log message to standard out (combined to syslog). Second
one is '-l' which allows user to set log level from command line.

BR,
--
Eric

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] ulogd: add -v option to display message on stderr.
  2013-01-19  9:50 [ulogd patch 0/3] improve ulogd command line Eric Leblond
@ 2013-01-19  9:50 ` Eric Leblond
  2013-01-19  9:50 ` [PATCH 2/3] conf: add flag to allow option setup tuning Eric Leblond
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Leblond @ 2013-01-19  9:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: eric

If can be painful to have to check the logfile, so this patch adds
a '-v' option which display logs message to stderr.

Signed-off-by: Eric Leblond <eric@regit.org>
---
 src/ulogd.c |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/ulogd.c b/src/ulogd.c
index c821bbf..344d330 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -83,6 +83,8 @@ static FILE syslog_dummy;
 
 static int info_mode = 0;
 
+static int verbose = 0;
+
 /* linked list for all registered plugins */
 static LLIST_HEAD(ulogd_plugins);
 /* linked list for all plugins handle */
@@ -430,31 +432,42 @@ void __ulogd_log(int level, char *file, int line, const char *format, ...)
 		else
 			outfd = stderr;
 
-		va_start(ap, format);
-
 		tm = time(NULL);
 		timestr = ctime(&tm);
 		timestr[strlen(timestr)-1] = '\0';
 		fprintf(outfd, "%s <%1.1d> %s:%d ", timestr, level, file, line);
+		if (verbose)
+			fprintf(stderr, "%s <%1.1d> %s:%d ", timestr, level, file, line);
+
 
+		va_start(ap, format);
 		vfprintf(outfd, format, ap);
 		va_end(ap);
-
 		/* flush glibc's buffer */
 		fflush(outfd);
+
+		if (verbose) {
+			va_start(ap, format);
+			vfprintf(stderr, format, ap);
+			va_end(ap);
+			fflush(stderr);
+		}
+
 	}
 }
 
 static void warn_and_exit(int daemonize)
 {
 	if (!daemonize) {
-		if (logfile)
-			fprintf(stderr, "Fatal error, check logfile \"%s\".\n",
+		if (logfile && !verbose) {
+			fprintf(stderr, "Fatal error, check logfile \"%s\""
+				" or use '-v' flag.\n",
 				ulogd_logfile);
-		else
+
+		} else
 			fprintf(stderr, "Fatal error.\n");
 	}
-	exit(1);
+exit(1);
 }
 
 /* clean results (set all values to 0 and free pointers) */
@@ -1098,6 +1111,7 @@ static void print_usage(void)
 	printf("\t-h --help\tThis help page\n");
 	printf("\t-V --version\tPrint version information\n");
 	printf("\t-d --daemon\tDaemonize (fork into background)\n");
+	printf("\t-v --verbose\tOutput info on standard output\n");
 	printf("\t-c --configfile\tUse alternative Configfile\n");
 	printf("\t-u --uid\tChange UID/GID\n");
 	printf("\t-i --info\tDisplay infos about plugin\n");
@@ -1110,6 +1124,7 @@ static struct option opts[] = {
 	{ "configfile", 1, NULL, 'c'},
 	{ "uid", 1, NULL, 'u' },
 	{ "info", 1, NULL, 'i' },
+	{ "verbose", 0, NULL, 'v' },
 	{NULL, 0, NULL, 0}
 };
 
@@ -1125,7 +1140,7 @@ int main(int argc, char* argv[])
 
 	ulogd_logfile = strdup(ULOGD_LOGFILE_DEFAULT);
 
-	while ((argch = getopt_long(argc, argv, "c:dh::Vu:i:", opts, NULL)) != -1) {
+	while ((argch = getopt_long(argc, argv, "c:dvh::Vu:i:", opts, NULL)) != -1) {
 		switch (argch) {
 		default:
 		case '?':
@@ -1171,9 +1186,19 @@ int main(int argc, char* argv[])
 			load_plugin(optarg);
 			exit(0);
 			break;
+		case 'v':
+			verbose = 1;
+			break;
 		}
 	}
 
+	if (daemonize && verbose) {
+		verbose = 0;
+		ulogd_log(ULOGD_ERROR,
+		          "suppressing verbose output (not compatible"
+			  " with daemon mode).\n");
+	}
+
 	if (config_register_file(ulogd_configfile)) {
 		ulogd_log(ULOGD_FATAL, "error registering configfile \"%s\"\n",
 			  ulogd_configfile);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] conf: add flag to allow option setup tuning
  2013-01-19  9:50 [ulogd patch 0/3] improve ulogd command line Eric Leblond
  2013-01-19  9:50 ` [PATCH 1/3] ulogd: add -v option to display message on stderr Eric Leblond
@ 2013-01-19  9:50 ` Eric Leblond
  2013-01-19  9:50 ` [PATCH 3/3] Add -l option to set log level from command line Eric Leblond
  2013-01-25 22:28 ` [ulogd patch 0/3] improve ulogd " Eric Leblond
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Leblond @ 2013-01-19  9:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: eric

This patch adds a flag to the config_entry structure to be able to
tune setup. First usage is to ask config parser not to update a key
if it has been already set.

Signed-off-by: Eric Leblond <eric@regit.org>
---
 include/ulogd/conffile.h |    4 ++++
 src/conffile.c           |    3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/ulogd/conffile.h b/include/ulogd/conffile.h
index 7431243..aa35809 100644
--- a/include/ulogd/conffile.h
+++ b/include/ulogd/conffile.h
@@ -41,11 +41,15 @@ enum {
 #define CONFIG_OPT_MANDATORY	0x0001
 #define CONFIG_OPT_MULTI	0x0002
 
+/* valid flag part */
+#define CONFIG_FLAG_VAL_PROTECTED	(1<<0)
+
 struct config_entry {
 	char key[CONFIG_KEY_LEN];	/* name of config directive */
 	u_int8_t type;			/* type; see above */
 	u_int8_t options;		/* options; see above  */
 	u_int8_t hit;			/* found? */
+	u_int8_t flag;			/* tune setup of option */
 	union {
 		char string[CONFIG_VAL_STRING_LEN];
 		int value;
diff --git a/src/conffile.c b/src/conffile.c
index b27187e..8dbd726 100644
--- a/src/conffile.c
+++ b/src/conffile.c
@@ -167,7 +167,8 @@ int config_parse_file(const char *section, struct config_keyset *kset)
 		for (i = 0; i < kset->num_ces; i++) {
 			struct config_entry *ce = &kset->ces[i];
 			pr_debug("parse main loop, key: %s\n", ce->key);
-			if (strcmp(ce->key, (char *) &wordbuf)) {
+			if ((strcmp(ce->key, (char *) &wordbuf)) ||
+			     ce->flag & CONFIG_FLAG_VAL_PROTECTED) {
 				continue;
 			}
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] Add -l option to set log level from command line
  2013-01-19  9:50 [ulogd patch 0/3] improve ulogd command line Eric Leblond
  2013-01-19  9:50 ` [PATCH 1/3] ulogd: add -v option to display message on stderr Eric Leblond
  2013-01-19  9:50 ` [PATCH 2/3] conf: add flag to allow option setup tuning Eric Leblond
@ 2013-01-19  9:50 ` Eric Leblond
  2013-01-25 22:28 ` [ulogd patch 0/3] improve ulogd " Eric Leblond
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Leblond @ 2013-01-19  9:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: eric

This patch adds a '-l' option which can be used to setup ulogd
loglevel. Command line option has precedence on the configuration
file one.

Signed-off-by: Eric Leblond <eric@regit.org>
---
 src/ulogd.c   |   15 +++++++++++++--
 ulogd.conf.in |    4 ++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/ulogd.c b/src/ulogd.c
index 344d330..5693572 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -1112,6 +1112,7 @@ static void print_usage(void)
 	printf("\t-V --version\tPrint version information\n");
 	printf("\t-d --daemon\tDaemonize (fork into background)\n");
 	printf("\t-v --verbose\tOutput info on standard output\n");
+	printf("\t-l --loglevel\tSet log level\n");
 	printf("\t-c --configfile\tUse alternative Configfile\n");
 	printf("\t-u --uid\tChange UID/GID\n");
 	printf("\t-i --info\tDisplay infos about plugin\n");
@@ -1125,6 +1126,7 @@ static struct option opts[] = {
 	{ "uid", 1, NULL, 'u' },
 	{ "info", 1, NULL, 'i' },
 	{ "verbose", 0, NULL, 'v' },
+	{ "loglevel", 1, NULL, 'l' },
 	{NULL, 0, NULL, 0}
 };
 
@@ -1137,10 +1139,11 @@ int main(int argc, char* argv[])
 	struct passwd *pw;
 	uid_t uid = 0;
 	gid_t gid = 0;
+	int loglevel = 0;
 
 	ulogd_logfile = strdup(ULOGD_LOGFILE_DEFAULT);
 
-	while ((argch = getopt_long(argc, argv, "c:dvh::Vu:i:", opts, NULL)) != -1) {
+	while ((argch = getopt_long(argc, argv, "c:dvl:h::Vu:i:", opts, NULL)) != -1) {
 		switch (argch) {
 		default:
 		case '?':
@@ -1189,9 +1192,17 @@ int main(int argc, char* argv[])
 		case 'v':
 			verbose = 1;
 			break;
+		case 'l':
+			loglevel = atoi(optarg);
+			break;
 		}
 	}
 
+	/* command line has precedence on config file */
+	if (loglevel)
+		loglevel_ce.u.value = loglevel;
+		loglevel_ce.flag |= CONFIG_FLAG_VAL_PROTECTED;
+
 	if (daemonize && verbose) {
 		verbose = 0;
 		ulogd_log(ULOGD_ERROR,
@@ -1204,7 +1215,7 @@ int main(int argc, char* argv[])
 			  ulogd_configfile);
 		warn_and_exit(daemonize);
 	}
-	
+
 	/* parse config file */
 	if (parse_conffile("global", &ulogd_kset)) {
 		ulogd_log(ULOGD_FATAL, "parse_conffile\n");
diff --git a/ulogd.conf.in b/ulogd.conf.in
index 783cb2b..d5db77b 100644
--- a/ulogd.conf.in
+++ b/ulogd.conf.in
@@ -11,8 +11,8 @@
 # logfile for status messages
 logfile="/var/log/ulogd.log"
 
-# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8)
-loglevel=1
+# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8) (default 5)
+# loglevel=1
 
 ######################################################################
 # PLUGIN OPTIONS
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [ulogd patch 0/3] improve ulogd command line
  2013-01-19  9:50 [ulogd patch 0/3] improve ulogd command line Eric Leblond
                   ` (2 preceding siblings ...)
  2013-01-19  9:50 ` [PATCH 3/3] Add -l option to set log level from command line Eric Leblond
@ 2013-01-25 22:28 ` Eric Leblond
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Leblond @ 2013-01-25 22:28 UTC (permalink / raw)
  To: netfilter-devel

Hello,

Patchset has been applied.

BR,
On Sat, 2013-01-19 at 10:50 +0100, Eric Leblond wrote:
> Hello,
> 
> This little patchset adds some options to ulogd. First one is '-v'
> which sends log message to standard out (combined to syslog). Second
> one is '-l' which allows user to set log level from command line.
> 
> BR,
> --
> Eric
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Eric Leblond <eric@regit.org>
Blog: https://home.regit.org/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-25 22:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-19  9:50 [ulogd patch 0/3] improve ulogd command line Eric Leblond
2013-01-19  9:50 ` [PATCH 1/3] ulogd: add -v option to display message on stderr Eric Leblond
2013-01-19  9:50 ` [PATCH 2/3] conf: add flag to allow option setup tuning Eric Leblond
2013-01-19  9:50 ` [PATCH 3/3] Add -l option to set log level from command line Eric Leblond
2013-01-25 22:28 ` [ulogd patch 0/3] improve ulogd " Eric Leblond

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).