[master 1/2] Make loader log into syslog (so remote logging works for it as well) (#524980)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 loader/loader.c |    2 --
 loader/log.c    |   54 +++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/loader/loader.c b/loader/loader.c
index b42eb71..0c05c3c 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -38,7 +38,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
-#include <syslog.h>
 #include <unistd.h>
 #include <stdint.h>
 #include <dirent.h>
@@ -1933,7 +1932,6 @@ int main(int argc, char ** argv) {
 #endif
 
     openLog();
-    openlog("loader", 0, LOG_LOCAL0);
     
     /* XXX if RHEL, enable the AUTODD feature by default,
      * but we should come with more general way how to control this */
diff --git a/loader/log.c b/loader/log.c
index 0d1fa98..01abae8 100644
--- a/loader/log.c
+++ b/loader/log.c
@@ -30,12 +30,41 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/time.h>
+#include <syslog.h>
 
 #include "log.h"
 
 static FILE * tty_logfile = NULL;
 static FILE * file_logfile = NULL;
 static int minLevel = INFO;
+static const char * syslog_facility = "loader";
+
+/* maps our loglevel to syslog loglevel */
+static int mapLogLevel(int level)
+{
+    int syslog_level;
+    switch (level) {
+    case DEBUGLVL:
+        syslog_level = LOG_DEBUG;
+        break;
+    case INFO:
+        syslog_level = LOG_INFO;
+        break;
+    case WARNING:
+        syslog_level = LOG_WARNING;
+        break;
+    case CRITICAL:
+        syslog_level = LOG_CRIT;
+        break;
+    case ERROR:
+    default:
+        /* if someone called us with an invalid level value, log it as an error
+           too. */
+        syslog_level = LOG_ERR;
+        break;
+    }
+    return syslog_level;
+}
 
 static void printLogHeader(int level, FILE *outfile) {
     struct timeval current_time;
@@ -74,34 +103,28 @@ static void printLogHeader(int level, FILE *outfile) {
 }
 
 void logMessageV(int level, const char * s, va_list ap) {
+    va_list apc;
+    va_copy(apc, ap);
+    /* Log everything into syslog */
+    vsyslog(mapLogLevel(level), s, apc);
 
     /* Only log to the screen things that are above the minimum level. */
     if (tty_logfile && level >= minLevel) {
-        va_list apc;
-
-        va_copy(apc, ap);
-
         printLogHeader(level, tty_logfile);
         vfprintf(tty_logfile, s, apc);
         fprintf(tty_logfile, "\n");
         fflush(tty_logfile);
-
-        va_end(apc);
     }
 
     /* But log everything to the file. */
     if (file_logfile) {
-        va_list apc;
-
-        va_copy(apc, ap);
-
         printLogHeader(level, file_logfile);
         vfprintf(file_logfile, s, apc);
         fprintf(file_logfile, "\n");
         fflush(file_logfile);
-
-        va_end(apc);
     }
+
+    va_end(apc);
 }
 
 void logMessage(int level, const char * s, ...) {
@@ -116,8 +139,11 @@ int tty_logfd = -1;
 int file_logfd = -1;
 
 void openLog() {
-    int flags;
+    /* init syslog logging (so loader messages can also be forwarded to a remote
+       syslog daemon */
+    openlog(syslog_facility, 0, LOG_LOCAL1);
 
+    int flags;
     tty_logfile = fopen("/dev/tty3", "w");
     file_logfile = fopen("/tmp/anaconda.log", "w");
 
@@ -140,6 +166,8 @@ void closeLog(void) {
 
     if (file_logfile)
         fclose(file_logfile);
+    /* close syslog logger */
+    closelog();
 }
 
 /* set the level.  higher means you see more verbosity */
-- 
1.6.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux