spawn: add spawn_system() which works like system()

This adds a small function which behaves exactly like libc's system(), but also
clears the masked signal set in the child process.

This is needed because libev 3.8 masks signals. :(

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Uli Schlachter 2009-08-25 21:40:49 +02:00 committed by Julien Danjou
parent 42fe7f7949
commit 34d37c00c8
2 changed files with 27 additions and 0 deletions

25
spawn.c
View File

@ -358,4 +358,29 @@ luaA_spawn(lua_State *L)
return 0;
}
/** Spawn a program. This works exactly as system() does, but clears the signal mask.
* \param arg The shell command to execute.
* \return The return status of the program.
*/
int
spawn_system(const char *arg)
{
GError *error;
gboolean retval;
gint status;
static const char *shell = NULL;
if(!shell && !(shell = getenv("SHELL")))
shell = "/bin/sh";
char *argv[] = { (char *) shell, (char *) "-c", (char *) arg, NULL };
retval = g_spawn_sync(NULL, argv, NULL, 0, spawn_child_callback,
NULL, NULL, NULL, &status, &error);
if (retval)
return status;
g_error_free(error);
return -1;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -28,5 +28,7 @@ void spawn_init(void);
void spawn_start_notify(client_t *);
int luaA_spawn(lua_State *);
int spawn_system(const char *);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80