util: fix a_exec, use it for spawn
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
587302358c
commit
b0ab2d4193
|
@ -194,21 +194,12 @@ a_strcpy(char *dst, ssize_t n, const char *src)
|
||||||
void
|
void
|
||||||
a_exec(const char *cmd)
|
a_exec(const char *cmd)
|
||||||
{
|
{
|
||||||
char *args, *path;
|
static const char *shell = NULL;
|
||||||
|
|
||||||
/* Ignore the leading spaces if any */
|
if(!shell && !(shell = getenv("SHELL")))
|
||||||
while(cmd[0] && cmd[0] == ' ') cmd++;
|
shell = "/bin/sh";
|
||||||
|
|
||||||
/* Get the beginning of the arguments */
|
execl(shell, shell, "-c", cmd, NULL);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Split a string in substring.
|
/** Split a string in substring.
|
||||||
|
|
8
lua.c
8
lua.c
|
@ -478,14 +478,10 @@ luaA_otable_newindex(lua_State *L)
|
||||||
static int
|
static int
|
||||||
luaA_spawn(lua_State *L)
|
luaA_spawn(lua_State *L)
|
||||||
{
|
{
|
||||||
static const char *shell = NULL;
|
|
||||||
char *host, newdisplay[128];
|
char *host, newdisplay[128];
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
int screen = 0, screenp, displayp;
|
int screen = 0, screenp, displayp;
|
||||||
|
|
||||||
if(!shell && !(shell = getenv("SHELL")))
|
|
||||||
shell = "/bin/sh";
|
|
||||||
|
|
||||||
if(lua_gettop(L) == 2)
|
if(lua_gettop(L) == 2)
|
||||||
{
|
{
|
||||||
screen = luaL_checknumber(L, 2) - 1;
|
screen = luaL_checknumber(L, 2) - 1;
|
||||||
|
@ -511,8 +507,8 @@ luaA_spawn(lua_State *L)
|
||||||
if(globalconf.connection)
|
if(globalconf.connection)
|
||||||
xcb_disconnect(globalconf.connection);
|
xcb_disconnect(globalconf.connection);
|
||||||
setsid();
|
setsid();
|
||||||
execl(shell, shell, "-c", cmd, NULL);
|
a_exec(cmd);
|
||||||
warn("execl '%s -c %s' failed: %s\n", shell, cmd, strerror(errno));
|
warn("execl '%s' failed: %s\n", cmd, strerror(errno));
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue