From cbf55449a32899be314f7b48bfc481530532a368 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 3 Apr 2009 13:09:17 +0200 Subject: [PATCH] luaa: split spawn() into spawn.c Signed-off-by: Julien Danjou --- CMakeLists.txt | 1 + luaa.c | 59 +++-------------------------------- luaa.h | 4 +-- spawn.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ spawn.h | 30 ++++++++++++++++++ 5 files changed, 121 insertions(+), 57 deletions(-) create mode 100644 spawn.c create mode 100644 spawn.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 903dcdaad..d28aeded3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set(AWE_SRCS ${SOURCE_DIR}/mousegrabber.c ${SOURCE_DIR}/layout.c ${SOURCE_DIR}/luaa.c + ${SOURCE_DIR}/spawn.c ${SOURCE_DIR}/hooks.c ${SOURCE_DIR}/mouse.c ${SOURCE_DIR}/screen.c diff --git a/luaa.c b/luaa.c index 9ee238b46..1e11c33a4 100644 --- a/luaa.c +++ b/luaa.c @@ -1,5 +1,5 @@ /* - * lua.c - Lua configuration management + * luaa.c - Lua configuration management * * Copyright © 2008-2009 Julien Danjou * @@ -25,9 +25,6 @@ #include #include #include -#include -#include -#include #include #include @@ -43,6 +40,7 @@ #include "ewmh.h" #include "config.h" #include "luaa.h" +#include "spawn.h" #include "tag.h" #include "client.h" #include "screen.h" @@ -618,57 +616,6 @@ luaA_isloop(lua_State *L, int idx) return !ret; } -/** Spawn a program. - * This function is multi-head (Zaphod) aware and will set display to - * the right screen according to mouse position. - * \param L The Lua VM state. - * \return The number of elements pushed on stack - * \luastack - * \lparam The command to launch. - * \lparam The optional screen number to spawn the command on. - */ -static int -luaA_spawn(lua_State *L) -{ - char *host, newdisplay[128]; - const char *cmd; - int screen = 0, screenp, displayp; - - if(lua_gettop(L) == 2) - { - screen = luaL_checknumber(L, 2) - 1; - luaA_checkscreen(screen); - } - - cmd = luaL_checkstring(L, 1); - - if(!globalconf.xinerama_is_active) - { - xcb_parse_display(NULL, &host, &displayp, &screenp); - snprintf(newdisplay, sizeof(newdisplay), "%s:%d.%d", host, displayp, screen); - setenv("DISPLAY", newdisplay, 1); - p_delete(&host); - } - - /* The double-fork construct avoids zombie processes and keeps the code - * clean from stupid signal handlers. */ - if(fork() == 0) - { - if(fork() == 0) - { - if(globalconf.connection) - xcb_disconnect(globalconf.connection); - setsid(); - a_exec(cmd); - warn("execl '%s' failed: %s\n", cmd, strerror(errno)); - } - exit(EXIT_SUCCESS); - } - wait(0); - - return 0; -} - /** awesome global table. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -1210,3 +1157,5 @@ luaA_pushcolor(lua_State *L, const xcolor_t *c) lua_pushlstring(L, s, len); return 1; } + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/luaa.h b/luaa.h index c4d2a65ce..e4ddd125d 100644 --- a/luaa.h +++ b/luaa.h @@ -1,7 +1,7 @@ /* - * lua.h - Lua configuration management header + * luaa.h - Lua configuration management header * - * Copyright © 2008 Julien Danjou + * Copyright © 2008-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/spawn.c b/spawn.c new file mode 100644 index 000000000..27ac25c97 --- /dev/null +++ b/spawn.c @@ -0,0 +1,84 @@ +/* + * spawn.c - Lua configuration management + * + * Copyright © 2009 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include +#include + +#include "structs.h" +#include "spawn.h" +#include "luaa.h" + +extern awesome_t globalconf; + +/** Spawn a program. + * This function is multi-head (Zaphod) aware and will set display to + * the right screen according to mouse position. + * \param L The Lua VM state. + * \return The number of elements pushed on stack + * \luastack + * \lparam The command to launch. + * \lparam The optional screen number to spawn the command on. + */ +int +luaA_spawn(lua_State *L) +{ + char *host, newdisplay[128]; + const char *cmd; + int screen = 0, screenp, displayp; + + if(lua_gettop(L) == 2) + { + screen = luaL_checknumber(L, 2) - 1; + luaA_checkscreen(screen); + } + + cmd = luaL_checkstring(L, 1); + + if(!globalconf.xinerama_is_active) + { + xcb_parse_display(NULL, &host, &displayp, &screenp); + snprintf(newdisplay, sizeof(newdisplay), "%s:%d.%d", host, displayp, screen); + setenv("DISPLAY", newdisplay, 1); + p_delete(&host); + } + + /* The double-fork construct avoids zombie processes and keeps the code + * clean from stupid signal handlers. */ + if(fork() == 0) + { + if(fork() == 0) + { + if(globalconf.connection) + xcb_disconnect(globalconf.connection); + setsid(); + a_exec(cmd); + warn("execl '%s' failed: %s\n", cmd, strerror(errno)); + } + exit(EXIT_SUCCESS); + } + wait(0); + + return 0; +} + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/spawn.h b/spawn.h new file mode 100644 index 000000000..20e35f18c --- /dev/null +++ b/spawn.h @@ -0,0 +1,30 @@ +/* + * spawn.h - Lua configuration management header + * + * Copyright © 2009 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_SPAWN_H +#define AWESOME_SPAWN_H + +#include + +int luaA_spawn(lua_State *); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80