From a899a46664d1267b488cf361aa10345d1735776e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 31 Mar 2015 01:17:45 +0200 Subject: [PATCH] Set &error in parse_command, return it from luaA_spawn In case of parse errors from `g_shell_parse_argv`, this now gets returned by `luaA_spawn`. --- spawn.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spawn.c b/spawn.c index 1da89f5e..37dd3ba5 100644 --- a/spawn.c +++ b/spawn.c @@ -264,7 +264,7 @@ spawn_callback(gpointer user_data) * \return The argv array for the new process. */ static gchar ** -parse_command(lua_State *L, int idx) +parse_command(lua_State *L, int idx, GError **error) { gchar **argv = NULL; idx = luaA_absindex(L, idx); @@ -272,7 +272,7 @@ parse_command(lua_State *L, int idx) if (lua_isstring(L, idx)) { const char *cmd = luaL_checkstring(L, idx); - if(!g_shell_parse_argv(cmd, NULL, &argv, NULL)) + if(!g_shell_parse_argv(cmd, NULL, &argv, error)) return NULL; } else if (lua_istable(L, idx)) @@ -328,11 +328,15 @@ luaA_spawn(lua_State *L) if(lua_gettop(L) >= 2) use_sn = luaA_checkboolean(L, 2); - argv = parse_command(L, 1); + GError *error = NULL; + argv = parse_command(L, 1, &error); if(!argv || !argv[0]) { g_strfreev(argv); - return 0; + /* push error on stack */ + lua_pushfstring(L, "spawn: parse error: %s", error->message); + g_error_free(error); + return 1; } SnLauncherContext *context = NULL; @@ -350,7 +354,6 @@ luaA_spawn(lua_State *L) sn_launcher_context_setup_child_process(context); } - GError *error = NULL; retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, spawn_callback, NULL, &pid, &error); g_strfreev(argv);