sxhkd-rc

[fork] simple X hotkey daemon (but for the rc shell)
Log | Files | Refs | README | LICENSE

commit 6dd6a8b1597917e0fefbd69aac990d072a1910f8
parent d0a48ef60a302035b68f57dac9013f4bbc0e9b30
Author: Bastien Dejean <nihilhill@gmail.com>
Date:   Wed,  9 Jan 2013 20:56:34 +0100

Add an option to redirect the commands output

Diffstat:
MREADME.md | 1+
Mhelpers.c | 4++++
Msxhkd.1 | 3+++
Msxhkd.c | 13+++++++++++--
Msxhkd.h | 1+
5 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -13,6 +13,7 @@ sxhkd is a simple X hotkey daemon. * `-h`: Print the synopsis to standard output and exit. * `-v`: Print the version information to standard output and exit. * `-c CONFIG_FILE`: Read the main configuration from the given file. +* `-r REDIR_FILE`: Redirect the commands output to the given file. ## Configuration diff --git a/helpers.c b/helpers.c @@ -33,6 +33,10 @@ void spawn(char *cmd[]) close(xcb_get_file_descriptor(dpy)); if (fork() == 0) { setsid(); + if (redir_fd != -1) { + dup2(redir_fd, STDOUT_FILENO); + dup2(redir_fd, STDERR_FILENO); + } execvp(cmd[0], cmd); err("Spawning failed.\n"); } diff --git a/sxhkd.1 b/sxhkd.1 @@ -18,6 +18,9 @@ Print the version information to standard output and exit. .TP .BI -c " CONFIG_FILE" Read the configuration from the given file. +.TP +.BI -r " REDIR_FILE" +Redirect the commands output to the given file. .SH CONFIGURATION .PP Each line of the configuration file is interpreted as so: diff --git a/sxhkd.c b/sxhkd.c @@ -3,9 +3,11 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <sys/stat.h> #include <sys/wait.h> #include <sys/select.h> +#include <fcntl.h> #include <ctype.h> #include <getopt.h> #include <signal.h> @@ -197,16 +199,21 @@ int main(int argc, char *argv[]) char opt; config_path = NULL; - while ((opt = getopt(argc, argv, "vhc:")) != -1) { + while ((opt = getopt(argc, argv, "vhc:r:")) != -1) { switch (opt) { case 'v': printf("%s\n", VERSION); exit(EXIT_SUCCESS); break; case 'h': - printf("sxhkd [-h|-v|-c CONFIG_FILE] [EXTRA_CONFIG ...]\n"); + printf("sxhkd [-h|-v|-c CONFIG_FILE|-r REDIR_FILE] [EXTRA_CONFIG ...]\n"); exit(EXIT_SUCCESS); break; + case 'r': + redir_fd = open(optarg, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (redir_fd == -1) + warn("Failed to open the command redirection file.\n"); + break; case 'c': config_path = optarg; break; @@ -285,6 +292,8 @@ int main(int argc, char *argv[]) } } + if (redir_fd != -1) + close(redir_fd); ungrab(); cleanup(); xcb_key_symbols_free(symbols); diff --git a/sxhkd.h b/sxhkd.h @@ -38,6 +38,7 @@ char config_file[MAXLEN]; char *config_path; char **extra_confs; int num_extra_confs; +int redir_fd; bool running, reload;