Added -d to facilitate running as a standalone daemon.

master
Raheman Vaiya 5 years ago
parent cfb991b37a
commit 4e58ca139a
  1. BIN
      keyd.1.gz
  2. 18
      man.md
  3. 23
      src/main.c

Binary file not shown.

@ -15,24 +15,22 @@ keyd [-m] [-l]
**-l**: List all valid key names.
# OVERVIEW
keyd is intended to be run as a system wide daemon via systemd. If run
directly it will run in the foreground and print diagnostic information to
stderr.
**-d**: Fork and run in the background.
Control can be exercised using the standard systemd mechanisms. E.G:
# OVERVIEW
- journalctl -fu keyd # Print diagnostic information.
- systemctl restart keyd # Restart the daemon to effect configuration reload.
keyd is intended to be run as system wide daemon managed by systemd. The
default behaviour is to run the forground and print to stderr but it can also
be run as a standalone daemon if -d is supplied, in which case log output will
be stored in /var/log/keyd.log.
# CONFIGURATION
All configuration files are stored in /etc/keyd. The name of each file should
correspond to the device name (see `-m`) to which it is to be applied followed
by .cfg (e.g /etc/keyd/Magic\ Keyboard.cfg). Configuration files are loaded
upon initialization, thus restarting the daemon is necessary for changes
to take effect.
upon initialization thus restarting the daemon is necessary for changes
to take effect (e.g sudo systemctl restart keyd).
If no configuration file exists for a given keyboard and default.cfg is present, it is used.

@ -43,6 +43,7 @@
#define UINPUT_DEVICE_NAME "keyd virtual keyboard"
#define MAX_KEYBOARDS 256
#define LOCK_FILE "/var/lock/keyd.lock"
#define LOG_FILE "/var/log/keyd.log" //Only used when running as a daemon.
static int ufd = -1;
@ -642,6 +643,24 @@ static void exit_signal_handler(int sig)
exit(0);
}
void daemonize()
{
int fd = open(LOG_FILE, O_APPEND|O_WRONLY);
warn("Daemonizing.");
warn("Log output will be stored in %s", LOG_FILE);
if(fork()) exit(0);
if(fork()) exit(0);
close(0);
close(1);
close(2);
dup2(fd, 1);
dup2(fd, 2);
}
int main(int argc, char *argv[])
{
if(argc > 1 && !strcmp(argv[1], "-m"))
@ -659,6 +678,10 @@ int main(int argc, char *argv[])
signal(SIGINT, exit_signal_handler);
signal(SIGTERM, exit_signal_handler);
if(argc > 1 && !strcmp(argv[1], "-d"))
daemonize();
warn("Starting keyd.");
config_generate();
ufd = create_uinput_fd();

Loading…
Cancel
Save