]> sourceware.org Git - systemtap.git/commitdiff
PR6930: staprun: supports error message to syslog
authorMasami Hiramatsu <mhiramat@redhat.com>
Fri, 20 Mar 2009 15:54:15 +0000 (11:54 -0400)
committerMasami Hiramatsu <mhiramat@redhat.com>
Fri, 20 Mar 2009 15:54:15 +0000 (11:54 -0400)
Add an interface (eprintf) to output error messages to syslogd,
because staprun has no stderr after detaching from console.

runtime/staprun/common.c
runtime/staprun/mainloop.c
runtime/staprun/staprun.h

index fd16b4b812371694220730c995368f8cb084592a..b8860248076d877c60095cc5d6dbad557256f2b0 100644 (file)
@@ -344,3 +344,24 @@ int send_request(int type, void *data, int len)
         if (rc < 0) return rc;
         return (rc != len+4);
 }
+
+#include <stdarg.h>
+
+static int use_syslog = 0;
+
+void eprintf(const char *fmt, ...)
+{
+       va_list va;
+       va_start(va, fmt);
+       if (use_syslog)
+               vsyslog(LOG_ERR, fmt, va);
+       else
+               vfprintf(stderr, fmt, va);
+       va_end(va);
+}
+
+void switch_syslog(const char *name)
+{
+       openlog(name, LOG_PID, LOG_DAEMON);
+       use_syslog = 1;
+}
index db6ef6b742300d4988fef4b74a32e1dc60dd56fb..e91e6302d8f618c9d9ca9774efb03285763d511e 100644 (file)
@@ -468,7 +468,7 @@ int stp_main_loop(void)
       }
 #endif
     case STP_OOB_DATA:
-      fputs((char *)data, stderr);
+      eprintf("%s", (char *)data);
       break;
     case STP_EXIT:
       {
index 84cf63fc494d05b4fe15c672f09dbe3ce72681b9..4c43e3ee3c653f8a985c3389aaf27179e5bfc300 100644 (file)
 #include <sys/wait.h>
 #include <sys/statfs.h>
 #include <linux/version.h>
+#include <syslog.h>
 
 /* Include config.h to pick up dependency for --prefix usage. */
 #include "config.h"
 
-#define dbug(level, args...) {if (verbose>=level) {fprintf(stderr,"%s:%s:%d ",__name__,__FUNCTION__, __LINE__); fprintf(stderr,args);}}
+extern void eprintf(const char *fmt, ...);
+extern void switch_syslog(const char *name);
+
+#define dbug(level, args...) do {if (verbose>=level) {eprintf("%s:%s:%d ",__name__,__FUNCTION__, __LINE__); eprintf(args);}} while (0)
 
 extern char *__name__;
 
 /* print to stderr */
-#define err(args...) fprintf(stderr,args)
+#define err(args...) eprintf(args)
 
 /* better perror() */
 #define perr(args...) do {                                     \
                int _errno = errno;                             \
-               fputs("ERROR: ", stderr);                       \
-               fprintf(stderr, args);                          \
-               fprintf(stderr, ": %s\n", strerror(_errno));    \
+               eprintf("ERROR: ");                             \
+               eprintf(args);                                  \
+               eprintf(": %s\n", strerror(_errno));            \
        } while (0)
 
 /* Error messages. Use these for serious errors, not informational messages to stderr. */
-#define _err(args...) do {fprintf(stderr,"%s:%s:%d: ERROR: ",__name__, __FUNCTION__, __LINE__); fprintf(stderr,args);} while(0)
+#define _err(args...) do {eprintf("%s:%s:%d: ERROR: ",__name__, __FUNCTION__, __LINE__); eprintf(args);} while(0)
 #define _perr(args...) do {                                    \
                int _errno = errno;                             \
                _err(args);                                     \
-               fprintf(stderr, ": %s\n", strerror(_errno));    \
+               eprintf(": %s\n", strerror(_errno));    \
        } while (0)
 #define overflow_error() _err("Internal buffer overflow. Please file a bug report.\n")
 
This page took 0.032373 seconds and 5 git commands to generate.