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 OpenRC#278.
  • Loading branch information
williamh committed Dec 24, 2018
1 parent 084877e commit f181d0c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/librc/librc-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
fp = fopen("/proc/self/status", "r");
if (fp) {
while (! feof(fp)) {
rc_getline(&line, &len, fp);
if (getline(&line, &len, fp) <= 0)
break;
if (strncmp(line, "envID:\t0", 8) == 0) {
openvz_host = true;
break;
Expand Down Expand Up @@ -190,7 +191,8 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
if (! fp)
continue;
while (! feof(fp)) {
rc_getline(&line, &len, 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 @@ -341,7 +343,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 @@ -546,7 +548,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 @@ -127,7 +127,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 @@ -779,7 +779,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 @@ -134,7 +134,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 @@ -178,7 +178,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 @@ -175,7 +175,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 @@ -650,7 +650,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 @@ -689,7 +693,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 f181d0c

Please sign in to comment.