luaa: split spawn() into spawn.c
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
16606c6744
commit
cbf55449a3
|
@ -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
|
||||
|
|
59
luaa.c
59
luaa.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* lua.c - Lua configuration management
|
||||
* luaa.c - Lua configuration management
|
||||
*
|
||||
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
||||
*
|
||||
|
@ -25,9 +25,6 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <ev.h>
|
||||
|
@ -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
|
||||
|
|
4
luaa.h
4
luaa.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* lua.h - Lua configuration management header
|
||||
* luaa.h - Lua configuration management header
|
||||
*
|
||||
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
||||
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* spawn.c - Lua configuration management
|
||||
*
|
||||
* Copyright © 2009 Julien Danjou <julien@danjou.info>
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#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
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* spawn.h - Lua configuration management header
|
||||
*
|
||||
* Copyright © 2009 Julien Danjou <julien@danjou.info>
|
||||
*
|
||||
* 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 <lua.h>
|
||||
|
||||
int luaA_spawn(lua_State *);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
Loading…
Reference in New Issue