awful.widget.taglist: remove needless taglist_squares conditions
[awesome.git] / spawn.c
bloba15b6952e95ba6c2c7a24e7f10ec8443490957b0
1 /*
2 * spawn.c - Lua configuration management
4 * Copyright © 2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <unistd.h>
23 #include <errno.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
27 #include "structs.h"
28 #include "spawn.h"
29 #include "luaa.h"
31 /** Spawn a program.
32 * This function is multi-head (Zaphod) aware and will set display to
33 * the right screen according to mouse position.
34 * \param L The Lua VM state.
35 * \return The number of elements pushed on stack
36 * \luastack
37 * \lparam The command to launch.
38 * \lparam The optional screen number to spawn the command on.
40 int
41 luaA_spawn(lua_State *L)
43 char *host, newdisplay[128];
44 const char *cmd;
45 int screen = 0, screenp, displayp;
47 if(lua_gettop(L) == 2)
49 screen = luaL_checknumber(L, 2) - 1;
50 luaA_checkscreen(screen);
53 cmd = luaL_checkstring(L, 1);
55 if(!globalconf.xinerama_is_active)
57 xcb_parse_display(NULL, &host, &displayp, &screenp);
58 snprintf(newdisplay, sizeof(newdisplay), "%s:%d.%d", host, displayp, screen);
59 setenv("DISPLAY", newdisplay, 1);
60 p_delete(&host);
63 /* The double-fork construct avoids zombie processes and keeps the code
64 * clean from stupid signal handlers. */
65 if(fork() == 0)
67 if(fork() == 0)
69 if(globalconf.connection)
70 xcb_disconnect(globalconf.connection);
71 setsid();
72 a_exec(cmd);
73 warn("execl '%s' failed: %s\n", cmd, strerror(errno));
75 exit(EXIT_SUCCESS);
77 wait(0);
79 return 0;
82 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80