sysvinit-devel
[Top][All Lists]
Advanced

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

Re: [sysvinit-devel] [PATCH 0/5] init.c: add return tests for fprintf()


From: Michał Kulling
Subject: Re: [sysvinit-devel] [PATCH 0/5] init.c: add return tests for fprintf()
Date: Tue, 11 Feb 2014 04:10:39 -0800

I created new function get_cmd_record() - looks like a fscanf() wrapper for first switch in *get_record().
When something go wrong - eg. open fd, read from fd, etc, get_cmd_record() returns zero as a failure.

I skipped second switch block, for detailed information (write to output name of cmd):

#v+
@@ -418,10 +447,16 @@
                        get_void(f);
                        break;
                case C_PID:
-                       fscanf(f, "%d\n", &(p->pid));
+                       if(fscanf(f, "%d\n", &(p->pid)) < 0){
+                               fprintf(stderr, "Failed to read PID: %s\n", strerror(errno));
+                               return NULL;
+                       }
                        break;
                case C_EXS:
-                       fscanf(f, "%u\n", &(p->exstat));
+                       if(fscanf(f, "%u\n", &(p->exstat)) < 0){
+                               fprintf(stderr, "Failed to read EXS: %s\n", strerror(errno));
+                               return NULL;
+                       }
                        break;
                case C_LEV:
                        get_string(p->rlevel, sizeof(p->rlevel), f);
#v-

I skipped setting oops_error, because it's never tested.

I can add a testing oops_error in while() statement:

#v+
/* Additional patch */
@@ -449,8 +484,10 @@
                        free(p);
                        oops_error = -1;
                        return NULL;
-       } while( cmd != C_EOR);
+       } while( cmd != C_EOR && oops_error != -1);

+       if(oops_error == -1)
+               return NULL;
        return p;
#v-

then it makes sense to use.

But, there we need to ask - we need to test it?

Patch for rev 159 in attachment.

Attachment: init.c_patch0_11022014.patch
Description: Text Data


reply via email to

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