--- loader/init.c | 122 ------------------------------------------------------- loader/loader.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 123 deletions(-) diff --git a/loader/init.c b/loader/init.c index 0c441e9..02f3cd4 100644 --- a/loader/init.c +++ b/loader/init.c @@ -58,8 +58,6 @@ #include <asm/types.h> #include <linux/serial.h> -static char *VIRTIO_PORT = "/dev/virtio-ports/org.fedoraproject.anaconda.log.0"; - /* * this needs to handle the following cases: * @@ -72,8 +70,6 @@ static char *VIRTIO_PORT = "/dev/virtio-ports/org.fedoraproject.anaconda.log.0"; void shutDown(int doKill, reboot_action rebootAction); static int getKillPolicy(void); -static int getSyslog(gchar **, gchar **); -static int onQEMU(void); struct termios ts; static void printstr(char * string) { @@ -89,51 +85,6 @@ static void fatal_error(int usePerror) { #endif } -/* sets up and launches syslog */ -static void startSyslog(void) { - int conf_fd; - gchar *addr = NULL, *virtiolog = NULL; - const char *forward_tcp = "*.* @@"; - const char *forward_format_tcp = "\n"; - const char *forward_virtio = "*.* "; - const char *forward_format_virtio = ";virtio_ForwardFormat\n"; - - /* update the config file with command line arguments first */ - - if (getSyslog(&addr, &virtiolog)) { - 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 { - if (addr != NULL) { - write(conf_fd, forward_tcp, strlen(forward_tcp)); - write(conf_fd, addr, strlen(addr)); - write(conf_fd, forward_format_tcp, strlen(forward_format_tcp)); - } - if (virtiolog != NULL) { - write(conf_fd, forward_virtio, strlen(forward_virtio)); - write(conf_fd, virtiolog, strlen(virtiolog)); - write(conf_fd, forward_format_virtio, strlen(forward_format_virtio)); - } - close(conf_fd); - } - } - - /* rsyslog is going to take care of things, so disable console logging */ - klogctl(8, NULL, 1); - /* now we really start the daemon. */ - int status; - status = system("/sbin/rsyslogd -c 4"); - if (status < 0 || - !WIFEXITED(status) || - WEXITSTATUS(status) != 0) { - printf("Unable to start syslog daemon.\n"); - fatal_error(1); - } -} - static int setupTerminal(int fd) { struct winsize winsize; gpointer value = NULL; @@ -223,76 +174,6 @@ static int getKillPolicy(void) { return 1; } -/* - * Detects the non-static part of rsyslog configuration. - * - * Remote TCP logging is enabled if syslog= is found on the kernel command - * line. Remote virtio-serial logging is enabled if the declared virtio port - * exists. - */ -static int getSyslog(gchar **addr, gchar **virtiolog) { - gpointer value = NULL; - int ret = 0; - - if (g_hash_table_lookup_extended(cmdline, "syslog", NULL, &value)) { - *addr = (gchar *) value; - /* address can be either a hostname or IPv4 or IPv6, with or without port; - thus we only allow the following characters in the address: letters and - digits, dots, colons, slashes, dashes and square brackets */ - if (g_regex_match_simple("^[\\w.:/\\-\\[\\]]*$", *addr, 0, 0)) { - ++ret; - } else { - /* malformed, disable use */ - *addr = NULL; - printf("The syslog= command line parameter is malformed and will be\n"); - printf("ignored by the installer.\n"); - sleep(5); - } - } - - if (onQEMU()) { - /* look for virtio-serial logging on a QEMU machine. */ - printf("Looking for the virtio ports... "); - if (system("/sbin/udevadm trigger --action=add --sysname-match='vport*'") || - system("/sbin/udevadm settle")) { - fprintf(stderr, "Error calling udevadm trigger to get virtio ports.\n"); - sleep(5); - } else { - printf("done.\n"); - } - if (!access(VIRTIO_PORT, W_OK)) { - /* that means we really have virtio-serial logging */ - *virtiolog = VIRTIO_PORT; - ++ret; - } - } - - return ret; -} - -/* - * Use anything you can find to determine if we are running on a QEMU virtual - * machine. - */ -static int onQEMU(void) -{ - const gchar *lookfor = "QEMU Virtual CPU"; - gchar *contents = NULL; - GError *fileErr = NULL; - int ret = 0; - - if (!g_file_get_contents("/proc/cpuinfo", &contents, NULL, &fileErr)) { - fprintf(stderr, "Unable to read /proc/cpuinfo.\n"); - sleep(5); - return 0; - } - if (strstr(contents, lookfor)) { - ret = 1; - } - g_free(contents); - return ret; -} - static void copyErrorFn (char *msg) { printf(msg); } @@ -520,9 +401,6 @@ int main(int argc, char **argv) { tcsetattr(0, TCSANOW, &ts); } - /* Now we have some /tmp space set up, and /etc and /dev point to - it. We should be in pretty good shape. */ - startSyslog(); /* Go into normal init mode - keep going, and then do a orderly shutdown when: diff --git a/loader/loader.c b/loader/loader.c index d2853e2..194975e 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -44,6 +44,7 @@ #include <arpa/inet.h> #include <sys/ioctl.h> +#include <sys/klog.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> @@ -128,6 +129,8 @@ static pid_t init_pid = 1; static int init_sig = SIGUSR1; /* default to shutdown=halt */ static const char *LANG_DEFAULT = "en_US.UTF-8"; +static char *VIRTIO_PORT = "/dev/virtio-ports/org.fedoraproject.anaconda.log.0"; + static struct installMethod installMethods[] = { { N_("Local CD/DVD"), "METHOD_CDROM", 0, DEVICE_CDROM, promptForCdrom, loadCdromImages}, { N_("Hard drive"), "METHOD_HD", 0, DEVICE_DISK, promptForHardDrive, loadHdImages }, @@ -1195,6 +1198,120 @@ static int haveDeviceOfType(int type) { return 0; } +/* + * Use anything you can find to determine if we are running on a QEMU virtual + * machine. + */ +static int onQEMU(void) +{ + const gchar *lookfor = "QEMU Virtual CPU"; + gchar *contents = NULL; + GError *fileErr = NULL; + int ret = 0; + + if (!g_file_get_contents("/proc/cpuinfo", &contents, NULL, &fileErr)) { + fprintf(stderr, "Unable to read /proc/cpuinfo.\n"); + sleep(5); + return 0; + } + if (strstr(contents, lookfor)) { + ret = 1; + } + g_free(contents); + return ret; +} + +/* + * Detects the non-static part of rsyslog configuration. + * + * Remote TCP logging is enabled if syslog= is found on the kernel command + * line. Remote virtio-serial logging is enabled if the declared virtio port + * exists. + */ +static int getSyslog(gchar **addr, gchar **virtiolog) { + gpointer value = NULL; + int ret = 0; + + if (g_hash_table_lookup_extended(cmdline, "syslog", NULL, &value)) { + *addr = (gchar *) value; + /* address can be either a hostname or IPv4 or IPv6, with or without port; + thus we only allow the following characters in the address: letters and + digits, dots, colons, slashes, dashes and square brackets */ + if (g_regex_match_simple("^[\\w.:/\\-\\[\\]]*$", *addr, 0, 0)) { + ++ret; + } else { + /* malformed, disable use */ + *addr = NULL; + printf("The syslog= command line parameter is malformed and will be\n"); + printf("ignored by the installer.\n"); + sleep(5); + } + } + + if (onQEMU()) { + /* look for virtio-serial logging on a QEMU machine. */ + printf("Looking for the virtio ports... "); + if (system("/sbin/udevadm trigger --action=add --sysname-match='vport*'") || + system("/sbin/udevadm settle")) { + fprintf(stderr, "Error calling udevadm trigger to get virtio ports.\n"); + sleep(5); + } else { + printf("done.\n"); + } + if (!access(VIRTIO_PORT, W_OK)) { + /* that means we really have virtio-serial logging */ + *virtiolog = VIRTIO_PORT; + ++ret; + } + } + + return ret; +} + +/* sets up and restarts syslog */ +static void restartSyslog(void) { + int conf_fd; + gchar *addr = NULL, *virtiolog = NULL; + const char *forward_tcp = "*.* @@"; + const char *forward_format_tcp = "\n"; + const char *forward_virtio = "*.* "; + const char *forward_format_virtio = ";virtio_ForwardFormat\n"; + + /* update the config file with command line arguments first */ + if (!getSyslog(&addr, &virtiolog)) + return; + + 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 { + if (addr != NULL) { + write(conf_fd, forward_tcp, strlen(forward_tcp)); + write(conf_fd, addr, strlen(addr)); + write(conf_fd, forward_format_tcp, strlen(forward_format_tcp)); + } + if (virtiolog != NULL) { + write(conf_fd, forward_virtio, strlen(forward_virtio)); + write(conf_fd, virtiolog, strlen(virtiolog)); + write(conf_fd, forward_format_virtio, strlen(forward_format_virtio)); + } + close(conf_fd); + } + + /* rsyslog is going to take care of things, so disable console logging */ + klogctl(8, NULL, 1); + /* now we really start the daemon. */ + int status = system("/bin/systemctl --quiet restart rsyslog.service"); + if (status < 0 || + !WIFEXITED(status) || + WEXITSTATUS(status) != 0) { + printf("Unable to start syslog daemon.\n"); + doExit(EXIT_FAILURE); + } +} + static void doLoaderMain(struct loaderData_s *loaderData, moduleInfoSet modInfo) { enum { STEP_LANG, STEP_KBD, STEP_METHOD, STEP_DRIVER, @@ -1782,8 +1899,10 @@ int main(int argc, char ** argv) { cmdline = readvars_parse_file("/proc/cmdline"); + restartSyslog(); + /* check for development mode early */ - if (g_hash_table_lookup_extended(cmdline, "devel", NULL, NULL)) { + if (cmdline && g_hash_table_lookup_extended(cmdline, "devel", NULL, NULL)) { printf("Enabling development mode - cores will be dumped\n"); isDevelMode = 1; } -- 1.7.4.1 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list