X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fmain.c;h=7738dacc12e1e6725e975cce0446dd97fa5f6fde;hb=36a1a8282f99bbfd905d97b44a091a37f768bf88;hp=45cb162c42599d1551730c59622f84a7212b1762;hpb=f7a73f4a6871244d546f6cd8e0295e5666185758;p=i3%2Fi3 diff --git a/src/main.c b/src/main.c index 45cb162c..7738dacc 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE) * * main.c: Initialization, main loop * @@ -28,6 +28,9 @@ struct rlimit original_rlimit_core; /* Whether this version of i3 is a debug build or a release build. */ bool debug_build = false; +/** The number of file descriptors passed via socket activation. */ +int listen_fds; + static int xkb_event_base; int xkb_current_group; @@ -335,7 +338,7 @@ int main(int argc, char *argv[]) { break; } else if (strcmp(long_options[option_index].name, "get-socketpath") == 0 || strcmp(long_options[option_index].name, "get_socketpath") == 0) { - char *socket_path = socket_path_from_x11(); + char *socket_path = root_atom_contents("I3_SOCKET_PATH"); if (socket_path) { printf("%s\n", socket_path); return 0; @@ -416,7 +419,7 @@ int main(int argc, char *argv[]) { optind++; } LOG("Command is: %s (%d bytes)\n", payload, strlen(payload)); - char *socket_path = socket_path_from_x11(); + char *socket_path = root_atom_contents("I3_SOCKET_PATH"); if (!socket_path) { ELOG("Could not get i3 IPC socket path\n"); return 1; @@ -597,16 +600,7 @@ int main(int argc, char *argv[]) { property_handlers_init(); - /* Set up the atoms we support */ - xcb_atom_t supported_atoms[] = { -#define xmacro(atom) A_ ## atom, -#include "atoms.xmacro" -#undef xmacro - }; - xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, XCB_ATOM_ATOM, 32, 16, supported_atoms); - /* Set up the window manager’s name */ - xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &root); - xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3"); + ewmh_setup_hints(); keysyms = xcb_key_symbols_alloc(conn); @@ -671,14 +665,26 @@ int main(int argc, char *argv[]) { /* Also handle the UNIX domain sockets passed via socket activation. The * parameter 1 means "remove the environment variables", we don’t want to * pass these to child processes. */ - int fds = sd_listen_fds(1); - if (fds < 0) + listen_fds = sd_listen_fds(0); + if (listen_fds < 0) ELOG("socket activation: Error in sd_listen_fds\n"); - else if (fds == 0) + else if (listen_fds == 0) DLOG("socket activation: no sockets passed\n"); else { - for (int fd = SD_LISTEN_FDS_START; fd < (SD_LISTEN_FDS_START + fds); fd++) { + int flags; + for (int fd = SD_LISTEN_FDS_START; + fd < (SD_LISTEN_FDS_START + listen_fds); + fd++) { DLOG("socket activation: also listening on fd %d\n", fd); + + /* sd_listen_fds() enables FD_CLOEXEC by default. + * However, we need to keep the file descriptors open for in-place + * restarting, therefore we explicitly disable FD_CLOEXEC. */ + if ((flags = fcntl(fd, F_GETFD)) < 0 || + fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) < 0) { + ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd); + } + struct ev_io *ipc_io = scalloc(sizeof(struct ev_io)); ev_io_init(ipc_io, ipc_new_client, fd, EV_READ); ev_io_start(main_loop, ipc_io);