diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-22 17:46:57 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-22 17:46:57 -0700 |
commit | 2ecf19e1ece03ee3f8bde6b5d7d9acbdc40bc597 (patch) | |
tree | 9bb7ac39c5f3422d9e820137bcd8eb21bf1d0374 /test | |
parent | a598f15bf36eb346a08c9580c91f84501fb2d0d5 (diff) |
Add test case for removing init.d scripts
Test the functionality of removing an active script. Remove definitely
has some bugs, but the test case is sane.
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/tremove.c | 78 |
3 files changed, 83 insertions, 2 deletions
diff --git a/test/.gitignore b/test/.gitignore index dbc2fb3..d43442d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -10,4 +10,5 @@ tadd-deps1 tadd-deps2 trem-deps tinstall +tremove rc?.d diff --git a/test/Makefile.am b/test/Makefile.am index ad8afd4..2862eee 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 \ - tadd-deps1 tadd-deps2 trem-deps tinstall + tadd-deps1 tadd-deps2 trem-deps tinstall tremove check_PROGRAMS = tstr tstrarg tdep tparse tparse-dir tinitd tinitd-list \ - tactive tadd-deps1 tadd-deps2 trem-deps tinstall + tactive tadd-deps1 tadd-deps2 trem-deps tinstall tremove tstr_SOURCES = tstr.c tstr_LDADD = $(top_builddir)/lib/libinitd.la @@ -34,6 +34,8 @@ trem_deps_SOURCES = trem-deps.c trem_deps_LDADD = $(top_builddir)/lib/libinitd.la tinstall_SOURCES = tinstall.c tinstall_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..18c1963 --- /dev/null +++ b/test/tremove.c @@ -0,0 +1,78 @@ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <stdio.h> +#include "initd.h" +#include "types.h" +#include "rdep.h" +#include "installrm.h" + +static void print_sk_list(const initd_list_t *list, initd_sk_t sk); + +int main(int argc, char *argv[]) +{ + initd_list_t *all, *startlist, *stoplist; + dep_t *rem = dep_new(); + + if (argc <= 1) + dep_add(rem, "mountfs"); + + while (argc > 1) { + dep_add(rem, argv[1]); + argv++; + argc--; + } + + all = initd_list_from_dir("init.d"); + + initd_recurse_set_verbose(true); + initd_installrm_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; + } + + initd_installrm_links(startlist, "init.d", SK_START); + initd_installrm_links(stoplist, "init.d", SK_STOP); + + 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\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); + } +} |