aboutsummaryrefslogtreecommitdiff
path: root/dwl.c
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2020-08-18 19:39:34 -0500
committerDevin J. Pohly <djpohly@gmail.com>2020-08-18 19:39:34 -0500
commit83f60e89b0ce395511a91f3f1944015668730758 (patch)
treef22d538879d5e99b3ba5651819ce48d458c72ed8 /dwl.c
parentd615d3836c8a4091a9fc7f5313e517f04df48601 (diff)
add macro for fatal errors
dwm lets the OS do cleanup if the program errors out
Diffstat (limited to 'dwl.c')
-rw-r--r--dwl.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/dwl.c b/dwl.c
index 18c2b33..8aa428b 100644
--- a/dwl.c
+++ b/dwl.c
@@ -40,6 +40,8 @@
#endif
/* macros */
+#define BARF(fmt, ...) do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); } while (0)
+#define EBARF(fmt, ...) BARF(fmt ": %s", ##__VA_ARGS__, strerror(errno))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
@@ -1280,20 +1282,13 @@ run(char *startup_cmd)
/* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(dpy);
- if (!socket) {
- perror("startup: display_add_socket_auto");
- wlr_backend_destroy(backend);
- exit(EXIT_FAILURE);
- }
+ if (!socket)
+ BARF("startup: display_add_socket_auto");
/* Start the backend. This will enumerate outputs and inputs, become the DRM
* master, etc */
- if (!wlr_backend_start(backend)) {
- perror("startup: backend_start");
- wlr_backend_destroy(backend);
- wl_display_destroy(dpy);
- exit(EXIT_FAILURE);
- }
+ if (!wlr_backend_start(backend))
+ BARF("startup: backend_start");
/* Now that outputs are initialized, choose initial selmon based on
* cursor position, and set default cursor image */
@@ -1311,16 +1306,11 @@ run(char *startup_cmd)
setenv("WAYLAND_DISPLAY", socket, 1);
if (startup_cmd) {
startup_pid = fork();
- if (startup_pid < 0) {
- perror("startup: fork");
- wl_display_destroy(dpy);
- exit(EXIT_FAILURE);
- }
+ if (startup_pid < 0)
+ EBARF("startup: fork");
if (startup_pid == 0) {
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, (void *)NULL);
- perror("startup: execl");
- wl_display_destroy(dpy);
- exit(EXIT_FAILURE);
+ EBARF("startup: execl");
}
}
/* Run the Wayland event loop. This does not return until you exit the
@@ -1586,10 +1576,8 @@ setup(void)
void
sigchld(int unused)
{
- if (signal(SIGCHLD, sigchld) == SIG_ERR) {
- perror("can't install SIGCHLD handler");
- exit(EXIT_FAILURE);
- }
+ if (signal(SIGCHLD, sigchld) == SIG_ERR)
+ EBARF("can't install SIGCHLD handler");
while (0 < waitpid(-1, NULL, WNOHANG))
;
}
@@ -1600,9 +1588,7 @@ spawn(const Arg *arg)
if (fork() == 0) {
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
- fprintf(stderr, "dwl: execvp %s", ((char **)arg->v)[0]);
- perror(" failed");
- exit(EXIT_FAILURE);
+ EBARF("dwl: execvp %s failed", ((char **)arg->v)[0]);
}
}
@@ -1941,10 +1927,8 @@ main(int argc, char *argv[])
// Wayland requires XDG_RUNTIME_DIR for creating its communications
// socket
- if (!getenv("XDG_RUNTIME_DIR")) {
- fprintf(stderr, "XDG_RUNTIME_DIR must be set\n");
- exit(EXIT_FAILURE);
- }
+ if (!getenv("XDG_RUNTIME_DIR"))
+ BARF("XDG_RUNTIME_DIR must be set");
/* The Wayland display is managed by libwayland. It handles accepting
* clients from the Unix socket, manging Wayland globals, and so on. */