diff --git a/NEWS b/NEWS index 251a1fec..7ffe74a9 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ procps-ng-NEXT * ps: recognizes SCHED_DEADLINE as valid CPU scheduler * ps: display NUMA node under which a thread ran issue #58 * sysctl: Permit empty string for value issue #74 + * sysctl: Don't segv when file not available issue #76 * top: add config file support for XDG specification * top: eliminated minor libnuma memory leak * top: show fewer memory decimal places (configurable) issue #50 diff --git a/sysctl.c b/sysctl.c index 70042215..9356910f 100644 --- a/sysctl.c +++ b/sysctl.c @@ -220,9 +220,6 @@ static int ReadSetting(const char *restrict const name) fp = fopen(tmpname, "r"); - if (iobuf) - setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ); - if (!fp) { switch (errno) { case ENOENT: @@ -244,6 +241,9 @@ static int ReadSetting(const char *restrict const name) break; } } else { + if (iobuf) + setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ); + errno = 0; if (fgets(inbuf, sizeof inbuf - 1, fp)) { /* this loop is required, see