FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 07-22-2010, 09:15 PM
David Cantrell
 
Default Use readvars_parse_file in loader/init.c

---
loader/init.c | 168 ++++++++++++++++++++-------------------------------------
1 files changed, 58 insertions(+), 110 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index aa1802e..a386631 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -55,6 +55,7 @@
#include "devt.h"
#include "devices.h"
#include "modules.h"
+#include "readvars.h"

#include <asm/types.h>
#include <linux/serial.h>
@@ -107,11 +108,13 @@ char * env[] = {

void shutDown(int doKill, reboot_action rebootAction);
static int getKillPolicy(void);
-static void getSyslog(char *, char *);
+static gchar *getSyslog(gchar **);
struct termios ts;

static int expected_exit = 0;

+static GHashTable *cmdline = NULL;
+
static void doExit(int) __attribute__ ((noreturn));
static void doExit(int result)
{
@@ -137,45 +140,48 @@ static void fatal_error(int usePerror) {
static void startSyslog(void) {
int conf_fd;
int ret;
- char addr[128];
- char virtiolog[128];
+ gchar *addr = NULL, *virtiolog = NULL;
const char *forward_tcp = "*.* @@";
const char *forward_format_tcp = "
";
const char *forward_virtio = "*.* /dev/virtio-ports/";
const char *forward_format_virtio = ";virtio_ForwardFormat
";
-
+
/* 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);
}
-
- if (strlen(virtiolog)) {
+
+ if (virtiolog != NULL) {
printf("Loading virtio_pci module... ");
if (mlLoadModule("virtio_pci", NULL)) {
printf("Error loading virtio_pci module. ");
printf("Virtio logging will not work.
.");
sleep(5);
} else {
- printf("done.
");
+ printf("done.
");
}
+
+ g_free(virtiolog);
}

/* rsyslog is going to take care of things, so disable console logging */
@@ -193,8 +199,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");
@@ -217,11 +222,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";
}
}

@@ -318,79 +320,54 @@ static void sigUsr2Handler(int signum) {
}

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;

if (!strncmp(basename(argv[0]), "poweroff", 8)) {
printf("Running poweroff...
");
@@ -519,41 +496,12 @@ int main(int argc, char **argv) {
fatal_error(1);
printf("done
");

+ cmdline = readvars_parse_file("/proc/cmdline");
+
/* check for development mode early */
- int fdn;
- if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
-
- /* get cmdline info */
- int len = read(fdn, buf, sizeof(buf) - 1);
- char *develstart;
- close(fdn);
-
- /* check the arguments */
- if (len > 0) {
- develstart = buf;
- while (develstart && (*develstart) != '') {
-
- /* strip spaces */
- while(*develstart == ' ') develstart++;
- if(*develstart == '') break;
-
- /* not the word we are looking for */
- if (strncmp(develstart, "devel", 5)) {
- develstart = strchr(develstart, ' ');
- continue;
- }
-
- /* is it isolated? */
- if(((*(develstart+5)) == ' ' || (*(develstart+5)) == '')) {
- printf("Enabling development mode - cores will be dumped
");
- isDevelMode++;
- break;
- }
-
- /* Find next argument */
- develstart = strchr(develstart, ' ');
- }
- }
+ if (g_hash_table_lookup_extended(cmdline, "devel", NULL, value)) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode = TRUE;
}

/* these args are only for testing from commandline */
--
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 07-23-2010, 12:41 AM
"Brian C. Lane"
 
Default Use readvars_parse_file in loader/init.c

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/22/2010 02:15 PM, David Cantrell wrote:

> +static gchar *getSyslog(gchar **virtiolog) {
> + gpointer value = NULL;
> + gchar *addr = NULL;
> +

Check virtiolog to make sure it is pointing someplace before using it.


> + if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, value)) {

Pass &value

> + if (!g_hash_table_lookup_extended(cmdline, "syslog", NULL, value)) {

Pass &value

> + if (g_hash_table_lookup_extended(cmdline, "devel", NULL, value)) {
> + printf("Enabling development mode - cores will be dumped
");
> + isDevelMode = TRUE;

That is sooo much nicer

- --
Brian C. Lane <bcl@redhat.com>
Red Hat / Port Orchard, WA
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEVAwUBTEjlKxF+jBaO/jp/AQJjhQgAnfIbEHiaVvB3TCJNFfZzfva3IhKP5O2u
rYTQxezRJbRUeW0jtPc9AUP4PAjmMM1f/nGhggwZd+s406vTGKuBRoueQ6Ig89j6
VRtg/QCM2mJ4SkYTAq52xJ390nzTN5bi2o0YKDHNs0DxbI8WZDLVQu/VoqbtTSCo
fWpWQJE1NLBLDIpEcI/5GOX1kgGOlh7kOzGMsoQP8jE2foQzRifjI3gl+pJBvb9D
xqcoc7v990R3t58ITa+/r/QTKfVJIfSvBCG5Spi9msPC9tUQMfTm7l9+8QbshJEt
2WbZbq21KolDUgoB4iu04wvGweRNt39qIh0RtQ02htta09z/krut/A==
=YqPa
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 07-27-2010, 04:09 AM
David Cantrell
 
Default Use readvars_parse_file in loader/init.c

On Thu, 22 Jul 2010, Brian C. Lane wrote:


On 07/22/2010 02:15 PM, David Cantrell wrote:


+static gchar *getSyslog(gchar **virtiolog) {
+ gpointer value = NULL;
+ gchar *addr = 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
 
Old 07-27-2010, 04:15 AM
David Cantrell
 
Default Use readvars_parse_file in loader/init.c

---
loader/init.c | 172 +++++++++++++++++++++-----------------------------------
1 files changed, 65 insertions(+), 107 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index f7ab4d4..655c545 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -55,6 +55,7 @@
#include "devt.h"
#include "devices.h"
#include "modules.h"
+#include "readvars.h"

#include <asm/types.h>
#include <linux/serial.h>
@@ -107,11 +108,12 @@ char * env[] = {

void shutDown(int doKill, reboot_action rebootAction);
static int getKillPolicy(void);
-static void getSyslog(char *, char *);
+static gchar *getSyslog(gchar **);
static int onQEMU(void);
struct termios ts;

static int expected_exit = 0;
+static GHashTable *cmdline = NULL;

static void doExit(int) __attribute__ ((noreturn));
static void doExit(int result)
@@ -138,36 +140,37 @@ static void fatal_error(int usePerror) {
static void startSyslog(void) {
int conf_fd;
int ret;
- char addr[128];
- char virtiolog[128];
+ gchar *addr = NULL, *virtiolog = NULL;
const char *forward_tcp = "*.* @@";
const char *forward_format_tcp = "
";
const char *forward_virtio = "*.* ";
const char *forward_format_virtio = ";virtio_ForwardFormat
";
-
+
/* 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";
}
}

@@ -308,63 +307,49 @@ static void sigUsr2Handler(int signum) {
}

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;

if (!strncmp(basename(argv[0]), "poweroff", 8)) {
printf("Running poweroff...
");
@@ -542,41 +529,12 @@ int main(int argc, char **argv) {
fatal_error(1);
printf("done
");

+ cmdline = readvars_parse_file("/proc/cmdline");
+
/* check for development mode early */
- int fdn;
- if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
-
- /* get cmdline info */
- int len = read(fdn, buf, sizeof(buf) - 1);
- char *develstart;
- close(fdn);
-
- /* check the arguments */
- if (len > 0) {
- develstart = buf;
- while (develstart && (*develstart) != '') {
-
- /* strip spaces */
- while(*develstart == ' ') develstart++;
- if(*develstart == '') break;
-
- /* not the word we are looking for */
- if (strncmp(develstart, "devel", 5)) {
- develstart = strchr(develstart, ' ');
- continue;
- }
-
- /* is it isolated? */
- if(((*(develstart+5)) == ' ' || (*(develstart+5)) == '')) {
- printf("Enabling development mode - cores will be dumped
");
- isDevelMode++;
- break;
- }
-
- /* Find next argument */
- develstart = strchr(develstart, ' ');
- }
- }
+ if (g_hash_table_lookup_extended(cmdline, "devel", NULL, value)) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode = TRUE;
}

/* these args are only for testing from commandline */
--
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 07-27-2010, 05:55 AM
"Brian C. Lane"
 
Default Use readvars_parse_file in loader/init.c

On 07/26/2010 09:15 PM, David Cantrell wrote:

---


NAK


+ if (g_hash_table_lookup_extended(cmdline, "utf8", NULL, value)) {
+ env[ENV_TERM] = "TERM=vt100";


&value


+ if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, value)) {
+ return 0;


&value


+ if (g_hash_table_lookup_extended(cmdline, "devel", NULL, value)) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode = TRUE;


&value

I must have missed those the 1st time through.

--
Brian C. Lane <bcl@redhat.com>
Red Hat / Port Orchard, WA

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 07-27-2010, 06:55 AM
David Cantrell
 
Default Use readvars_parse_file in loader/init.c

On Mon, 26 Jul 2010, Brian C. Lane wrote:


On 07/26/2010 09:15 PM, David Cantrell wrote:

---


NAK


+ if (g_hash_table_lookup_extended(cmdline, "utf8", NULL, value)) {
+ env[ENV_TERM] = "TERM=vt100";


&value


+ if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, value)) {
+ return 0;


&value


+ if (g_hash_table_lookup_extended(cmdline, "devel", NULL, value)) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode = TRUE;


&value

I must have missed those the 1st time through.


Whoops, here's the updated patch:

---
loader/init.c | 172 +++++++++++++++++++++-----------------------------------
1 files changed, 65 insertions(+), 107 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index f7ab4d4..411e6dc 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -55,6 +55,7 @@
#include "devt.h"
#include "devices.h"
#include "modules.h"
+#include "readvars.h"

#include <asm/types.h>
#include <linux/serial.h>
@@ -107,11 +108,12 @@ char * env[] = {

void shutDown(int doKill, reboot_action rebootAction);
static int getKillPolicy(void);
-static void getSyslog(char *, char *);
+static gchar *getSyslog(gchar **);
static int onQEMU(void);
struct termios ts;

static int expected_exit = 0;
+static GHashTable *cmdline = NULL;

static void doExit(int) __attribute__ ((noreturn));
static void doExit(int result)
@@ -138,36 +140,37 @@ static void fatal_error(int usePerror) {
static void startSyslog(void) {
int conf_fd;
int ret;
- char addr[128];
- char virtiolog[128];
+ gchar *addr = NULL, *virtiolog = NULL;
const char *forward_tcp = "*.* @@";
const char *forward_format_tcp = "
";
const char *forward_virtio = "*.* ";
const char *forward_format_virtio = ";virtio_ForwardFormat
";
-
+

/* 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";
}
}

@@ -308,63 +307,49 @@ static void sigUsr2Handler(int signum) {
}

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;

if (!strncmp(basename(argv[0]), "poweroff", 8)) {
printf("Running poweroff...
");
@@ -542,41 +529,12 @@ int main(int argc, char **argv) {
fatal_error(1);
printf("done
");

+ cmdline = readvars_parse_file("/proc/cmdline");
+
/* check for development mode early */
- int fdn;
- if ((fdn = open("/proc/cmdline", O_RDONLY, 0)) != -1) {
-
- /* get cmdline info */
- int len = read(fdn, buf, sizeof(buf) - 1);
- char *develstart;
- close(fdn);
-
- /* check the arguments */
- if (len > 0) {
- develstart = buf;
- while (develstart && (*develstart) != '') {
-
- /* strip spaces */

- while(*develstart == ' ') develstart++;
- if(*develstart == '') break;
-
- /* not the word we are looking for */

- if (strncmp(develstart, "devel", 5)) {
- develstart = strchr(develstart, ' ');
- continue;
- }
-
- /* is it isolated? */

- if(((*(develstart+5)) == ' ' || (*(develstart+5)) == '')) {
- printf("Enabling development mode - cores will be dumped
");
- isDevelMode++;
- break;
- }
-
- /* Find next argument */

- develstart = strchr(develstart, ' ');
- }
- }
+ if (g_hash_table_lookup_extended(cmdline, "devel", NULL, &value)) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode = TRUE;
}

/* these args are only for testing from commandline */

--
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
 
Old 07-27-2010, 02:11 PM
"Brian C. Lane"
 
Default Use readvars_parse_file in loader/init.c

On 07/26/2010 11:55 PM, David Cantrell wrote:

On Mon, 26 Jul 2010, Brian C. Lane wrote:


On 07/26/2010 09:15 PM, David Cantrell wrote:

---


NAK


+ if (g_hash_table_lookup_extended(cmdline, "utf8", NULL, value)) {
+ env[ENV_TERM] = "TERM=vt100";


&value


+ if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, value)) {
+ return 0;


&value


+ if (g_hash_table_lookup_extended(cmdline, "devel", NULL, value)) {
+ printf("Enabling development mode - cores will be dumped
");
+ isDevelMode = TRUE;


&value

I must have missed those the 1st time through.


Whoops, here's the updated patch:


Ack!


--
Brian C. Lane <bcl@redhat.com>
Red Hat / Port Orchard, WA

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

Thread Tools




All times are GMT. The time now is 09:29 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org