Skip to content

Commit

Permalink
ovs-vsctl: simply vsctl_parent_process_info()
Browse files Browse the repository at this point in the history
Use ds_get_line() instead of hand rolling it. Rearrange the logic
to removes some duplication.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
Acked-by: William Tu <[email protected]>
  • Loading branch information
azhou-nicira committed Aug 10, 2016
1 parent 0693531 commit ed29f22
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2488,26 +2488,16 @@ vsctl_parent_process_info(void)
procfile = xasprintf("/proc/%d/cmdline", parent_pid);

f = fopen(procfile, "r");
if (!f) {
free(procfile);
return NULL;
}
free(procfile);

for (;;) {
int c = getc(f);
if (!c || c == EOF) {
break;
}
ds_put_char(&s, c);
if (f) {
ds_get_line(&s, f);
fclose(f);
}
fclose(f);
} else {
ds_put_cstr(&s, "init");
}

ds_put_format(&s, " (pid %d)", parent_pid);

return ds_steal_cstr(&s);
#else
return NULL;
Expand Down

0 comments on commit ed29f22

Please sign in to comment.