ret = asprintf(&evdev_path, "%s", argv[1]);
if (ret < 0) {
fprintf(stderr, "CRTITICAL: Cannot set up event device path\n");
- return -1;
+ goto bail_out_1;
}
/* Setup threading data */
exit_app = 0;
if (pthread_mutex_init(&exit_mutex, NULL) != 0) {
fprintf(stderr, "CRITICAL: Cannot create exit_mutex!");
- return -1;
+ goto bail_out_1;
}
-
+
etd.exit_mutex = &exit_mutex;
etd.pexit_app = &exit_app;
-
+
if (XInitThreads() <= 0) {
fprintf(stderr, "Unable to initialize X11 threads\n");
- pthread_mutex_destroy(&exit_mutex);
- return -1;
+ goto bail_out_2;
}
/* Create main window */
if (create_window() < 0)
- return -1;
+ goto bail_out_2;
/* Start main window event loop */
if (pthread_create(&win_event_loop, NULL, &window_event_loop, &etd) != 0) {
fprintf(stderr, "CRITICAL: Cannot start main window event loop!\n");
- return -1;
+ goto bail_out_2;
}
-
+
if (init_keyb_logging(evdev_path) != 0)
- goto exit;
-
+ goto bail_out_3;
+
if (init_fps_counter(&etd) != 0)
- goto exit;
-
+ goto bail_out_3;
+
if (pthread_create(&kb_event_loop, NULL, &get_keyb_events, &etd) != 0) {
fprintf(stderr, "CRITICAL: Cannot start boundkeys event loop!\n");
- return -1;
+ goto bail_out_3;
}
-
+
pthread_join(win_event_loop, NULL);
stop_benchmark();
destroy_window();
pthread_mutex_destroy(&exit_mutex);
+ free(evdev_path);
return 0;
-
- exit:
- pthread_join(win_event_loop, NULL);
+
+bail_out_3:
+ pthread_join(win_event_loop, NULL);
+bail_out_2:
pthread_mutex_destroy(&exit_mutex);
-
+bail_out_1:
+ free(evdev_path);
return -1;
}