Skip to content

Commit

Permalink
Convert internal rc_getline() calls to getline() calls
Browse files Browse the repository at this point in the history
getline has been in posix since POSIX.1-2008, so it should be safe for
us to use it instead of using our wrapper function.

This fixes #278.
  • Loading branch information
williamh committed Jan 27, 2022
1 parent e6d48ea commit 3b10265
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/librc/librc-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/librc/librc-depend.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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, "_");
Expand Down Expand Up @@ -773,7 +773,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, " ");
Expand Down
4 changes: 2 additions & 2 deletions src/librc/librc-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'))
Expand Down
14 changes: 11 additions & 3 deletions src/librc/librc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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' */
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3b10265

Please sign in to comment.