Use ds_get_line() instead of hand rolling it. Rearrange the logic
to removes some duplication.

Signed-off-by: Andy Zhou <az...@ovn.org>
---
 utilities/ovs-vsctl.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 722dcd9..1c18de8 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -2481,26 +2481,16 @@ vsctl_parent_process_info(void)
     parent_pid = getppid();
     procfile = xasprintf("/proc/%d/cmdline", parent_pid);
 
+    ds_init(&s);
     f = fopen(procfile, "r");
-    if (!f) {
+    if (f) {
+        ds_get_line(&s, f);
+        fclose(f);
+    } else {
         VLOG_WARN("%s: open failed (%s)", procfile, ovs_strerror(errno));
-        free(procfile);
-        return NULL;
     }
-    free(procfile);
-
-    ds_init(&s);
-    for (;;) {
-        int c = getc(f);
-        if (!c || c == EOF) {
-            break;
-        }
-        ds_put_char(&s, c);
-    }
-    fclose(f);
-
-    ds_put_format(&s, " (pid %d)", parent_pid);
 
+    free(procfile);
     return ds_steal_cstr(&s);
 #else
     return NULL;
-- 
1.9.1

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to