From 34d37c00c8c8aa3b5fd63456375c3e798d713fda Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 25 Aug 2009 21:40:49 +0200 Subject: [PATCH] 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 Signed-off-by: Julien Danjou --- spawn.c | 25 +++++++++++++++++++++++++ spawn.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/spawn.c b/spawn.c index 65ce96945..59faa77c5 100644 --- a/spawn.c +++ b/spawn.c @@ -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 diff --git a/spawn.h b/spawn.h index 7318acf05..cadacc3e0 100644 --- a/spawn.h +++ b/spawn.h @@ -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