summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2008-06-03 08:59:46 -0700
committerDan Nicholson <dbn.lists@gmail.com>2008-06-03 08:59:46 -0700
commit15ed6c5ed519865bb9ce1c0974534f8f003b4ff0 (patch)
treeba246d7fdd472345a8a5f14d75b57c2a8dee3069
parentf7934805253c8ab03d6c0490da167ad5e0375694 (diff)
Add install_initd program
Create the executable install_initd for installing services using Linux Standard Base (LSB) headers. It creates symlinks for use in a System-V initialization scheme.
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac1
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am6
-rw-r--r--src/install_initd.c119
5 files changed, 128 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index f51ec12..128d61e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1 @@
-SUBDIRS = lib test
+SUBDIRS = lib src test
diff --git a/configure.ac b/configure.ac
index 19db689..f89b46c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,7 @@ fi
AC_CONFIG_FILES([
Makefile
lib/Makefile
+src/Makefile
test/Makefile
])
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..91951c0
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1 @@
+install_initd
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..364e271
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = -I$(top_srcdir)/lib
+
+sbin_PROGRAMS = install_initd
+
+install_initd_SOURCES = install_initd.c
+install_initd_LDADD = $(top_builddir)/lib/libinitd.la
diff --git a/src/install_initd.c b/src/install_initd.c
new file mode 100644
index 0000000..9650b75
--- /dev/null
+++ b/src/install_initd.c
@@ -0,0 +1,119 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+#include <getopt.h>
+#include "initd.h"
+#include "types.h"
+#include "rdep.h"
+#include "installrm.h"
+
+#ifndef _GNU_SOURCE
+char *program_invocation_name = NULL;
+char *program_invocation_short_name = NULL;
+#endif
+#define PROGNAME "install_initd"
+
+static struct option long_opts[] = {
+ {"directory", 1, NULL, 'd'},
+ {"verbose", 0, NULL, 'v'},
+ {"help", 0, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+};
+
+static void usage(FILE *stream);
+static void set_verbose(void);
+
+int main(int argc, char *argv[])
+{
+ char *id_dir = NULL;
+ initd_list_t *all, *startlist, *stoplist;
+ dep_t *need = dep_new();
+
+ /* parse arguments */
+ while (1) {
+ int optc, index = 0;
+ optc = getopt_long(argc, argv, "d:vh", long_opts, &index);
+
+ if (optc == -1)
+ break;
+
+ switch (optc) {
+ case 'd':
+ id_dir = optarg;
+ break;
+ case 'h':
+ usage(stdout);
+ exit(EXIT_SUCCESS);
+ case 'v':
+ set_verbose();
+ break;
+ case '?':
+ error(EXIT_FAILURE, 0,
+ "Unrecognized option '%c'\n"
+ "See `%s --help' for usage",
+ optopt, program_invocation_name);
+ }
+ }
+
+ if (optind < argc) {
+ while (optind < argc)
+ dep_add(need, argv[optind++]);
+ } else {
+ error(EXIT_FAILURE, 0, "No services supplied\n"
+ "See `%s --help' for usage",
+ program_invocation_name);
+ }
+
+ if (!id_dir)
+ id_dir = DEF_INITD_DIR;
+
+ all = initd_list_from_dir(id_dir);
+
+ startlist = initd_add_recurse_deps(all, SK_START, need);
+ if (!startlist)
+ exit(EXIT_FAILURE);
+
+ stoplist = initd_add_recurse_deps(all, SK_STOP, need);
+ if (!stoplist)
+ exit(EXIT_FAILURE);
+
+ if (!initd_installrm_links(startlist, id_dir, SK_START))
+ exit(EXIT_FAILURE);
+ if (!initd_installrm_links(stoplist, id_dir, SK_STOP))
+ exit(EXIT_FAILURE);
+
+ return 0;
+}
+
+static void usage(FILE *stream)
+{
+ FILE *out;
+
+ if (!stream)
+ out = stdout;
+ if (!program_invocation_name)
+ program_invocation_name = PROGNAME;
+
+ fprintf(stderr,
+ "Usage: %s [OPTION] [SERVICE]...\n"
+ "Install initd SERVICES(s).\n"
+ "\n"
+ " -d, --directory set the service directory\n"
+ " -v, --verbose show the actions being performed\n"
+ " -h, --help show this text and exit\n"
+ "\n"
+ "When an absolute path to SERVICE is not given, it is assumed\n"
+ "to be relative to the default service directory, %s.\n",
+ program_invocation_name,
+ DEF_INITD_DIR);
+}
+
+static void set_verbose(void)
+{
+ initd_recurse_set_verbose(true);
+ initd_installrm_set_verbose(true);
+}