spawn: use glib spawn module to catch error
This is a lot better than our previous code. We can now report execution error to Lua directly. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
57aeb2b85e
commit
0705fbf29d
|
@ -135,6 +135,7 @@ pkg_check_modules(AWESOME_COMMON_REQUIRED REQUIRED
|
|||
xcb>=1.1)
|
||||
|
||||
pkg_check_modules(AWESOME_REQUIRED REQUIRED
|
||||
glib-2.0
|
||||
cairo
|
||||
x11
|
||||
pango>=1.19.3
|
||||
|
|
|
@ -242,7 +242,8 @@ globalkeys = awful.util.table.join(
|
|||
function ()
|
||||
awful.prompt.run({ prompt = "Run: " },
|
||||
mypromptbox[mouse.screen],
|
||||
awful.util.spawn, awful.completion.shell,
|
||||
function (...) mypromptbox[mouse.screen].text = awful.util.spawn(unpack(arg)) end,
|
||||
awful.completion.shell,
|
||||
awful.util.getdir("cache") .. "/history")
|
||||
end),
|
||||
|
||||
|
|
27
spawn.c
27
spawn.c
|
@ -24,6 +24,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <glib/gspawn.h>
|
||||
|
||||
#include "spawn.h"
|
||||
#include "screen.h"
|
||||
#include "luaa.h"
|
||||
|
@ -228,6 +230,7 @@ spawn_launchee_timeout(struct ev_loop *loop, ev_timer *w, int revents)
|
|||
* \lparam The command to launch.
|
||||
* \lparam Use startup-notification, true or false, default to true.
|
||||
* \lparam The optional screen number to spawn the command on.
|
||||
* \lreturn Nothing if launch was successful, an error string otherwise.
|
||||
*/
|
||||
int
|
||||
luaA_spawn(lua_State *L)
|
||||
|
@ -256,6 +259,7 @@ luaA_spawn(lua_State *L)
|
|||
p_delete(&host);
|
||||
}
|
||||
|
||||
SnLauncherContext *context = NULL;
|
||||
if(use_sn)
|
||||
{
|
||||
char *cmdname, *space;
|
||||
|
@ -264,7 +268,7 @@ luaA_spawn(lua_State *L)
|
|||
else
|
||||
cmdname = a_strdup(cmd);
|
||||
|
||||
SnLauncherContext *context = sn_launcher_context_new(globalconf.sndisplay, screen_virttophys(screen));
|
||||
context = sn_launcher_context_new(globalconf.sndisplay, screen_virttophys(screen));
|
||||
sn_launcher_context_set_name(context, "awesome");
|
||||
sn_launcher_context_set_description(context, "awesome spawn");
|
||||
sn_launcher_context_set_binary_name(context, cmdname);
|
||||
|
@ -280,21 +284,16 @@ luaA_spawn(lua_State *L)
|
|||
sn_launcher_context_setup_child_process(context);
|
||||
}
|
||||
|
||||
/* The double-fork construct avoids zombie processes and keeps the code
|
||||
* clean from stupid signal handlers. */
|
||||
if(fork() == 0)
|
||||
GError *error = NULL;
|
||||
if(!g_spawn_command_line_async(cmd, &error))
|
||||
{
|
||||
if(fork() == 0)
|
||||
{
|
||||
if(globalconf.connection)
|
||||
xcb_disconnect(globalconf.connection);
|
||||
setsid();
|
||||
a_exec(cmd);
|
||||
warn("execl '%s' failed: %s\n", cmd, strerror(errno));
|
||||
/* push error on stack */
|
||||
lua_pushstring(L, error->message);
|
||||
g_error_free(error);
|
||||
if(context)
|
||||
sn_launcher_context_complete(context);
|
||||
return 1;
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
wait(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue