[master 1/2] logging: support logging through virtio-serial (#576439).

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

 



---
 loader/init.c     |   68 ++++++++++++++++++++++++++++++++++++++++++++++-------
 scripts/mk-images |    1 +
 2 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index 1a38df3..5e2f07d 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -114,7 +114,7 @@ char * env[] = {
 
 void shutDown(int doKill, reboot_action rebootAction);
 static int getKillPolicy(void);
-static void getSyslog(char*);
+static void getSyslog(char *, char *);
 struct termios ts;
 
 static int expected_exit = 0;
@@ -145,23 +145,60 @@ static void startSyslog(void) {
     int conf_fd;
     int ret;
     char addr[128];
-    char forwardtcp[] = "*.* @@";
+    char virtiolog[128];
+    const char *forward_tcp = "*.* @@";
+    const char *forward_format_tcp = "\n";
+    const char *forward_virtio = "*.* /dev/virtio-ports/";
+    const char *forward_format_virtio = ";virtio_ForwardFormat\n";
     
     /* update the config file with command line arguments first */
-    getSyslog(addr);
-    if (strlen(addr) > 0) {
+    getSyslog(addr, virtiolog);
+    if (strlen(addr) > 0 || strlen(virtiolog) > 0) {
         conf_fd = open("/etc/rsyslog.conf", O_WRONLY|O_APPEND);
         if (conf_fd < 0) {
             printf("error opening /etc/rsyslog.conf: %d\n", errno);
             printf("syslog forwarding will not be enabled\n");
             sleep(5);
         } else {
-            ret = write(conf_fd, forwardtcp, strlen(forwardtcp));
-            ret = write(conf_fd, addr, strlen(addr));
-            ret = write(conf_fd, "\n", 1);
+            if (strlen(addr) > 0) {
+                ret = write(conf_fd, forward_tcp, strlen(forward_tcp));
+                ret = write(conf_fd, addr, strlen(addr));
+                ret = write(conf_fd, forward_format_tcp, strlen(forward_format_tcp));
+            }
+            if (strlen(virtiolog) > 0) {
+                ret = write(conf_fd, forward_virtio, strlen(forward_virtio));
+                ret = write(conf_fd, virtiolog, strlen(virtiolog));
+                ret = write(conf_fd, forward_format_virtio, strlen(forward_format_virtio));
+            }
             close(conf_fd);
         }
     }
+    
+    if (strlen(virtiolog)) {
+        /* virtio_console doesn't work until virtio_pci is loaded */
+        int childpid;
+        int waitstatus;
+        childpid = fork();
+        printf("Loading virtio_pci module... ");
+        if (!childpid) {
+            int fd;
+            /* suppress stdout */
+            fd = open("/dev/null", O_WRONLY);
+            dup2(fd, STDOUT_FILENO);
+            close(fd);
+            /* now run modprobe */
+            ret = execl("/sbin/modprobe", "/sbin/modprobe", "virtio_pci", NULL);
+        }
+        waitpid(childpid, &waitstatus, 0);
+        if (!WIFEXITED(waitstatus) || 
+            (WIFEXITED(waitstatus) && WEXITSTATUS(waitstatus))) {
+            printf("Error loading virtio_pci module. ");
+            printf("Virtio logging will not work.\n.");
+            sleep(5);
+        } else {
+            printf("done.\n");
+        }
+    }
 
     /* rsyslog is going to take care of things, so disable console logging */
     klogctl(8, NULL, 1);
@@ -318,7 +355,7 @@ static int getKillPolicy(void) {
 }
 
 /* Looks through /proc/cmdline for remote syslog paramters. */
-static void getSyslog(char *addr) {
+static void getSyslog(char *addr, char *virtiolog) {
     int fd;
     int len;
     char buf[1024];
@@ -346,7 +383,12 @@ static void getSyslog(char *addr) {
         if (!strncmp(argv[i], "syslog=", 7)) {
             strncpy(addr, argv[i] + 7, 127);
             addr[127] = '\0';
-            break;
+            continue;
+        }
+        if (!strncmp(argv[i], "virtiolog=", 10)) {
+            strncpy(virtiolog, argv[i] + 10, 127);
+            virtiolog[127] = '\0';
+            continue;
         }
     }
     g_strfreev(argv);
@@ -362,6 +404,14 @@ static void getSyslog(char *addr) {
         sleep(5);
     }
 
+    /* virtiolog can only be letters and digits, dots, dashes and underscores */
+    if (!g_regex_match_simple("^[\\w.-_]*$", addr, 0, 0)) {
+        /* the parameter is malformed, disable its use */
+        virtiolog[0] = '\0';
+        printf("The virtiolog= command line parameter is malformed and will\n");
+        printf("be ignored by the installer.\n");
+        sleep(5);
+    }
 }
 
 static int getInitPid(void) {
diff --git a/scripts/mk-images b/scripts/mk-images
index 1125c9b..d263b25 100755
--- a/scripts/mk-images
+++ b/scripts/mk-images
@@ -812,6 +812,7 @@ $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
 
 $template anaconda_tty4, "%syslogseverity-text:::uppercase% %programname%:%msg%\n"
 $template anaconda_syslog, "%timestamp:8:$:date-rfc3164%,%timestamp:1:3:date-subseconds% %syslogseverity-text:::uppercase% %programname%:%msg%\n"
+$template virtio_ForwardFormat, "<%PRI%>%TIMESTAMP:::date-rfc3339% %syslogtag:1:32%%msg:::sp-if-no-1st-sp%%msg%"
 
 #### RULES ####
 # log everything except anaconda-specific records from local1 (those are stored
-- 
1.7.1

_______________________________________________
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