util: fix a_exec, use it for spawn

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-09-08 01:45:22 +02:00
parent 587302358c
commit b0ab2d4193
2 changed files with 6 additions and 19 deletions

View file

@ -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.

8
lua.c
View file

@ -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);
}