wmstatus: simplify spawning
MPD and NUT sockets are FD_CLOEXEC already, do the same with Xlib.
This commit is contained in:
parent
9e437bd921
commit
ba8657d8fe
22
wmstatus.c
22
wmstatus.c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* wmstatus.c: simple PulseAudio-enabled status setter for dwm and i3
|
* wmstatus.c: simple PulseAudio-enabled status setter for dwm and i3
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 - 2016, Přemysl Janouch <p.janouch@gmail.com>
|
* Copyright (c) 2015 - 2017, Přemysl Janouch <p.janouch@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* 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);
|
poller_init (&self->poller);
|
||||||
self->api = poller_pa_new (&self->poller);
|
self->api = poller_pa_new (&self->poller);
|
||||||
|
|
||||||
|
set_cloexec (ConnectionNumber (self->dpy));
|
||||||
poller_fd_init (&self->x_event, &self->poller,
|
poller_fd_init (&self->x_event, &self->poller,
|
||||||
ConnectionNumber (self->dpy));
|
ConnectionNumber (self->dpy));
|
||||||
|
|
||||||
|
@ -2072,17 +2073,11 @@ on_make_context (void *user_data)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
static void
|
static void
|
||||||
spawn (struct app_context *ctx, char *argv[])
|
spawn (char *argv[])
|
||||||
{
|
{
|
||||||
posix_spawn_file_actions_t actions;
|
posix_spawn_file_actions_t actions;
|
||||||
posix_spawn_file_actions_init (&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
|
// That would mess up our JSON
|
||||||
posix_spawn_file_actions_addopen
|
posix_spawn_file_actions_addopen
|
||||||
(&actions, STDOUT_FILENO, "/dev/null", O_WRONLY, 0);
|
(&actions, STDOUT_FILENO, "/dev/null", O_WRONLY, 0);
|
||||||
|
@ -2190,29 +2185,32 @@ on_volume_set (struct app_context *ctx, int arg)
|
||||||
static void
|
static void
|
||||||
on_lock (struct app_context *ctx, int arg)
|
on_lock (struct app_context *ctx, int arg)
|
||||||
{
|
{
|
||||||
|
(void) ctx;
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
// One of these will work
|
// One of these will work
|
||||||
char *argv_gdm[] = { "gdm-switch-user", NULL };
|
char *argv_gdm[] = { "gdm-switch-user", NULL };
|
||||||
spawn (ctx, argv_gdm);
|
spawn (argv_gdm);
|
||||||
char *argv_ldm[] = { "dm-tool", "lock", NULL };
|
char *argv_ldm[] = { "dm-tool", "lock", NULL };
|
||||||
spawn (ctx, argv_ldm);
|
spawn (argv_ldm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_input_switch (struct app_context *ctx, int arg)
|
on_input_switch (struct app_context *ctx, int arg)
|
||||||
{
|
{
|
||||||
|
(void) ctx;
|
||||||
char *values[] = { "vga", "dvi", "dp", "hdmi" };
|
char *values[] = { "vga", "dvi", "dp", "hdmi" };
|
||||||
char *argv[] = { "input-switch", values[arg], NULL };
|
char *argv[] = { "input-switch", values[arg], NULL };
|
||||||
spawn (ctx, argv);
|
spawn (argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_brightness (struct app_context *ctx, int arg)
|
on_brightness (struct app_context *ctx, int arg)
|
||||||
{
|
{
|
||||||
|
(void) ctx;
|
||||||
char *value = xstrdup_printf ("%d", arg);
|
char *value = xstrdup_printf ("%d", arg);
|
||||||
char *argv[] = { "brightness", value, NULL };
|
char *argv[] = { "brightness", value, NULL };
|
||||||
spawn (ctx, argv);
|
spawn (argv);
|
||||||
free (value);
|
free (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue