wmsl

Block-based window manager status line
git clone https://git.sinitax.com/sinitax/wmsl
Log | Files | Refs | README | LICENSE | sfeed.txt

sigwmsl.c (840B)


      1#include <err.h>
      2#include <errno.h>
      3#include <signal.h>
      4#include <stdarg.h>
      5#include <stdio.h>
      6#include <string.h>
      7#include <stdlib.h>
      8
      9static const char *pid_file = "/tmp/wmsl.pid";
     10
     11int
     12main(int argc, const char **argv)
     13{
     14	char buffer[64];
     15	pid_t pid;
     16	sigval_t sigval;
     17	int block_id;
     18	FILE *file;
     19
     20	if (argc != 2) {
     21		fprintf(stderr, "Usage: sigwmsl <block-id>\n");
     22		return 1;
     23	}
     24
     25	block_id = atoi(argv[1]);
     26	if (!block_id) errx(1, "invalid block id");
     27
     28	file = fopen(pid_file, "r");
     29	if (!file) err(1, "fopen '%s'", pid_file);
     30
     31	if (!fgets(buffer, 64, file))
     32		errx(1, "pid file empty");
     33
     34	pid = atoi(buffer);
     35
     36	sigval.sival_int = block_id;
     37	if (sigqueue(pid, SIGUSR1, sigval) == -1) {
     38		if (errno == EINVAL) {
     39			errx(1, "invalid signal value");
     40		} else if (errno == ESRCH) {
     41			errx(1, "wmsl not running");
     42		}
     43	}
     44
     45	fclose(file);
     46}