|
@@ -0,0 +1,118 @@
|
|
|
+
|
|
|
+ * sigexec.c
|
|
|
+ *
|
|
|
+ * Programm to execute processes with unblocked signals.
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+#ifdef HAVE_CONFIG_H
|
|
|
+#include "config.h"
|
|
|
+#endif
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <errno.h>
|
|
|
+#include <string.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <signal.h>
|
|
|
+#ifdef HAVE_GETOPT_H
|
|
|
+#include <getopt.h>
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifndef VERSION
|
|
|
+#define VERSION 1.5.6
|
|
|
+#endif
|
|
|
+#define QUOTE(t) #t
|
|
|
+#define version(v) printf("%s\n", v)
|
|
|
+
|
|
|
+static void help(int status, const char *argv0);
|
|
|
+
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ char **child_argv;
|
|
|
+ sigset_t sigs;
|
|
|
+
|
|
|
+ static const char *shortopts = "+hv";
|
|
|
+#ifdef HAVE_GETOPT_H
|
|
|
+ static const struct option longopts[] = {
|
|
|
+ {"help", 0, NULL, 'h'},
|
|
|
+ {"version", 0, NULL, 'v'},
|
|
|
+ {NULL, 0, NULL, 0}
|
|
|
+ };
|
|
|
+#endif
|
|
|
+
|
|
|
+ while(1) {
|
|
|
+ int opt;
|
|
|
+#ifdef HAVE_GETOPT_H
|
|
|
+ opt = getopt_long(argc, argv, shortopts, longopts, NULL);
|
|
|
+#else
|
|
|
+ opt = getopt(argc, argv, shortopts);
|
|
|
+#endif
|
|
|
+ if (-1 == opt)
|
|
|
+ break;
|
|
|
+ switch (opt) {
|
|
|
+ case 0:
|
|
|
+ break;
|
|
|
+ case 'h':
|
|
|
+ help(0, argv[0]);
|
|
|
+ exit(0);
|
|
|
+ break;
|
|
|
+ case 'v':
|
|
|
+ version(VERSION);
|
|
|
+ exit(0);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ help(1, argv[0]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ child_argv = &argv[optind];
|
|
|
+
|
|
|
+ if (! child_argv[0]) {
|
|
|
+ fprintf(stderr, "Error: Nothing to execute.\n");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sigemptyset(&sigs);
|
|
|
+ sigprocmask(SIG_BLOCK, &sigs, NULL);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (execvp(child_argv[0], child_argv) < 0) {
|
|
|
+ fprintf(stderr, "Error: Cannot execute %s: %s\n",
|
|
|
+ child_argv[0], strerror(errno));
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+static void help(int status, const char *argv0)
|
|
|
+{
|
|
|
+ const char *name = NULL;
|
|
|
+
|
|
|
+ if (!argv0)
|
|
|
+ return;
|
|
|
+
|
|
|
+
|
|
|
+ name = strrchr(argv0, '/');
|
|
|
+ if (name)
|
|
|
+ name++;
|
|
|
+ else
|
|
|
+ name = argv0;
|
|
|
+
|
|
|
+ if (status != 0) {
|
|
|
+ fprintf(stderr, "Try `%s -h' for more information.\n",
|
|
|
+ name);
|
|
|
+ } else {
|
|
|
+ printf("Usage: %s [options] -- <command to execute>\n", name);
|
|
|
+ printf("Utility to execute process with unblocked signals.\n");
|
|
|
+ printf("Options:\n");
|
|
|
+ printf("\t-v, --version\tPrint utility version.\n");
|
|
|
+ printf("\t-h, --help\tPrint this help.\n");
|
|
|
+ }
|
|
|
+}
|