sysvinit-devel
[Top][All Lists]
Advanced

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

[sysvinit-devel] TODO in src/init.c


From: Zachary Winnerman
Subject: [sysvinit-devel] TODO in src/init.c
Date: Wed, 26 Dec 2012 23:10:54 -0500

Sysvinit maintainers,

Below is a git-diff that implements the TODO mentioned in src/init.c.
I am not very familiar with SVN, so I am not sure how to properly
submit this patch.  Thank you for your time.
diff --git a/src/init.c b/src/init.c
index 27532ad..3b72575 100644
--- a/src/init.c
+++ b/src/init.c
@@ -309,22 +309,6 @@ void send_state(int fd)
 }

 /*
- *     Read a string from a file descriptor.
- *     FIXME: why not use fgets() ?
- */
-static int get_string(char *p, int size, FILE *f)
-{
-       int     c;
-
-       while ((c = getc(f)) != EOF && c != '\n') {
-               if (--size > 0)
-                       *p++ = c;
-       }
-       *p = '\0';
-       return (c != EOF) && (size > 0);
-}
-
-/*
  *     Read trailing data from the state pipe until we see a newline.
  */
 static int get_void(FILE *f)
@@ -412,7 +396,7 @@ static CHILD *get_record(FILE *f)
        } while (cmd != C_REC);

        p = imalloc(sizeof(CHILD));
-       get_string(p->id, sizeof(p->id), f);
+       fgets(p->id, sizeof(p->id), f);

        do switch(cmd = get_cmd(f)) {
                case 0:
@@ -426,13 +410,13 @@ static CHILD *get_record(FILE *f)
                        fscanf(f, "%u\n", &(p->exstat));
                        break;
                case C_LEV:
-                       get_string(p->rlevel, sizeof(p->rlevel), f);
+                       fgets(p->rlevel, sizeof(p->rlevel), f);
                        break;
                case C_PROCESS:
-                       get_string(p->process, sizeof(p->process), f);
+                       fgets(p->process, sizeof(p->process), f);
                        break;
                case C_FLAG:
-                       get_string(s, sizeof(s), f);
+                       fgets(s, sizeof(s), f);
                        for(i = 0; flags[i].name; i++) {
                                if (strcmp(flags[i].name,s) == 0)
                                        break;
@@ -440,7 +424,7 @@ static CHILD *get_record(FILE *f)
                        p->flags |= flags[i].mask;
                        break;
                case C_ACTION:
-                       get_string(s, sizeof(s), f);
+                       fgets(s, sizeof(s), f);
                        for(i = 0; actions[i].name; i++) {
                                if (strcmp(actions[i].name, s) == 0)
                                        break;
@@ -471,7 +455,7 @@ int receive_state(int fd)

        if (get_cmd(f) != C_VER)
                return -1;
-       get_string(old_version, sizeof(old_version), f);
+       fgets(old_version, sizeof(old_version), f);
        oops_error = 0;
        for (pp = &family; (*pp = get_record(f)) != NULL; pp = &((*pp)->next))
                ;

Thank you,
Zach



reply via email to

[Prev in Thread] Current Thread [Next in Thread]