diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-22 09:02:44 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-22 09:10:44 -0700 |
commit | c136a3765efc354080aee77a7a8c64bdccadc0e4 (patch) | |
tree | 2f01d89a4b631faf8251e1402f5b831b6125d441 /test | |
parent | 11920a5b64435f869aa920f33c135b7920a4df99 (diff) |
Add functions for installing and removing init.d symlinks
This adds the initd_installrm_links function and its helpers for
installing and removing symlinks. The function takes an ordered start or
kill list and the init.d directory to operate on. There is just a single
entry point since the determination of removal or addition is done in
the dependency ordering.
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/tinstall.c | 78 |
3 files changed, 83 insertions, 2 deletions
diff --git a/test/.gitignore b/test/.gitignore index df00b44..9917b29 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -9,4 +9,5 @@ tparse-dir trdeps tverify tremove +tinstall rc?.d diff --git a/test/Makefile.am b/test/Makefile.am index cef5738..1c7230a 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 tremove + trdeps tverify tremove tinstall check_PROGRAMS = tstr tstrarg tdep tparse tparse-dir tinitd tinitd-list \ - tactive trdeps tverify tremove + tactive trdeps tverify tremove tinstall tstr_SOURCES = tstr.c tstr_LDADD = $(top_builddir)/lib/libinitd.la @@ -32,6 +32,8 @@ tverify_SOURCES = tverify.c tverify_LDADD = $(top_builddir)/lib/libinitd.la tremove_SOURCES = tremove.c tremove_LDADD = $(top_builddir)/lib/libinitd.la +tinstall_SOURCES = tinstall.c +tinstall_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/tinstall.c b/test/tinstall.c new file mode 100644 index 0000000..21a458a --- /dev/null +++ b/test/tinstall.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 *need = dep_new(); + + if (argc <= 1) + dep_add(need, "foo"); + + while (argc > 1) { + dep_add(need, argv[1]); + argv++; + argc--; + } + + all = initd_list_from_dir("init.d"); + + initd_recurse_set_verbose(true); + initd_installrm_set_verbose(true); + + startlist = initd_add_recurse_deps(all, SK_START, need); + if (startlist) { + print_sk_list(startlist, SK_START); + } else { + fprintf(stderr, "Failed recursing start scripts\n"); + return 1; + } + + stoplist = initd_add_recurse_deps(all, SK_STOP, need); + 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); + } +} |