diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c index ec02e8b75..e95d20d9b 100644 --- a/src/librc/librc-daemon.c +++ b/src/librc/librc-daemon.c @@ -129,8 +129,9 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid) if (exists("/proc/self/status")) { fp = fopen("/proc/self/status", "r"); if (fp) { - while (!feof(fp)) { - rc_getline(&line, &len, fp); + while (! feof(fp)) { + if (getline(&line, &len, fp) <= 0) + break; if (strncmp(line, "envID:\t0", 8) == 0) { openvz_host = true; break; @@ -185,8 +186,9 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid) free(buffer); if (!fp) continue; - while (!feof(fp)) { - rc_getline(&line, &len, fp); + while (! feof(fp)) { + if (getline(&line, &len, fp) <= 0) + break; if (strncmp(line, "envID:", 6) == 0) { container_pid = !(strncmp(line, "envID:\t0", 8) == 0); break; @@ -335,7 +337,7 @@ _match_daemon(const char *path, const char *file, RC_STRINGLIST *match) if (!fp) return false; - while ((rc_getline(&line, &len, fp))) { + while ((getline(&line, &len, fp) > 0)) { TAILQ_FOREACH(m, match, entries) if (strcmp(line, m->value) == 0) { TAILQ_REMOVE(match, m, entries); @@ -538,7 +540,7 @@ rc_service_daemons_crashed(const char *service) if (!fp) break; - while ((rc_getline(&line, &len, fp))) { + while ((getline(&line, &len, fp) > 0)) { p = line; if ((token = strsep(&p, "=")) == NULL || !p) continue; diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index 03149a52f..aeb69b3d4 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -130,7 +130,7 @@ rc_deptree_load_file(const char *deptree_file) deptree = xmalloc(sizeof(*deptree)); TAILQ_INIT(deptree); - while ((rc_getline(&line, &len, fp))) + while ((getline(&line, &len, fp) > 0)) { p = line; e = strsep(&p, "_"); @@ -775,7 +775,7 @@ rc_deptree_update(void) deptree = xmalloc(sizeof(*deptree)); TAILQ_INIT(deptree); config = rc_stringlist_new(); - while ((rc_getline(&line, &len, fp))) + while ((getline(&line, &len, fp) > 0)) { depends = line; service = strsep(&depends, " "); diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index 9dfbaec0e..35080451e 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -132,7 +132,7 @@ rc_proc_getent(const char *ent _unused) proc = NULL; i = 0; - if (rc_getline(&proc, &i, fp) == -1 || proc == NULL) + if (getline(&proc, &i, fp) == -1 || proc == NULL) return NULL; if (proc != NULL) { @@ -175,7 +175,7 @@ rc_config_list(const char *file) if (!(fp = fopen(file, "r"))) return list; - while ((rc_getline(&buffer, &len, fp))) { + while ((getline(&buffer, &len, fp) > 0)) { p = buffer; /* Strip leading spaces/tabs */ while ((*p == ' ') || (*p == '\t')) diff --git a/src/librc/librc.c b/src/librc/librc.c index 7802cc413..cd73dced1 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -173,7 +173,7 @@ file_regex(const char *file, const char *regex) return false; } - while ((rc_getline(&line, &len, fp))) { + while ((getline(&line, &len, fp) > 0)) { char *str = line; /* some /proc files have \0 separated content so we have to loop through the 'line' */ @@ -637,7 +637,11 @@ rc_service_extra_commands(const char *service) free(svc); if ((fp = popen(cmd, "r"))) { - rc_getline(&buffer, &len, fp); + if (getline(&buffer, &len, fp) < 0) { + pclose(fp); + free(cmd); + return NULL; + } p = buffer; commands = rc_stringlist_new(); @@ -675,7 +679,11 @@ rc_service_description(const char *service, const char *option) snprintf(cmd, l, DESCSTR, svc, *option ? "_" : "", option); free(svc); if ((fp = popen(cmd, "r"))) { - rc_getline(&desc, &len, fp); + if (getline(&desc, &len, fp) < 0) { + pclose(fp); + free(cmd); + return desc; + } pclose(fp); } free(cmd);