From b0ab2d419370b727d9151baf9b5ff606dbe74564 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 8 Sep 2008 01:45:22 +0200 Subject: [PATCH] util: fix a_exec, use it for spawn Signed-off-by: Julien Danjou --- common/util.c | 17 ++++------------- lua.c | 8 ++------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/common/util.c b/common/util.c index 4a0d6f64b..f00d76148 100644 --- a/common/util.c +++ b/common/util.c @@ -194,21 +194,12 @@ a_strcpy(char *dst, ssize_t n, const char *src) void a_exec(const char *cmd) { - char *args, *path; + static const char *shell = NULL; - /* Ignore the leading spaces if any */ - while(cmd[0] && cmd[0] == ' ') cmd++; + if(!shell && !(shell = getenv("SHELL"))) + shell = "/bin/sh"; - /* Get the beginning of the arguments */ - args = strchr(cmd, ' '); - if(args) - path = a_strndup(cmd, args - cmd); - else - path = a_strndup(cmd, a_strlen(cmd)); - - execlp(path, cmd, NULL); - - p_delete(&path); + execl(shell, shell, "-c", cmd, NULL); } /** Split a string in substring. diff --git a/lua.c b/lua.c index 8fc6ab65b..0e49393a6 100644 --- a/lua.c +++ b/lua.c @@ -478,14 +478,10 @@ luaA_otable_newindex(lua_State *L) static int luaA_spawn(lua_State *L) { - static const char *shell = NULL; char *host, newdisplay[128]; const char *cmd; int screen = 0, screenp, displayp; - if(!shell && !(shell = getenv("SHELL"))) - shell = "/bin/sh"; - if(lua_gettop(L) == 2) { screen = luaL_checknumber(L, 2) - 1; @@ -511,8 +507,8 @@ luaA_spawn(lua_State *L) if(globalconf.connection) xcb_disconnect(globalconf.connection); setsid(); - execl(shell, shell, "-c", cmd, NULL); - warn("execl '%s -c %s' failed: %s\n", shell, cmd, strerror(errno)); + a_exec(cmd); + warn("execl '%s' failed: %s\n", cmd, strerror(errno)); } exit(EXIT_SUCCESS); }