From 9beb9331c055cf30e114d99810b8837ce5c7b182 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 29 Jun 2015 00:43:52 -0600 Subject: Start re-jiggering RVS. --- rvs/wrapper/outer.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 rvs/wrapper/outer.c (limited to 'rvs/wrapper/outer.c') 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 . + */ +#include /* for errno */ +#include /* for error(3) */ +#include /* for dgettext(3) */ +#include /* for bindtextdomain(3) and textdomain(3) */ +#include /* for asprintf(3) */ +#include /* for getenv(3), calloc(3) */ +#include /* for mempcy(3) */ +#include /* 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; +} -- cgit v1.2.3