hal/hald hald.c, 1.40, 1.41 hald.h, 1.9, 1.10 logger.c, 1.7,
1.8 logger.h, 1.9, 1.10
Danny Kukawka
dkukawka at freedesktop.org
Wed Oct 26 11:35:42 PDT 2005
Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv10121/hald
Modified Files:
hald.c hald.h logger.c logger.h
Log Message:
2005-10-26 Danny Kukawka <danny.kukawka at web.de>
* hald/hald.c: (usage), (main); hald/hald.h : Added new command
line option '--use-syslog' to write debug messages to syslog
instead of stderr. With this option HAL writes debug messages also
if run as daemon.
Removed useless call of logger_init (). Moved first debug message
to reduce unneeded double check of opt_become_daemon.
* hald/logger.c: (logger_enable_syslog), (logger_disable_syslog),
(logger_emit); hald/logger.h: Added write to syslog instead of
stderr. Remove empty and useless function logger_init ().
Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- hald.c 27 Sep 2005 09:42:12 -0000 1.40
+++ hald.c 26 Oct 2005 18:35:40 -0000 1.41
@@ -211,7 +211,10 @@
"\n"
" --daemon=yes|no Become a daemon\n"
" --verbose=yes|no Print out debug (overrides HALD_VERBOSE)\n"
- " --retain-privileges Run as root instead of normal user (calling of\n"
+ " --use-syslog Print out debug messages to syslog instead of stderr.\n"
+ " Use this option to get debug messages if HAL runs as\n"
+ " daemon.\n"
+ " --retain-privileges Run as root instead of normal user (calling of\n"
" external scripts to modify fstab etc. will work)\n"
" --help Show this information and exit\n"
"\n"
@@ -228,6 +231,7 @@
/** If #TRUE, we will spew out debug */
dbus_bool_t hald_is_verbose = FALSE;
+dbus_bool_t hald_use_syslog = FALSE;
static int sigterm_unix_signal_pipe_fds[2];
static GIOChannel *sigterm_iochn;
@@ -408,7 +412,6 @@
g_type_init ();
- logger_init ();
if (getenv ("HALD_VERBOSE"))
hald_is_verbose = TRUE;
else
@@ -433,6 +436,7 @@
static struct option long_options[] = {
{"daemon", 1, NULL, 0},
{"verbose", 1, NULL, 0},
+ {"use-syslog", 0, NULL, 0},
{"help", 0, NULL, 0},
{"retain-privileges", 0, NULL, 0},
{NULL, 0, NULL, 0}
@@ -470,7 +474,10 @@
}
} else if (strcmp (opt, "retain-privileges") == 0) {
retain_privs = TRUE;
+ } else if (strcmp (opt, "use-syslog") == 0) {
+ hald_use_syslog = TRUE;
}
+
break;
default:
@@ -485,6 +492,11 @@
else
logger_disable ();
+ if (hald_use_syslog)
+ logger_enable_syslog ();
+ else
+ logger_disable_syslog ();
+
/* will fork into two; only the child will return here if we are successful */
/*master_slave_setup ();
sleep (100000000);*/
@@ -492,10 +504,6 @@
loop = g_main_loop_new (NULL, FALSE);
HAL_INFO ((PACKAGE_STRING));
- if (opt_become_daemon)
- HAL_INFO (("Will daemonize"));
- else
- HAL_INFO (("Will not daemonize"));
if (opt_become_daemon) {
int child_pid;
@@ -503,6 +511,7 @@
int pf;
char pid[9];
+ HAL_INFO (("Will daemonize"));
HAL_INFO (("Becoming a daemon"));
if (pipe (startup_daemonize_pipe) != 0) {
@@ -557,6 +566,8 @@
close (pf);
atexit (delete_pid);
}
+ } else {
+ HAL_INFO (("Will not daemonize"));
}
Index: hald.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- hald.h 29 Jul 2005 20:32:57 -0000 1.9
+++ hald.h 26 Oct 2005 18:35:40 -0000 1.10
@@ -45,6 +45,7 @@
void property_atomic_update_end ();
extern dbus_bool_t hald_is_verbose;
+extern dbus_bool_t hald_use_syslog;
extern dbus_bool_t hald_is_initialising;
extern dbus_bool_t hald_is_shutting_down;
Index: logger.c
===================================================================
RCS file: /cvs/hal/hal/hald/logger.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- logger.c 29 Jul 2005 20:32:57 -0000 1.7
+++ logger.c 26 Oct 2005 18:35:40 -0000 1.8
@@ -33,6 +33,7 @@
#include <stdarg.h>
#include <time.h>
#include <sys/time.h>
+#include <sys/syslog.h>
#include "logger.h"
@@ -50,16 +51,9 @@
static const char *function;
static int is_enabled = 1;
+static int syslog_enabled = 0;
-/** Initialize logging system
- *
- */
-void
-logger_init (void)
-{
-}
-
/** Disable all logging
*
*/
@@ -78,6 +72,24 @@
is_enabled = 1;
}
+/** enable usage of syslog for logging
+ *
+ */
+void
+logger_enable_syslog (void)
+{
+ syslog_enabled = 1;
+}
+
+/** disable usage of syslog for logging
+ *
+ */
+void
+logger_disable_syslog (void)
+{
+ syslog_enabled = 0;
+}
+
/** Setup logging entry
*
* @param priority Logging priority, one of HAL_LOGPRI_*
@@ -140,8 +152,24 @@
strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
/** @todo Make programmatic interface to logging */
- if (priority != HAL_LOGPRI_TRACE)
+ if (priority != HAL_LOGPRI_TRACE && !syslog_enabled ) {
fprintf (stderr, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
+ } else if (priority != HAL_LOGPRI_TRACE && syslog_enabled ) {
+ /* use syslog for debug/log messages if HAL started as daemon */
+ switch (priority) {
+ case HAL_LOGPRI_DEBUG:
+ case HAL_LOGPRI_INFO:
+ syslog(LOG_INFO, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf );
+ break;
+ case HAL_LOGPRI_WARNING:
+ syslog(LOG_WARNING, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf );
+ break;
+ default: /* explicit fallthrough */
+ case HAL_LOGPRI_ERROR:
+ syslog(LOG_ERR, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf );
+ break;
+ }
+ }
va_end (args);
}
Index: logger.h
===================================================================
RCS file: /cvs/hal/hal/hald/logger.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- logger.h 29 Jul 2005 20:32:57 -0000 1.9
+++ logger.h 26 Oct 2005 18:35:40 -0000 1.10
@@ -46,8 +46,6 @@
HAL_LOGPRI_ERROR = (1 << 4) /**< error */
};
-void logger_init (void);
-
void logger_setup (int priority, const char *file, int line, const char *function);
void logger_emit (const char *format, ...);
@@ -55,6 +53,10 @@
void logger_enable (void);
void logger_disable (void);
+void logger_enable_syslog (void);
+void logger_disable_syslog (void);
+
+
/** Trace logging macro */
#define HAL_TRACE(expr) do {logger_setup(HAL_LOGPRI_TRACE, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
More information about the hal-commit
mailing list