From ba8657d8fef11d20d1b0c24cfc7f439aa2200797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sat, 6 May 2017 22:07:14 +0200 Subject: wmstatus: simplify spawning MPD and NUT sockets are FD_CLOEXEC already, do the same with Xlib. --- wmstatus.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/wmstatus.c b/wmstatus.c index 00dafdf..8568ce3 100644 --- a/wmstatus.c +++ b/wmstatus.c @@ -1,7 +1,7 @@ /* * wmstatus.c: simple PulseAudio-enabled status setter for dwm and i3 * - * Copyright (c) 2015 - 2016, Přemysl Janouch + * Copyright (c) 2015 - 2017, Přemysl Janouch * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -1210,6 +1210,7 @@ app_context_init (struct app_context *self) poller_init (&self->poller); self->api = poller_pa_new (&self->poller); + set_cloexec (ConnectionNumber (self->dpy)); poller_fd_init (&self->x_event, &self->poller, ConnectionNumber (self->dpy)); @@ -2072,17 +2073,11 @@ on_make_context (void *user_data) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static void -spawn (struct app_context *ctx, char *argv[]) +spawn (char *argv[]) { posix_spawn_file_actions_t actions; posix_spawn_file_actions_init (&actions); - posix_spawn_file_actions_addclose (&actions, ConnectionNumber (ctx->dpy)); - if (ctx->mpd_client.socket != -1) - posix_spawn_file_actions_addclose (&actions, ctx->mpd_client.socket); - if (ctx->nut_client.socket != -1) - posix_spawn_file_actions_addclose (&actions, ctx->nut_client.socket); - // That would mess up our JSON posix_spawn_file_actions_addopen (&actions, STDOUT_FILENO, "/dev/null", O_WRONLY, 0); @@ -2190,29 +2185,32 @@ on_volume_set (struct app_context *ctx, int arg) static void on_lock (struct app_context *ctx, int arg) { + (void) ctx; (void) arg; // One of these will work char *argv_gdm[] = { "gdm-switch-user", NULL }; - spawn (ctx, argv_gdm); + spawn (argv_gdm); char *argv_ldm[] = { "dm-tool", "lock", NULL }; - spawn (ctx, argv_ldm); + spawn (argv_ldm); } static void on_input_switch (struct app_context *ctx, int arg) { + (void) ctx; char *values[] = { "vga", "dvi", "dp", "hdmi" }; char *argv[] = { "input-switch", values[arg], NULL }; - spawn (ctx, argv); + spawn (argv); } static void on_brightness (struct app_context *ctx, int arg) { + (void) ctx; char *value = xstrdup_printf ("%d", arg); char *argv[] = { "brightness", value, NULL }; - spawn (ctx, argv); + spawn (argv); free (value); } -- cgit v1.2.3