2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
7 * main.c: Initialization, main loop
12 #include <sys/types.h>
13 #include <sys/socket.h>
16 #include <sys/resource.h>
21 #include "sd-daemon.h"
23 /* The original value of RLIMIT_CORE when i3 was started. We need to restore
24 * this before starting any other process, since we set RLIMIT_CORE to
25 * RLIM_INFINITY for i3 debugging versions. */
26 struct rlimit original_rlimit_core;
28 /* Whether this version of i3 is a debug build or a release build. */
29 bool debug_build = false;
31 static int xkb_event_base;
33 int xkb_current_group;
39 xcb_connection_t *conn;
40 /* The screen (0 when you are using DISPLAY=:0) of the connection 'conn' */
43 /* Display handle for libstartup-notification */
46 /* The last timestamp we got from X11 (timestamps are included in some events
47 * and are used for some things, like determining a unique ID in startup
49 xcb_timestamp_t last_timestamp = XCB_CURRENT_TIME;
51 xcb_screen_t *root_screen;
55 struct ev_loop *main_loop;
57 xcb_key_symbols_t *keysyms;
59 /* Those are our connections to X11 for use with libXcursor and XKB */
60 Display *xlibdpy, *xkbdpy;
62 /* The list of key bindings */
63 struct bindings_head *bindings;
65 /* The list of exec-lines */
66 struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts);
68 /* The list of exec_always lines */
69 struct autostarts_always_head autostarts_always = TAILQ_HEAD_INITIALIZER(autostarts_always);
71 /* The list of assignments */
72 struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments);
74 /* The list of workspace assignments (which workspace should end up on which
76 struct ws_assignments_head ws_assignments = TAILQ_HEAD_INITIALIZER(ws_assignments);
78 /* We hope that those are supported and set them to true */
79 bool xcursor_supported = true;
80 bool xkb_supported = true;
82 /* This will be set to true when -C is used so that functions can behave
83 * slightly differently. We don’t want i3-nagbar to be started when validating
84 * the config, for example. */
85 bool only_check_config = false;
88 * This callback is only a dummy, see xcb_prepare_cb and xcb_check_cb.
89 * See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
92 static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
93 /* empty, because xcb_prepare_cb and xcb_check_cb are used */
97 * Flush before blocking (and waiting for new events)
100 static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
105 * Instead of polling the X connection socket we leave this to
106 * xcb_poll_for_event() which knows better than we can ever know.
109 static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
110 xcb_generic_event_t *event;
112 while ((event = xcb_poll_for_event(conn)) != NULL) {
113 if (event->response_type == 0) {
114 if (event_is_ignored(event->sequence, 0))
115 DLOG("Expected X11 Error received for sequence %x\n", event->sequence);
117 xcb_generic_error_t *error = (xcb_generic_error_t*)event;
118 ELOG("X11 Error received! sequence 0x%x, error_code = %d\n",
119 error->sequence, error->error_code);
125 /* Strip off the highest bit (set if the event is generated) */
126 int type = (event->response_type & 0x7F);
128 handle_event(type, event);
136 * When using xmodmap to change the keyboard mapping, this event
137 * is only sent via XKB. Therefore, we need this special handler.
140 static void xkb_got_event(EV_P_ struct ev_io *w, int revents) {
141 DLOG("Handling XKB event\n");
144 /* When using xmodmap, every change (!) gets an own event.
145 * Therefore, we just read all events and only handle the
146 * mapping_notify once. */
147 bool mapping_changed = false;
148 while (XPending(xkbdpy)) {
149 XNextEvent(xkbdpy, (XEvent*)&ev);
150 /* While we should never receive a non-XKB event,
151 * better do sanity checking */
152 if (ev.type != xkb_event_base)
155 if (ev.any.xkb_type == XkbMapNotify) {
156 mapping_changed = true;
160 if (ev.any.xkb_type != XkbStateNotify) {
161 ELOG("Unknown XKB event received (type %d)\n", ev.any.xkb_type);
165 /* See The XKB Extension: Library Specification, section 14.1 */
166 /* We check if the current group (each group contains
167 * two levels) has been changed. Mode_switch activates
168 * group XkbGroup2Index */
169 if (xkb_current_group == ev.state.group)
172 xkb_current_group = ev.state.group;
174 if (ev.state.group == XkbGroup2Index) {
175 DLOG("Mode_switch enabled\n");
176 grab_all_keys(conn, true);
179 if (ev.state.group == XkbGroup1Index) {
180 DLOG("Mode_switch disabled\n");
181 ungrab_all_keys(conn);
182 grab_all_keys(conn, false);
186 if (!mapping_changed)
189 DLOG("Keyboard mapping changed, updating keybindings\n");
190 xcb_key_symbols_free(keysyms);
191 keysyms = xcb_key_symbols_alloc(conn);
193 xcb_numlock_mask = aio_get_mod_mask_for(XCB_NUM_LOCK, keysyms);
195 ungrab_all_keys(conn);
196 DLOG("Re-grabbing...\n");
198 grab_all_keys(conn, (xkb_current_group == XkbGroup2Index));
203 * Exit handler which destroys the main_loop. Will trigger cleanup handlers.
206 static void i3_exit() {
207 /* We need ev >= 4 for the following code. Since it is not *that* important (it
208 * only makes sure that there are no i3-nagbar instances left behind) we still
209 * support old systems with libev 3. */
210 #if EV_VERSION_MAJOR >= 4
211 ev_loop_destroy(main_loop);
214 if (*shmlogname != '\0') {
215 fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
217 shm_unlink(shmlogname);
222 * (One-shot) Handler for all signals with default action "Term", see signal(7)
224 * Unlinks the SHM log and re-raises the signal.
227 static void handle_signal(int sig, siginfo_t *info, void *data) {
228 fprintf(stderr, "Received signal %d, terminating\n", sig);
229 if (*shmlogname != '\0') {
230 fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
231 shm_unlink(shmlogname);
237 int main(int argc, char *argv[]) {
238 char *override_configpath = NULL;
239 bool autostart = true;
240 char *layout_path = NULL;
241 bool delete_layout_path = false;
242 bool force_xinerama = false;
243 bool disable_signalhandler = false;
244 static struct option long_options[] = {
245 {"no-autostart", no_argument, 0, 'a'},
246 {"config", required_argument, 0, 'c'},
247 {"version", no_argument, 0, 'v'},
248 {"help", no_argument, 0, 'h'},
249 {"layout", required_argument, 0, 'L'},
250 {"restart", required_argument, 0, 0},
251 {"force-xinerama", no_argument, 0, 0},
252 {"force_xinerama", no_argument, 0, 0},
253 {"disable-signalhandler", no_argument, 0, 0},
254 {"shmlog-size", required_argument, 0, 0},
255 {"shmlog_size", required_argument, 0, 0},
256 {"get-socketpath", no_argument, 0, 0},
257 {"get_socketpath", no_argument, 0, 0},
260 int option_index = 0, opt;
262 setlocale(LC_ALL, "");
264 /* Get the RLIMIT_CORE limit at startup time to restore this before
265 * starting processes. */
266 getrlimit(RLIMIT_CORE, &original_rlimit_core);
268 /* Disable output buffering to make redirects in .xsession actually useful for debugging */
269 if (!isatty(fileno(stdout)))
270 setbuf(stdout, NULL);
274 /* Init logging *before* initializing debug_build to guarantee early
278 /* I3_VERSION contains either something like this:
279 * "4.0.2 (2011-11-11, branch "release")".
280 * or: "4.0.2-123-gCOFFEEBABE (2011-11-11, branch "next")".
282 * So we check for the offset of the first opening round bracket to
283 * determine whether this is a git version or a release version. */
284 debug_build = ((strchr(I3_VERSION, '(') - I3_VERSION) > 10);
286 /* On non-release builds, disable SHM logging by default. */
287 shmlog_size = (debug_build ? 25 * 1024 * 1024 : 0);
291 while ((opt = getopt_long(argc, argv, "c:CvaL:hld:V", long_options, &option_index)) != -1) {
294 LOG("Autostart disabled using -a\n");
299 layout_path = sstrdup(optarg);
300 delete_layout_path = false;
303 FREE(override_configpath);
304 override_configpath = sstrdup(optarg);
307 LOG("Checking configuration file only (-C)\n");
308 only_check_config = true;
311 printf("i3 version " I3_VERSION " © 2009-2011 Michael Stapelberg and contributors\n");
317 LOG("Enabling debug loglevel %s\n", optarg);
318 add_loglevel(optarg);
321 /* DEPRECATED, ignored for the next 3 versions (3.e, 3.f, 3.g) */
324 if (strcmp(long_options[option_index].name, "force-xinerama") == 0 ||
325 strcmp(long_options[option_index].name, "force_xinerama") == 0) {
326 force_xinerama = true;
327 ELOG("Using Xinerama instead of RandR. This option should be "
328 "avoided at all cost because it does not refresh the list "
329 "of screens, so you cannot configure displays at runtime. "
330 "Please check if your driver really does not support RandR "
331 "and disable this option as soon as you can.\n");
333 } else if (strcmp(long_options[option_index].name, "disable-signalhandler") == 0) {
334 disable_signalhandler = true;
336 } else if (strcmp(long_options[option_index].name, "get-socketpath") == 0 ||
337 strcmp(long_options[option_index].name, "get_socketpath") == 0) {
338 char *socket_path = socket_path_from_x11();
340 printf("%s\n", socket_path);
345 } else if (strcmp(long_options[option_index].name, "shmlog-size") == 0 ||
346 strcmp(long_options[option_index].name, "shmlog_size") == 0) {
347 shmlog_size = atoi(optarg);
348 /* Re-initialize logging immediately to get as many
349 * logmessages as possible into the SHM log. */
351 LOG("Limiting SHM log size to %d bytes\n", shmlog_size);
353 } else if (strcmp(long_options[option_index].name, "restart") == 0) {
355 layout_path = sstrdup(optarg);
356 delete_layout_path = true;
361 fprintf(stderr, "Usage: %s [-c configfile] [-d loglevel] [-a] [-v] [-V] [-C]\n", argv[0]);
362 fprintf(stderr, "\n");
363 fprintf(stderr, "\t-a disable autostart ('exec' lines in config)\n");
364 fprintf(stderr, "\t-c <file> use the provided configfile instead\n");
365 fprintf(stderr, "\t-C validate configuration file and exit\n");
366 fprintf(stderr, "\t-d <level> enable debug output with the specified loglevel\n");
367 fprintf(stderr, "\t-L <file> path to the serialized layout during restarts\n");
368 fprintf(stderr, "\t-v display version and exit\n");
369 fprintf(stderr, "\t-V enable verbose mode\n");
370 fprintf(stderr, "\n");
371 fprintf(stderr, "\t--force-xinerama\n"
372 "\tUse Xinerama instead of RandR.\n"
373 "\tThis option should only be used if you are stuck with the\n"
374 "\tnvidia closed source driver which does not support RandR.\n");
375 fprintf(stderr, "\n");
376 fprintf(stderr, "\t--get-socketpath\n"
377 "\tRetrieve the i3 IPC socket path from X11, print it, then exit.\n");
378 fprintf(stderr, "\n");
379 fprintf(stderr, "\t--shmlog-size <limit>\n"
380 "\tLimits the size of the i3 SHM log to <limit> bytes. Setting this\n"
381 "\tto 0 disables SHM logging entirely.\n"
382 "\tThe default is %d bytes.\n", shmlog_size);
383 fprintf(stderr, "\n");
384 fprintf(stderr, "If you pass plain text arguments, i3 will interpret them as a command\n"
385 "to send to a currently running i3 (like i3-msg). This allows you to\n"
386 "use nice and logical commands, such as:\n"
389 "\ti3 floating toggle\n"
396 /* If the user passes more arguments, we act like i3-msg would: Just send
397 * the arguments as an IPC message to i3. This allows for nice semantic
398 * commands such as 'i3 border none'. */
400 /* We enable verbose mode so that the user knows what’s going on.
401 * This should make it easier to find mistakes when the user passes
402 * arguments by mistake. */
405 LOG("Additional arguments passed. Sending them as a command to i3.\n");
406 char *payload = NULL;
407 while (optind < argc) {
409 payload = sstrdup(argv[optind]);
412 sasprintf(&both, "%s %s", payload, argv[optind]);
418 LOG("Command is: %s (%d bytes)\n", payload, strlen(payload));
419 char *socket_path = socket_path_from_x11();
421 ELOG("Could not get i3 IPC socket path\n");
425 int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
427 err(EXIT_FAILURE, "Could not create socket");
429 struct sockaddr_un addr;
430 memset(&addr, 0, sizeof(struct sockaddr_un));
431 addr.sun_family = AF_LOCAL;
432 strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
433 if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
434 err(EXIT_FAILURE, "Could not connect to i3");
436 if (ipc_send_message(sockfd, strlen(payload), I3_IPC_MESSAGE_TYPE_COMMAND,
437 (uint8_t*)payload) == -1)
438 err(EXIT_FAILURE, "IPC: write()");
440 uint32_t reply_length;
443 if ((ret = ipc_recv_message(sockfd, I3_IPC_MESSAGE_TYPE_COMMAND,
444 &reply_length, &reply)) != 0) {
446 err(EXIT_FAILURE, "IPC: read()");
449 printf("%.*s\n", reply_length, reply);
453 /* Enable logging to handle the case when the user did not specify --shmlog-size */
456 /* Try to enable core dumps by default when running a debug build */
458 struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY };
459 setrlimit(RLIMIT_CORE, &limit);
461 /* The following code is helpful, but not required. We thus don’t pay
462 * much attention to error handling, non-linux or other edge cases. */
464 LOG("CORE DUMPS: You are running a development version of i3, so coredumps were automatically enabled (ulimit -c unlimited).\n");
465 if (getcwd(cwd, sizeof(cwd)) != NULL)
466 LOG("CORE DUMPS: Your current working directory is \"%s\".\n", cwd);
468 if ((patternfd = open("/proc/sys/kernel/core_pattern", O_RDONLY)) >= 0) {
469 memset(cwd, '\0', sizeof(cwd));
470 if (read(patternfd, cwd, sizeof(cwd)) > 0)
471 /* a trailing newline is included in cwd */
472 LOG("CORE DUMPS: Your core_pattern is: %s", cwd);
477 LOG("i3 (tree) version " I3_VERSION " starting\n");
479 conn = xcb_connect(NULL, &conn_screen);
480 if (xcb_connection_has_error(conn))
481 errx(EXIT_FAILURE, "Cannot open display\n");
483 sndisplay = sn_xcb_display_new(conn, NULL, NULL);
485 /* Initialize the libev event loop. This needs to be done before loading
486 * the config file because the parser will install an ev_child watcher
487 * for the nagbar when config errors are found. */
488 main_loop = EV_DEFAULT;
489 if (main_loop == NULL)
490 die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
492 root_screen = xcb_aux_get_screen(conn, conn_screen);
493 root = root_screen->root;
494 root_depth = root_screen->root_depth;
495 xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(conn, root);
496 xcb_query_pointer_cookie_t pointercookie = xcb_query_pointer(conn, root);
498 load_configuration(conn, override_configpath, false);
499 if (only_check_config) {
500 LOG("Done checking configuration file. Exiting.\n");
504 if (config.ipc_socket_path == NULL) {
505 /* Fall back to a file name in /tmp/ based on the PID */
506 if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL)
507 config.ipc_socket_path = get_process_filename("ipc-socket");
509 config.ipc_socket_path = sstrdup(config.ipc_socket_path);
512 uint32_t mask = XCB_CW_EVENT_MASK;
513 uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
514 XCB_EVENT_MASK_STRUCTURE_NOTIFY | /* when the user adds a screen (e.g. video
515 projector), the root window gets a
517 XCB_EVENT_MASK_POINTER_MOTION |
518 XCB_EVENT_MASK_PROPERTY_CHANGE |
519 XCB_EVENT_MASK_ENTER_WINDOW };
520 xcb_void_cookie_t cookie;
521 cookie = xcb_change_window_attributes_checked(conn, root, mask, values);
522 check_error(conn, cookie, "Another window manager seems to be running");
524 xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(conn, gcookie, NULL);
525 if (greply == NULL) {
526 ELOG("Could not get geometry of the root window, exiting\n");
529 DLOG("root geometry reply: (%d, %d) %d x %d\n", greply->x, greply->y, greply->width, greply->height);
531 /* Place requests for the atoms we need as soon as possible */
532 #define xmacro(atom) \
533 xcb_intern_atom_cookie_t atom ## _cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
534 #include "atoms.xmacro"
537 /* Initialize the Xlib connection */
538 xlibdpy = xkbdpy = XOpenDisplay(NULL);
540 /* Try to load the X cursors and initialize the XKB extension */
541 if (xlibdpy == NULL) {
542 ELOG("ERROR: XOpenDisplay() failed, disabling libXcursor/XKB support\n");
543 xcursor_supported = false;
544 xkb_supported = false;
545 } else if (fcntl(ConnectionNumber(xlibdpy), F_SETFD, FD_CLOEXEC) == -1) {
546 ELOG("Could not set FD_CLOEXEC on xkbdpy\n");
549 xcursor_load_cursors();
553 /* Set a cursor for the root window (otherwise the root window will show no
554 cursor until the first client is launched). */
555 if (xcursor_supported)
556 xcursor_set_root_cursor(XCURSOR_CURSOR_POINTER);
557 else xcb_set_root_cursor(XCURSOR_CURSOR_POINTER);
561 major = XkbMajorVersion,
562 minor = XkbMinorVersion;
564 if (fcntl(ConnectionNumber(xkbdpy), F_SETFD, FD_CLOEXEC) == -1) {
565 fprintf(stderr, "Could not set FD_CLOEXEC on xkbdpy\n");
570 if (!XkbQueryExtension(xkbdpy,&i1,&xkb_event_base,&errBase,&major,&minor)) {
571 fprintf(stderr, "XKB not supported by X-server\n");
574 /* end of ugliness */
576 if (!XkbSelectEvents(xkbdpy, XkbUseCoreKbd,
577 XkbMapNotifyMask | XkbStateNotifyMask,
578 XkbMapNotifyMask | XkbStateNotifyMask)) {
579 fprintf(stderr, "Could not set XKB event mask\n");
584 /* Setup NetWM atoms */
585 #define xmacro(name) \
587 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, name ## _cookie, NULL); \
589 ELOG("Could not get atom " #name "\n"); \
592 A_ ## name = reply->atom; \
595 #include "atoms.xmacro"
598 property_handlers_init();
600 /* Set up the atoms we support */
601 xcb_atom_t supported_atoms[] = {
602 #define xmacro(atom) A_ ## atom,
603 #include "atoms.xmacro"
606 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, XCB_ATOM_ATOM, 32, 16, supported_atoms);
607 /* Set up the window manager’s name */
608 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &root);
609 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
611 keysyms = xcb_key_symbols_alloc(conn);
613 xcb_numlock_mask = aio_get_mod_mask_for(XCB_NUM_LOCK, keysyms);
616 grab_all_keys(conn, false);
618 bool needs_tree_init = true;
620 LOG("Trying to restore the layout from %s...", layout_path);
621 needs_tree_init = !tree_restore(layout_path, greply);
622 if (delete_layout_path)
631 /* Force Xinerama (for drivers which don't support RandR yet, esp. the
632 * nVidia binary graphics driver), when specified either in the config
633 * file or on command-line */
634 if (force_xinerama || config.force_xinerama) {
637 DLOG("Checking for XRandR...\n");
638 randr_init(&randr_base);
641 xcb_query_pointer_reply_t *pointerreply;
642 Output *output = NULL;
643 if (!(pointerreply = xcb_query_pointer_reply(conn, pointercookie, NULL))) {
644 ELOG("Could not query pointer position, using first screen\n");
645 output = get_first_output();
647 DLOG("Pointer at %d, %d\n", pointerreply->root_x, pointerreply->root_y);
648 output = get_output_containing(pointerreply->root_x, pointerreply->root_y);
650 ELOG("ERROR: No screen at (%d, %d), starting on the first screen\n",
651 pointerreply->root_x, pointerreply->root_y);
652 output = get_first_output();
655 con_focus(con_descend_focused(output_get_content(output->con)));
660 /* Create the UNIX domain socket for IPC */
661 int ipc_socket = ipc_create_socket(config.ipc_socket_path);
662 if (ipc_socket == -1) {
663 ELOG("Could not create the IPC socket, IPC disabled\n");
665 free(config.ipc_socket_path);
666 struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
667 ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
668 ev_io_start(main_loop, ipc_io);
671 /* Also handle the UNIX domain sockets passed via socket activation. The
672 * parameter 1 means "remove the environment variables", we don’t want to
673 * pass these to child processes. */
674 int fds = sd_listen_fds(1);
676 ELOG("socket activation: Error in sd_listen_fds\n");
678 DLOG("socket activation: no sockets passed\n");
680 for (int fd = SD_LISTEN_FDS_START; fd < (SD_LISTEN_FDS_START + fds); fd++) {
681 DLOG("socket activation: also listening on fd %d\n", fd);
682 struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
683 ev_io_init(ipc_io, ipc_new_client, fd, EV_READ);
684 ev_io_start(main_loop, ipc_io);
688 /* Set up i3 specific atoms like I3_SOCKET_PATH and I3_CONFIG_PATH */
691 struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
692 struct ev_io *xkb = scalloc(sizeof(struct ev_io));
693 struct ev_check *xcb_check = scalloc(sizeof(struct ev_check));
694 struct ev_prepare *xcb_prepare = scalloc(sizeof(struct ev_prepare));
696 ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
697 ev_io_start(main_loop, xcb_watcher);
701 ev_io_init(xkb, xkb_got_event, ConnectionNumber(xkbdpy), EV_READ);
702 ev_io_start(main_loop, xkb);
704 /* Flush the buffer so that libev can properly get new events */
708 ev_check_init(xcb_check, xcb_check_cb);
709 ev_check_start(main_loop, xcb_check);
711 ev_prepare_init(xcb_prepare, xcb_prepare_cb);
712 ev_prepare_start(main_loop, xcb_prepare);
716 manage_existing_windows(root);
718 struct sigaction action;
720 action.sa_sigaction = handle_signal;
721 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
722 sigemptyset(&action.sa_mask);
724 if (!disable_signalhandler)
725 setup_signal_handler();
727 /* Catch all signals with default action "Core", see signal(7) */
728 if (sigaction(SIGQUIT, &action, NULL) == -1 ||
729 sigaction(SIGILL, &action, NULL) == -1 ||
730 sigaction(SIGABRT, &action, NULL) == -1 ||
731 sigaction(SIGFPE, &action, NULL) == -1 ||
732 sigaction(SIGSEGV, &action, NULL) == -1)
733 ELOG("Could not setup signal handler");
736 /* Catch all signals with default action "Term", see signal(7) */
737 if (sigaction(SIGHUP, &action, NULL) == -1 ||
738 sigaction(SIGINT, &action, NULL) == -1 ||
739 sigaction(SIGALRM, &action, NULL) == -1 ||
740 sigaction(SIGUSR1, &action, NULL) == -1 ||
741 sigaction(SIGUSR2, &action, NULL) == -1)
742 ELOG("Could not setup signal handler");
744 /* Ignore SIGPIPE to survive errors when an IPC client disconnects
745 * while we are sending him a message */
746 signal(SIGPIPE, SIG_IGN);
748 /* Autostarting exec-lines */
750 struct Autostart *exec;
751 TAILQ_FOREACH(exec, &autostarts, autostarts) {
752 LOG("auto-starting %s\n", exec->command);
753 start_application(exec->command, exec->no_startup_id);
757 /* Autostarting exec_always-lines */
758 struct Autostart *exec_always;
759 TAILQ_FOREACH(exec_always, &autostarts_always, autostarts_always) {
760 LOG("auto-starting (always!) %s\n", exec_always->command);
761 start_application(exec_always->command, exec_always->no_startup_id);
764 /* Start i3bar processes for all configured bars */
765 Barconfig *barconfig;
766 TAILQ_FOREACH(barconfig, &barconfigs, configs) {
767 char *command = NULL;
768 sasprintf(&command, "%s --bar_id=%s --socket=\"%s\"",
769 barconfig->i3bar_command ? barconfig->i3bar_command : "i3bar",
770 barconfig->id, current_socketpath);
771 LOG("Starting bar process: %s\n", command);
772 start_application(command, true);
776 /* Make sure to destroy the event loop to invoke the cleeanup callbacks
777 * when calling exit() */
780 ev_loop(main_loop, 0);