/* 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; }