static int getKillPolicy(void) {
- int fd;
- int len;
- char buf[1024];
+ gpointer value = NULL;
/* look through /proc/cmdline for special options */
- if ((fd = open("/proc/cmdline", O_RDONLY,0)) > 0) {
- len = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- if ((len > 0) && strstr(buf, "nokill"))
- return 0;
+ if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, value)) {
+ return 0;
}
+
return 1;
}
/* Looks through /proc/cmdline for remote syslog paramters. */
-static void getSyslog(char *addr, char *virtiolog) {
- int fd;
- int len;
- char buf[1024];
-
- /* assume nothing gets found */
- addr[0] = ' ';
- virtiolog[0] = ' ';
- if ((fd = open("/proc/cmdline", O_RDONLY,0)) <= 0) {
- return;
- }
- len = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- buf[len] = ' ';
-
- /* Parse the command line into argument vector using glib */
- int i;
- int argc;
- char** argv;
- GError* err = NULL;
- if (!g_shell_parse_argv(buf, &argc, &argv, &err )) {
- g_error_free(err);
- return;
+static gchar *getSyslog(gchar **virtiolog) {
+ gpointer value = NULL;
+ gchar *addr = NULL;
+
+ if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, value)) {
+ return NULL;
+ } else {
+ addr = (gchar *) value;
}
- for (i = 0; i < argc; ++i) {
- /* find what we are looking for */
- if (!strncmp(argv[i], "syslog=", 7)) {
- strncpy(addr, argv[i] + 7, 127);
- addr[127] = ' ';
- continue;
- }
- if (!strncmp(argv[i], "virtiolog=", 10)) {
- strncpy(virtiolog, argv[i] + 10, 127);
- virtiolog[127] = ' ';
- continue;
+
+ if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, value)) {
+ *virtiolog = NULL;
+ } else {
+ *virtiolog = (gchar *) value;
+
+ /* virtiolog can only be letters and digits, dots, dashes and underscores */
+ if (!g_regex_match_simple("^[w.-_]*$", *virtiolog, 0, 0)) {
+ /* the parameter is malformed, disable its use */
+ *virtiolog = NULL;
+ printf("The virtiolog= command line parameter is malformed and will
");
+ printf("be ignored by the installer.
");
+ sleep(5);
}
}
- g_strfreev(argv);
/* 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)) {
/* the parameter is malformed, disable its use */
- addr[0] = ' ';
+ addr = NULL;
printf("The syslog= command line parameter is malformed and will be
");
printf("ignored by the installer.
");
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] = ' ';
- printf("The virtiolog= command line parameter is malformed and will
");
- printf("be ignored by the installer.
");
- sleep(5);
- }
+ return addr;
}
static int getInitPid(void) {
@@ -470,16 +447,16 @@ int main(int argc, char **argv) {
int doShutdown =0;
reboot_action shutdown_method = HALT;
int isSerial = 0;
- int isDevelMode = 0;
+ gboolean isDevelMode = FALSE;
char * console = NULL;
int doKill = 1;
char * argvc[15];
- char buf[1024];
char ** argvp = argvc;
char twelve = 12;
struct serial_struct si;
int i, disable_keys;
int ret;
+ gpointer value = NULL;
Check virtiolog to make sure it is pointing someplace before using it.
The 2nd g_hash_table_lookup_extended() in this function is meant to do that.
Updated in the next patch series. I was not supposed to look up syslog twice,
but look up syslog first then virtiolog.
+ if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, value)) {
Pass &value
+ if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, value)) {
Pass &value
Fixed, thanks.
--
David Cantrell <dcantrell@redhat.com>
Red Hat / Honolulu, HI
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
static int getKillPolicy(void) {
- int fd;
- int len;
- char buf[1024];
+ gpointer value = NULL;
- /* look through /proc/cmdline for special options */
- if ((fd = open("/proc/cmdline", O_RDONLY,0)) > 0) {
- len = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- if ((len > 0) && strstr(buf, "nokill"))
- return 0;
+ if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, value)) {
+ return 0;
}
+
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.
+/*
+ * 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 void getSyslog(char *addr, char *virtiolog)
-{
+static gchar *getSyslog(gchar **virtiolog) {
+ gpointer value = NULL;
+ gchar *addr = NULL;
const char *virtio_port = "/dev/virtio-ports/org.fedoraproject.anaconda.log.0";
- int fd;
- int len;
- char buf[1024];
-
- /* assume nothing gets found */
- addr[0] = ' ';
- virtiolog[0] = ' ';
- if ((fd = open("/proc/cmdline", O_RDONLY,0)) <= 0) {
- return;
- }
- len = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- buf[len] = ' ';
-
- /* Parse the command line into argument vector using glib */
- int i;
- int argc;
- char** argv;
- GError* err = NULL;
- if (!g_shell_parse_argv(buf, &argc, &argv, &err )) {
- g_error_free(err);
- return;
+ if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, &value)) {
+ return NULL;
+ } else {
+ addr = (gchar *) value;
}
- for (i = 0; i < argc; ++i) {
- /* find what we are looking for */
- if (!strncmp(argv[i], "syslog=", 7)) {
- strncpy(addr, argv[i] + 7, 127);
- addr[127] = ' ';
- continue;
+
+ if (!g_hash_table_lookup_extended(cmdline, "virtiolog", NULL, &value)) {
+ *virtiolog = NULL;
+ } else {
+ *virtiolog = (gchar *) value;
+
+ /* virtiolog can only be letters and digits, dots, dashes
+ * and underscores */
+ if (!g_regex_match_simple("^[w.-_]*$", *virtiolog, 0, 0)) {
+ /* the parameter is malformed, disable its use */
+ *virtiolog = NULL;
+ printf("The virtiolog= command line parameter is malformed and will
");
+ printf("be ignored by the installer.
");
+ sleep(5);
}
}
- g_strfreev(argv);
-
+
if (onQEMU()) {
/* look for virtio-serial logging on a QEMU machine. */
printf("Loading virtio_pci module... ");
@@ -372,12 +357,12 @@ static void getSyslog(char *addr, char *virtiolog)
fprintf(stderr, "Error loading virtio_pci module.
");
sleep(5);
} else {
- printf("done.
");
+ printf("done.
");
}
if (!access(virtio_port, W_OK)) {
/* that means we really have virtio-serial logging */
- strncpy(virtiolog, virtio_port, 127);
- virtiolog[127] = ' ';
+ g_free(*virtiolog);
+ *virtiolog = g_strdup(virtio_port);
}
}
@@ -386,11 +371,13 @@ static void getSyslog(char *addr, char *virtiolog)
digits, dots, colons, slashes, dashes and square brackets */
if (!g_regex_match_simple("^[w.:/-[]]*$", addr, 0, 0)) {
/* the parameter is malformed, disable its use */
- addr[0] = ' ';
+ addr = NULL;
printf("The syslog= command line parameter is malformed and will be
");
printf("ignored by the installer.
");
sleep(5);
}
+
+ return addr;
}
/*
@@ -493,16 +480,16 @@ int main(int argc, char **argv) {
int doShutdown =0;
reboot_action shutdown_method = HALT;
int isSerial = 0;
- int isDevelMode = 0;
+ gboolean isDevelMode = FALSE;
char * console = NULL;
int doKill = 1;
char * argvc[15];
- char buf[1024];
char ** argvp = argvc;
char twelve = 12;
struct serial_struct si;
int i, disable_keys;
int ret;
+ gpointer value = NULL;
/* update the config file with command line arguments first */
- getSyslog(addr, virtiolog);
- if (strlen(addr) > 0 || strlen(virtiolog) > 0) {
+ addr = getSyslog(&virtiolog);
+ if (addr != NULL) {
conf_fd = open("/etc/rsyslog.conf", O_WRONLY|O_APPEND);
if (conf_fd < 0) {
printf("error opening /etc/rsyslog.conf: %d
", errno);
printf("syslog forwarding will not be enabled
");
sleep(5);
} else {
- 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_tcp, strlen(forward_tcp));
+ ret = write(conf_fd, addr, strlen(addr));
+ ret = write(conf_fd, forward_format_tcp, strlen(forward_format_tcp));
+
+ if (virtiolog != NULL) {
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);
}
+
+ g_free(addr);
}
-
+
/* rsyslog is going to take care of things, so disable console logging */
klogctl(8, NULL, 1);
/* now we really start the daemon. */
@@ -183,8 +186,7 @@ static void startSyslog(void) {
static int setupTerminal(int fd) {
struct winsize winsize;
- int fdn, len;
- char buf[65535];
+ gpointer value = NULL;
if (ioctl(fd, TIOCGWINSZ, &winsize)) {
printf("failed to get winsize");
@@ -207,11 +209,8 @@ static int setupTerminal(int fd) {
env[ENV_TERM] = "TERM=vt100-nav";
/* unless the user specifies that they want utf8 */
- if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
- len = read(fdn, buf, sizeof(buf) - 1);
- close(fdn);
- if (len > 0 && strstr(buf, "utf8"))
- env[ENV_TERM] = "TERM=vt100";
+ if (g_hash_table_lookup_extended(cmdline, "utf8", NULL, &value)) {
+ env[ENV_TERM] = "TERM=vt100";
}
}
static int getKillPolicy(void) {
- int fd;
- int len;
- char buf[1024];
+ gpointer value = NULL;
- /* look through /proc/cmdline for special options */
- if ((fd = open("/proc/cmdline", O_RDONLY,0)) > 0) {
- len = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- if ((len > 0) && strstr(buf, "nokill"))
- return 0;
+ if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, &value)) {
+ return 0;
}
+
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.
+/*
+ * 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 void getSyslog(char *addr, char *virtiolog)
-{
+static gchar *getSyslog(gchar **virtiolog) {
+ gpointer value = NULL;
+ gchar *addr = NULL;
const char *virtio_port = "/dev/virtio-ports/org.fedoraproject.anaconda.log.0";
- int fd;
- int len;
- char buf[1024];
-
- /* assume nothing gets found */
- addr[0] = ' ';
- virtiolog[0] = ' ';
- if ((fd = open("/proc/cmdline", O_RDONLY,0)) <= 0) {
- return;
- }
- len = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- buf[len] = ' ';
-
- /* Parse the command line into argument vector using glib */
- int i;
- int argc;
- char** argv;
- GError* err = NULL;
- if (!g_shell_parse_argv(buf, &argc, &argv, &err )) {
- g_error_free(err);
- return;
+ if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, &value)) {
+ return NULL;
+ } else {
+ addr = (gchar *) value;
}
- for (i = 0; i < argc; ++i) {
- /* find what we are looking for */
- if (!strncmp(argv[i], "syslog=", 7)) {
- strncpy(addr, argv[i] + 7, 127);
- addr[127] = ' ';
- continue;
+
+ if (!g_hash_table_lookup_extended(cmdline, "virtiolog", NULL, &value)) {
+ *virtiolog = NULL;
+ } else {
+ *virtiolog = (gchar *) value;
+
+ /* virtiolog can only be letters and digits, dots, dashes
+ * and underscores */
+ if (!g_regex_match_simple("^[w.-_]*$", *virtiolog, 0, 0)) {
+ /* the parameter is malformed, disable its use */
+ *virtiolog = NULL;
+ printf("The virtiolog= command line parameter is malformed and will
");
+ printf("be ignored by the installer.
");
+ sleep(5);
}
}
- g_strfreev(argv);
-
+