X Tutup
Skip to content

Commit e393eff

Browse files
committed
sysv-generator: FOREACH_LINE excorcism
1 parent 050ca29 commit e393eff

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/sysv-generator/sysv-generator.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <unistd.h>
66

77
#include "alloc-util.h"
8+
#include "def.h"
89
#include "dirent-util.h"
910
#include "exit-status.h"
1011
#include "fd-util.h"
@@ -432,7 +433,6 @@ static int load_sysv(SysvStub *s) {
432433
_cleanup_free_ char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL;
433434
char *description;
434435
bool supports_reload = false;
435-
char l[LINE_MAX];
436436

437437
assert(s);
438438

@@ -446,17 +446,24 @@ static int load_sysv(SysvStub *s) {
446446

447447
log_debug("Loading SysV script %s", s->path);
448448

449-
FOREACH_LINE(l, f, goto fail) {
449+
for (;;) {
450+
_cleanup_free_ char *l = NULL;
450451
char *t;
451452

453+
r = read_line(f, LONG_LINE_MAX, &l);
454+
if (r < 0)
455+
return log_error_errno(r, "Failed to read configuration file '%s': %m", s->path);
456+
if (r == 0)
457+
break;
458+
452459
line++;
453460

454461
t = strstrip(l);
455462
if (*t != '#') {
456463
/* Try to figure out whether this init script supports
457464
* the reload operation. This heuristic looks for
458465
* "Usage" lines which include the reload option. */
459-
if ( state == USAGE_CONTINUATION ||
466+
if (state == USAGE_CONTINUATION ||
460467
(state == NORMAL && strcasestr(t, "usage"))) {
461468
if (usage_contains_reload(t)) {
462469
supports_reload = true;
@@ -644,9 +651,6 @@ static int load_sysv(SysvStub *s) {
644651

645652
s->loaded = true;
646653
return 0;
647-
648-
fail:
649-
return log_error_errno(errno, "Failed to read configuration file '%s': %m", s->path);
650654
}
651655

652656
static int fix_order(SysvStub *s, Hashmap *all_services) {

0 commit comments

Comments
 (0)
X Tutup