diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-02 10:40:48 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-02 10:40:48 -0700 |
commit | 8855d447e2fc734b84bbf65d76b910863c0037fd (patch) | |
tree | 5b7c4ffcc5103c46c452f2b2ab87a843cdcb9f12 /test | |
parent | 657c850522263c5ab204ff9a8378b7092a89b25f (diff) |
rdep: Recurse and verify dependencies when removing
Added a new function, initd_remove_recurse_deps, which verifies that the
dependencies of the active services are still valid if specified
services are removed. There is a bit of hackery to play with the active
flags of the to-be-removed services and then restoring them.
A new test program, tremove, has been added to exercise this function.
It is basically the compliment to tverify (should be tinstall).
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/tremove.c | 102 |
3 files changed, 107 insertions, 2 deletions
diff --git a/test/.gitignore b/test/.gitignore index b28e94b..df00b44 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -8,4 +8,5 @@ tparse tparse-dir trdeps tverify +tremove rc?.d diff --git a/test/Makefile.am b/test/Makefile.am index a335c39..cef5738 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,9 +6,9 @@ testscripts = init.d/bar init.d/foo init.d/barf init.d/dual-headers \ EXTRA_DIST = $(runtestscripts) $(testscripts) TESTS = tstr tstrarg tdep $(runtestscripts) tinitd tinitd-list tactive \ - trdeps tverify + trdeps tverify tremove check_PROGRAMS = tstr tstrarg tdep tparse tparse-dir tinitd tinitd-list \ - tactive trdeps tverify + tactive trdeps tverify tremove tstr_SOURCES = tstr.c tstr_LDADD = $(top_builddir)/lib/libinitd.la @@ -30,6 +30,8 @@ trdeps_SOURCES = trdeps.c trdeps_LDADD = $(top_builddir)/lib/libinitd.la tverify_SOURCES = tverify.c tverify_LDADD = $(top_builddir)/lib/libinitd.la +tremove_SOURCES = tremove.c +tremove_LDADD = $(top_builddir)/lib/libinitd.la rctestdirs = rcS.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d testmountfslinks = rcS.d/S10mountfs rc0.d/K90mountfs rc6.d/K90mountfs diff --git a/test/tremove.c b/test/tremove.c new file mode 100644 index 0000000..127d0be --- /dev/null +++ b/test/tremove.c @@ -0,0 +1,102 @@ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <stdio.h> +#include "initd.h" +#include "types.h" +#include "rdep.h" + +static void print_sk_list(const initd_list_t *list, initd_sk_t sk); +static bool check_scripts_active(const initd_list_t *list, dep_t *scripts); + +int main(int argc, char *argv[]) +{ + initd_list_t *all, *startlist, *stoplist; + dep_t *rem = dep_new(); + + if (argc <= 1) + dep_add(rem, "network"); + + while (argc > 1) { + dep_add(rem, argv[1]); + argv++; + argc--; + } + + all = initd_list_from_dir("init.d"); + + if (!check_scripts_active(all, rem)) + return 1; + + initd_recurse_set_verbose(true); + startlist = initd_remove_recurse_deps(all, SK_START, rem); + if (startlist) { + print_sk_list(startlist, SK_START); + } else { + fprintf(stderr, "Failed recursing start scripts\n"); + return 1; + } + + stoplist = initd_remove_recurse_deps(all, SK_STOP, rem); + if (stoplist) { + print_sk_list(stoplist, SK_STOP); + } else { + fprintf(stderr, "Failed recursing stop scripts\n"); + return 1; + } + + if (!check_scripts_active(all, rem)) + return 1; + + return 0; +} + +static void print_sk_list(const initd_list_t *list, initd_sk_t sk) +{ + char *startstop; + initd_t *ip; + + switch (sk) { + case SK_START: + startstop = "start"; + break; + case SK_STOP: + startstop = "stop"; + break; + default: + startstop = ""; + } + + if (list) { + printf("All deps for %s after removal\n", startstop); + printf("Ordered:"); + for (ip = list->first; ip; ip = ip->next) + printf(" %s", ip->name); + printf("\n"); + } else { + printf("%s list is empty\n", startstop); + } +} + +static bool check_scripts_active(const initd_list_t *list, dep_t *scripts) +{ + int n; + initd_t *ip; + + /* Check that all the requested scripts are active */ + for (n = 0; n < dep_get_num(scripts); n++) { + ip = initd_list_find_name(list, dep_get_dep(scripts, n)); + if (!ip) { + fprintf(stderr, "No script named %s\n", + dep_get_dep(scripts, n)); + return false; + } + if (!(ip->astart & RC_ALL) || !(ip->astop & RC_ALL)) { + fprintf(stderr, "Script %s is not active\n", + ip->name); + return false; + } + } + + return true; +} |