From d31b7666a1919ecf1c2581f68e3883a0e9a18cce 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 e7d86626e..0932970c1 100644 --- a/spawn.c +++ b/spawn.c @@ -374,4 +374,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 6ebbdd8b6..d4a585460 100644 --- a/spawn.h +++ b/spawn.h @@ -28,5 +28,7 @@ void spawn_init(void); void spawn_start_notify(client_t *, const char *); 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