changeset 7:385e4e7f7daa

logging to stdout / stderr
author Simon Horman <horms@verge.net.au>
date Tue, 14 May 2002 13:43:31 +0900
parents d3545ac68b18
children 78f6455272bf
files pbs/pbs.c pbs/pbs_option.c
diffstat 2 files changed, 58 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/pbs/pbs.c	Tue May 14 10:38:00 2002 +0900
+++ b/pbs/pbs.c	Tue May 14 13:43:31 2002 +0900
@@ -87,6 +87,7 @@
 	pbs_db_t *db = NULL;
 	time_t now;
 	time_t expire_now = 0;
+	FILE *fh = NULL;
 
 	setlocale(LC_ALL, "");
 
@@ -107,28 +108,51 @@
 		goto leave;
 	}
 
-	/* Update Logger */
-	if(opt->mode == PBS_MODE_DAEMON || opt->mode == PBS_MODE_SETENV){
-  		vanessa_logger_closelog(pbs_vl);
-		if(opt->mode == PBS_MODE_DAEMON) {
-			vanessa_socket_daemon_process();
+	/* Set file descriptor to log to, if any */
+	fh = NULL;
+	if(opt->log_facility!=NULL) {
+		if(strcmp(opt->log_facility, "-") == 0) {
+			fh = stdout;
 		}
-		else {
-			vanessa_socket_daemon_inetd_process();
-		}
-		pbs_vl=vanessa_logger_openlog_syslog_byname(
-				opt->log_facility, LOG_IDENT, 
-				opt->log_level, LOG_CONS);
-		if(pbs_vl == NULL) {
-			fprintf(stderr, 
-				"main: vanessa_logger_openlog_syslog\n"
-				"Fatal error opening logger. Exiting.\n");
-			goto leave;
+		else if(strcmp(opt->log_facility, "+") == 0) {
+			fh = stderr;
 		}
 	}
+
+	/* 
+	 * Close file descriptors and detactch process from 
+	 * shell as necessary 
+	 */
+	if(opt->mode != PBS_MODE_DAEMON || opt->no_daemon || fh != NULL){
+		vanessa_socket_daemon_inetd_process();
+	}
+	else{
+		vanessa_socket_daemon_process();
+	}
+
+	/*
+	 * Re-create logger now process is detached (unless in inetd mode)
+	 * and configuration file has been read.
+	 */
+	vanessa_logger_closelog(pbs_vl);
+	if(fh != NULL) {
+		pbs_vl = vanessa_logger_openlog_filehandle(fh, LOG_IDENT, 
+				opt->log_level, LOG_CONS);
+	}
+	else if(opt->log_facility!=NULL && *(opt->log_facility)=='/'){
+		pbs_vl = vanessa_logger_openlog_filename(opt->log_facility,
+				LOG_IDENT, opt->log_level, LOG_CONS);
+	}
 	else {
-		vanessa_socket_daemon_inetd_process();
-		vanessa_logger_change_max_priority(pbs_vl, opt->log_level);
+		pbs_vl = vanessa_logger_openlog_syslog_byname(
+				opt->log_facility, LOG_IDENT,
+				opt->log_level, LOG_CONS);
+	}
+	if(pbs_vl == NULL){
+		fprintf(stderr, 
+			"main: vanessa_logger_openlog\n"
+			"Fatal error opening logger. Exiting.\n");
+		vanessa_socket_daemon_exit_cleanly(-1);
 	}
 
 	vanessa_socket_logger_set(pbs_vl);
--- a/pbs/pbs_option.c	Tue May 14 10:38:00 2002 +0900
+++ b/pbs/pbs_option.c	Tue May 14 13:43:31 2002 +0900
@@ -85,7 +85,7 @@
 	{
 		{"db_file",       'D', POPT_ARG_STRING, NULL, 'D'},
 		{"debug",        'd',  POPT_ARG_NONE,   NULL, 'd'},
-		{"log_facility", 'F',  POPT_ARG_NONE,   NULL, 'F'},
+		{"log_facility", 'F',  POPT_ARG_STRING, NULL, 'F'},
 		{"help",         'h',  POPT_ARG_NONE,   NULL, 'h'},
 		{"log_file",      'L', POPT_ARG_STRING, NULL, 'L'},
 		{"mode",          'm', POPT_ARG_STRING, NULL, 'm'},
@@ -93,6 +93,7 @@
 		{"perfix",        'p', POPT_ARG_STRING, NULL, 'p'},
 		{"quiet",         'q', POPT_ARG_NONE,   NULL, 'q'},
 		{"regex",         'r', POPT_ARG_STRING, NULL, 'r'},
+		{"timeout",       't', POPT_ARG_STRING, NULL, 't'},
 		{"user",          'u', POPT_ARG_STRING, NULL, 'u'},
 		{"group",         'g', POPT_ARG_STRING, NULL, 'g'},
 		{NULL,             0,  0,               NULL,  0 }
@@ -183,6 +184,9 @@
 			case 'r':
 				opt->regex = optarg;
 				break;
+			case 't':
+				opt->timeout = atoi(optarg);
+				break;
 			case 'u':
 				opt->user = optarg;
 				break;
@@ -244,17 +248,18 @@
 	"                    (default \"%s\")\n"
 	"\n"
 	"  options:\n"
-	"    -h, --help: print this message\n"
 	"    -D, --db_file FILE:  Database file to access\n"
 	"                         (default \"%s\")\n"
 	"    -d, --debug:         Verbose error messages\n"
 	"    -F, --log_facility FACILITY:\n"
 	"                         Syslog facility to log to. If the faclilty\n"
 	"                         has a leading '/' then it will be treated\n"
-	"                         as a file to log to.\n"
+	"                         as a file to log to. If \"-\" or \"+\" then\n"
+	"                         log to stdout or stderr respectively\n"
 	"                         (default \"%s\")\n"
         "    -g, --group: GROUP   Group to run as\n"
 	"                         (default \"%s\")\n"
+	"    -h, --help: print this message\n"
 	"    -L, --log_file FILE: Log file to monitor\n"
 	"                         (default \"%s\")\n"
 	"    --no_daemon:         Do not detach from terminal when in\n"
@@ -263,15 +268,19 @@
 	"                         (default \"%s\")\n"
 	"                         stored in or retrieved from the database\n"
 	"    -q, --quiet:         Supress all but critical log messages\n"
-	"    -r, --regex: REGEX   Regular expression to use when parsing\n"
+	"    -r, --regex REGEX:   Regular expression to use when parsing\n"
 	"                         log file. Should match the ip address as\n"
 	"                         the first result, and optionally the\n"
 	"                         username as the second result\n"
 	"                         (default \"%s\")\n"
-        "    -u, --user: USERNAME User to run as\n"
+	"    -t, --timeout SECONDS: \n"
+	"                         The expiry time for entries in the\n"
+	"                         database\n"
+	"                         (default %d)\n"
+        "    -u, --user USERNAME: User to run as\n"
 	"                         (default \"%s\")\n"
 	"\n"
-	"Notes: Default for binary flags is off\n",
+	"Note: Default for binary flags is off\n",
 	STR_NULL_SAFE(pbs_mode_str(PBS_DEFAULT_MODE)),
 	STR_NULL_SAFE(PBS_DEFAULT_DB_FILENAME),
 	STR_NULL_SAFE(PBS_DEFAULT_GROUP),
@@ -279,6 +288,7 @@
 	STR_NULL_SAFE(PBS_DEFAULT_LOG_FILENAME),
 	STR_NULL_SAFE(PBS_DEFAULT_PREFIX),
 	STR_NULL_SAFE(PBS_DEFAULT_REGEX),
+	PBS_DEFAULT_TIMEOUT,
 	STR_NULL_SAFE(PBS_DEFAULT_USERNAME)
 	);