summaryrefslogtreecommitdiff
path: root/rvs/wrapper/outer.c
diff options
context:
space:
mode:
Diffstat (limited to 'rvs/wrapper/outer.c')
-rw-r--r--rvs/wrapper/outer.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/rvs/wrapper/outer.c b/rvs/wrapper/outer.c
new file mode 100644
index 0000000..4bc2d2f
--- /dev/null
+++ b/rvs/wrapper/outer.c
@@ -0,0 +1,63 @@
+/* RVS outer.c - A wrapper for $(bindir) to call the main RVS program
+ * Copyright (C) 2015 Luke Shumaker
+ *
+ * This file is part of rvs.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <errno.h> /* for errno */
+#include <error.h> /* for error(3) */
+#include <libintl.h> /* for dgettext(3) */
+#include <locale.h> /* for bindtextdomain(3) and textdomain(3) */
+#include <stdio.h> /* for asprintf(3) */
+#include <stdlib.h> /* for getenv(3), calloc(3) */
+#include <string.h> /* for mempcy(3) */
+#include <unistd.h> /* for execv(3) */
+
+#include "config.h"
+#define _ gettext
+
+#define EXIT_FAILURE_OOM 126
+#define EXIT_FAILURE_EXEC 127
+
+int
+main(int argc, char *argv[]) {
+ bindtextdomain(pkgtextdomain, localedir);
+ textdomain(pkgtextdomain);
+
+ unsetenv("ENV");
+ unsetenv("BASH_ENV");
+
+ const char *varname = PACKAGE_UPPER "_EXEC_PATH";
+
+ char *exec_path = getenv(varname);
+ if (!exec_path)
+ exec_path = pkglibexecdir;
+
+ char *exec_file = NULL;
+ if (asprintf(&exec_file, "%s/" PACKAGE, exec_path) < 0)
+ error(EXIT_FAILURE_OOM, errno,
+ _("Could not allocate memory for string"));
+
+ char **args = calloc(argc+2, sizeof(char*));
+ if (!args)
+ error(EXIT_FAILURE_OOM, errno,
+ _("Could not allocate cleared memory"));
+ args[0] = exec_file;
+ memcpy(&args[1], argv, sizeof(char*) * argc);
+
+ execv(exec_file, args);
+ error(EXIT_FAILURE_EXEC, errno, _("Could not execute: %s"), exec_file);
+ return EXIT_FAILURE_EXEC;
+}