Skip to content

Commit 57a39fd

Browse files
navi-desuwilliamh
authored andcommitted
rc-status: Remove unnecessary checks in print_services().
Every caller of the function already gets a list of services from a valid librc api, and does filtering themselves.
1 parent cadc1d2 commit 57a39fd

1 file changed

Lines changed: 14 additions & 45 deletions

File tree

src/rc-status/rc-status.c

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const char *usagestring = "" \
6969
" or: rc-status [options] [-f ini] [-a | -c | -l | -m | -r | -s | -u]";
7070

7171
static RC_DEPTREE *deptree;
72-
static RC_STRINGLIST *types;
7372

7473
static RC_STRINGLIST *levels, *services, *tmp, *alist;
7574
static RC_STRINGLIST *sservices, *nservices, *needsme;
@@ -201,44 +200,15 @@ static void print_service(const char *service, enum format_t format)
201200
free(status);
202201
}
203202

204-
static void print_services(const char *runlevel, RC_STRINGLIST *svcs,
205-
enum format_t format)
203+
static void print_services(RC_STRINGLIST *svcs, enum format_t format)
206204
{
207-
RC_STRINGLIST *l = NULL;
208-
RC_STRING *s;
209-
char *r = NULL;
205+
RC_STRING *svc;
210206

211207
if (!svcs)
212208
return;
213-
if (!deptree)
214-
deptree = _rc_deptree_load(0, NULL);
215-
if (!deptree) {
216-
TAILQ_FOREACH(s, svcs, entries)
217-
if (!runlevel ||
218-
rc_service_in_runlevel(s->value, runlevel))
219-
print_service(s->value, format);
220-
return;
221-
}
222-
if (!types) {
223-
types = rc_stringlist_new();
224-
rc_stringlist_add(types, "ineed");
225-
rc_stringlist_add(types, "iuse");
226-
rc_stringlist_add(types, "iafter");
227-
}
228-
if (!runlevel)
229-
r = rc_runlevel_get();
230-
l = rc_deptree_depends(deptree, types, svcs, r ? r : runlevel,
231-
RC_DEP_STRICT | RC_DEP_TRACE | RC_DEP_START);
232-
free(r);
233-
if (!l)
234-
return;
235-
TAILQ_FOREACH(s, l, entries) {
236-
if (!rc_stringlist_find(svcs, s->value))
237-
continue;
238-
if (!runlevel || rc_service_in_runlevel(s->value, runlevel))
239-
print_service(s->value, format);
240-
}
241-
rc_stringlist_free(l);
209+
210+
TAILQ_FOREACH(svc, svcs, entries)
211+
print_service(svc->value, format);
242212
}
243213

244214
static void print_stacked_services(const char *runlevel, enum format_t format)
@@ -252,7 +222,7 @@ static void print_stacked_services(const char *runlevel, enum format_t format)
252222
continue;
253223
print_level("Stacked", stackedlevel->value, format);
254224
servicelist = rc_services_in_runlevel(stackedlevel->value);
255-
print_services(stackedlevel->value, servicelist, format);
225+
print_services(servicelist, format);
256226
rc_stringlist_free(servicelist);
257227
}
258228
rc_stringlist_free(stackedlevels);
@@ -319,7 +289,7 @@ int main(int argc, char **argv)
319289
free(s->value);
320290
free(s);
321291
}
322-
print_services(NULL, services, format);
292+
print_services(services, format);
323293
goto exit;
324294
/* NOTREACHED */
325295
case 'r':
@@ -332,12 +302,12 @@ int main(int argc, char **argv)
332302
TAILQ_FOREACH_SAFE(s, services, entries, t)
333303
if (!rc_service_value_get(s->value, "child_pid"))
334304
TAILQ_REMOVE(services, s, entries);
335-
print_services(NULL, services, format);
305+
print_services(services, format);
336306
goto exit;
337307
/* NOTREACHED */
338308
case 's':
339309
services = rc_services_in_runlevel(NULL);
340-
print_services(NULL, services, format);
310+
print_services(services, format);
341311
goto exit;
342312
/* NOTREACHED */
343313
case 'u':
@@ -352,7 +322,7 @@ int main(int argc, char **argv)
352322
break;
353323
}
354324
}
355-
print_services(NULL, services, format);
325+
print_services(services, format);
356326
goto exit;
357327
/* NOTREACHED */
358328

@@ -383,7 +353,7 @@ int main(int argc, char **argv)
383353
TAILQ_FOREACH(l, levels, entries) {
384354
print_level(NULL, l->value, format);
385355
services = rc_services_in_runlevel(l->value);
386-
print_services(l->value, services, format);
356+
print_services(services, format);
387357
print_stacked_services(l->value, format);
388358
rc_stringlist_free(nservices);
389359
nservices = NULL;
@@ -395,7 +365,7 @@ int main(int argc, char **argv)
395365
/* Show hotplugged services */
396366
print_level("Dynamic", "hotplugged", format);
397367
services = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
398-
print_services(NULL, services, format);
368+
print_services(services, format);
399369
rc_stringlist_free(services);
400370
services = NULL;
401371

@@ -454,9 +424,9 @@ int main(int argc, char **argv)
454424
unsetenv("RC_SVCNAME");
455425

456426
print_level("Dynamic", "needed/wanted", format);
457-
print_services(NULL, nservices, format);
427+
print_services(nservices, format);
458428
print_level("Dynamic", "manual", format);
459-
print_services(NULL, services, format);
429+
print_services(services, format);
460430
}
461431

462432
exit:
@@ -466,7 +436,6 @@ int main(int argc, char **argv)
466436
rc_stringlist_free(sservices);
467437
rc_stringlist_free(nservices);
468438
rc_stringlist_free(services);
469-
rc_stringlist_free(types);
470439
rc_stringlist_free(levels);
471440
rc_deptree_free(deptree);
472441

0 commit comments

Comments
 (0)