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:
parent
7e2291ec37
commit
2f739a5326
19
spawn.c
19
spawn.c
|
@ -276,20 +276,23 @@ spawn_child_callback(gpointer user_data)
|
||||||
* g_spawn_async.
|
* g_spawn_async.
|
||||||
* \return g_spawn_async value.
|
* \return g_spawn_async value.
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static GPid
|
||||||
spawn_command(const gchar *command_line, GError **error)
|
spawn_command(const gchar *command_line, GError **error)
|
||||||
{
|
{
|
||||||
gboolean retval;
|
gboolean retval;
|
||||||
|
GPid pid;
|
||||||
gchar **argv = 0;
|
gchar **argv = 0;
|
||||||
|
|
||||||
if(!g_shell_parse_argv(command_line, NULL, &argv, error))
|
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,
|
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);
|
g_strfreev (argv);
|
||||||
|
|
||||||
return retval;
|
if (!retval)
|
||||||
|
return 0;
|
||||||
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Spawn a program.
|
/** Spawn a program.
|
||||||
|
@ -361,7 +364,8 @@ luaA_spawn(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
if(!spawn_command(cmd, &error))
|
GPid pid = spawn_command(cmd, &error);
|
||||||
|
if(!pid)
|
||||||
{
|
{
|
||||||
/* push error on stack */
|
/* push error on stack */
|
||||||
lua_pushstring(L, error->message);
|
lua_pushstring(L, error->message);
|
||||||
|
@ -371,7 +375,10 @@ luaA_spawn(lua_State *L)
|
||||||
return 1;
|
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.
|
/** Spawn a program. This works exactly as system() does, but clears the signal mask.
|
||||||
|
|
Loading…
Reference in New Issue