awesome.spawn(): Return the PID

This modifies awesome.spawn() to return the process ID of the started process
which could e.g. be used for matching against _NET_WM_PID.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-04-24 11:49:57 +02:00
parent 7e2291ec37
commit 2f739a5326
1 changed files with 13 additions and 6 deletions

19
spawn.c
View File

@ -276,20 +276,23 @@ spawn_child_callback(gpointer user_data)
* g_spawn_async.
* \return g_spawn_async value.
*/
static gboolean
static GPid
spawn_command(const gchar *command_line, GError **error)
{
gboolean retval;
GPid pid;
gchar **argv = 0;
if(!g_shell_parse_argv(command_line, NULL, &argv, error))
return FALSE;
return 0;
retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
spawn_child_callback, NULL, NULL, error);
spawn_child_callback, NULL, &pid, error);
g_strfreev (argv);
return retval;
if (!retval)
return 0;
return pid;
}
/** Spawn a program.
@ -361,7 +364,8 @@ luaA_spawn(lua_State *L)
}
GError *error = NULL;
if(!spawn_command(cmd, &error))
GPid pid = spawn_command(cmd, &error);
if(!pid)
{
/* push error on stack */
lua_pushstring(L, error->message);
@ -371,7 +375,10 @@ luaA_spawn(lua_State *L)
return 1;
}
return 0;
/* push pid on stack */
lua_pushnumber(L, pid);
return 1;
}
/** Spawn a program. This works exactly as system() does, but clears the signal mask.