2020-07-06 21:23:31 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2020-07-09 20:10:34 +00:00
|
|
|
#include <limits.h>
|
2020-07-06 21:23:31 +00:00
|
|
|
#include <signal.h>
|
2020-07-03 21:04:11 +00:00
|
|
|
#include <stdio.h>
|
2020-07-06 21:23:31 +00:00
|
|
|
#include <stdlib.h>
|
2020-07-03 21:04:11 +00:00
|
|
|
#include <string.h>
|
2020-12-04 06:49:12 +00:00
|
|
|
#include <time.h>
|
2020-07-03 21:04:11 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
2020-11-12 08:20:26 +00:00
|
|
|
#define CMDLENGTH 50
|
2020-08-22 17:43:56 +00:00
|
|
|
#define STTLENGTH 256
|
|
|
|
#define NILL INT_MIN
|
|
|
|
#define LOCKFILE "/tmp/dwmblocks.pid"
|
2020-07-03 21:04:11 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2020-12-04 22:08:37 +00:00
|
|
|
char *const pathu;
|
|
|
|
char *const pathc;
|
2020-07-24 21:33:29 +00:00
|
|
|
const int interval;
|
|
|
|
const int signal;
|
2020-07-03 21:04:11 +00:00
|
|
|
char cmdoutcur[CMDLENGTH];
|
|
|
|
char cmdoutprv[CMDLENGTH];
|
|
|
|
} Block;
|
|
|
|
|
2020-07-07 10:17:13 +00:00
|
|
|
#include "blocks.h"
|
|
|
|
|
2020-12-08 06:34:23 +00:00
|
|
|
static void buttonhandler(int sig, siginfo_t *info, void *ucontext);
|
2020-11-24 20:11:43 +00:00
|
|
|
static void cleanup();
|
2020-07-09 20:10:34 +00:00
|
|
|
static void getcmd(Block *block, int sigval);
|
2020-07-25 20:32:38 +00:00
|
|
|
static void setroot();
|
2020-07-03 21:04:11 +00:00
|
|
|
static void setupsignals();
|
2020-12-08 06:34:23 +00:00
|
|
|
static void sighandler(int sig, siginfo_t *si, void *ucontext);
|
2020-07-03 21:04:11 +00:00
|
|
|
static void statusloop();
|
2020-12-08 06:34:23 +00:00
|
|
|
static void termhandler(int sig);
|
2020-07-03 21:04:11 +00:00
|
|
|
static int updatestatus();
|
|
|
|
static void writepid();
|
|
|
|
|
2020-11-24 20:07:36 +00:00
|
|
|
static char statustext[STTLENGTH];
|
2020-12-04 21:37:20 +00:00
|
|
|
static char *delim;
|
2020-07-03 21:04:11 +00:00
|
|
|
static size_t delimlength;
|
|
|
|
static Display *dpy;
|
2020-07-25 18:52:08 +00:00
|
|
|
static sigset_t blocksigmask;
|
2020-07-03 21:04:11 +00:00
|
|
|
|
|
|
|
void
|
2020-12-08 06:34:23 +00:00
|
|
|
buttonhandler(int sig, siginfo_t *info, void *ucontext)
|
2020-07-03 21:04:11 +00:00
|
|
|
{
|
2020-12-08 06:34:23 +00:00
|
|
|
sig = info->si_value.sival_int >> 8;
|
2020-11-15 07:54:15 +00:00
|
|
|
for (Block *block = blocks; block->pathu; block++)
|
2020-12-08 06:34:23 +00:00
|
|
|
if (block->signal == sig)
|
2020-10-03 10:32:07 +00:00
|
|
|
switch (fork()) {
|
|
|
|
case -1:
|
|
|
|
perror("buttonhandler - fork");
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
{
|
2020-12-08 06:34:23 +00:00
|
|
|
char button[] = { '0' + (info->si_value.sival_int & 0xff), '\0' };
|
2020-11-15 07:54:15 +00:00
|
|
|
char *arg[] = { block->pathc, button, NULL };
|
2020-07-03 21:04:11 +00:00
|
|
|
|
2020-10-03 10:32:07 +00:00
|
|
|
close(ConnectionNumber(dpy));
|
2020-07-03 21:04:11 +00:00
|
|
|
setsid();
|
|
|
|
execv(arg[0], arg);
|
2020-07-08 17:25:19 +00:00
|
|
|
perror("buttonhandler - child - execv");
|
2020-07-03 21:04:11 +00:00
|
|
|
_exit(127);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 20:11:43 +00:00
|
|
|
void
|
|
|
|
cleanup()
|
|
|
|
{
|
|
|
|
unlink(LOCKFILE);
|
|
|
|
XStoreName(dpy, DefaultRootWindow(dpy), "");
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
}
|
|
|
|
|
2020-07-03 21:04:11 +00:00
|
|
|
void
|
2020-07-09 20:10:34 +00:00
|
|
|
getcmd(Block *block, int sigval)
|
2020-07-03 21:04:11 +00:00
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
|
|
|
|
if (pipe(fd) == -1) {
|
|
|
|
perror("getcmd - pipe");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
switch (fork()) {
|
|
|
|
case -1:
|
|
|
|
perror("getcmd - fork");
|
|
|
|
exit(1);
|
|
|
|
case 0:
|
2020-07-06 20:01:38 +00:00
|
|
|
close(ConnectionNumber(dpy));
|
2020-07-03 21:04:11 +00:00
|
|
|
close(fd[0]);
|
2020-08-23 22:49:45 +00:00
|
|
|
if (fd[1] != STDOUT_FILENO) {
|
|
|
|
if (dup2(fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
|
|
|
|
perror("getcmd - child - dup2");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
close(fd[1]);
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
2020-07-09 20:10:34 +00:00
|
|
|
if (sigval == NILL) {
|
|
|
|
char *arg[] = { block->pathu, NULL };
|
2020-07-03 21:04:11 +00:00
|
|
|
|
|
|
|
execv(arg[0], arg);
|
|
|
|
} else {
|
2020-07-09 20:10:34 +00:00
|
|
|
char buf[12];
|
|
|
|
char *arg[] = { block->pathu, buf, NULL };
|
2020-07-03 21:04:11 +00:00
|
|
|
|
2020-07-09 20:10:34 +00:00
|
|
|
snprintf(buf, sizeof buf, "%d", sigval);
|
2020-07-03 21:04:11 +00:00
|
|
|
execv(arg[0], arg);
|
|
|
|
}
|
2020-07-08 17:25:19 +00:00
|
|
|
perror("getcmd - child - execv");
|
2020-07-03 21:04:11 +00:00
|
|
|
_exit(127);
|
|
|
|
default:
|
|
|
|
close(fd[1]);
|
|
|
|
if (read(fd[0], block->cmdoutcur, CMDLENGTH) == -1) {
|
|
|
|
perror("getcmd - read");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
close(fd[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 20:32:38 +00:00
|
|
|
void
|
|
|
|
setroot()
|
|
|
|
{
|
|
|
|
if (updatestatus()) {
|
2020-11-24 20:07:36 +00:00
|
|
|
XStoreName(dpy, DefaultRootWindow(dpy), statustext);
|
2020-07-25 20:32:38 +00:00
|
|
|
XSync(dpy, False);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 21:04:11 +00:00
|
|
|
void
|
|
|
|
setupsignals()
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
|
2020-11-24 20:11:43 +00:00
|
|
|
/* populate blocksigmask */
|
|
|
|
sigemptyset(&blocksigmask);
|
|
|
|
sigaddset(&blocksigmask, SIGHUP);
|
|
|
|
sigaddset(&blocksigmask, SIGINT);
|
|
|
|
sigaddset(&blocksigmask, SIGTERM);
|
|
|
|
for (Block *block = blocks; block->pathu; block++)
|
|
|
|
if (block->signal > 0)
|
|
|
|
sigaddset(&blocksigmask, SIGRTMIN + block->signal);
|
|
|
|
|
|
|
|
/* setup signal handlers */
|
2020-07-25 18:52:08 +00:00
|
|
|
/* to handle HUP, INT and TERM */
|
2020-07-03 21:04:11 +00:00
|
|
|
sa.sa_flags = SA_RESTART;
|
2020-07-25 18:52:08 +00:00
|
|
|
sigemptyset(&sa.sa_mask);
|
2020-07-03 21:04:11 +00:00
|
|
|
sa.sa_handler = termhandler;
|
2020-07-24 21:33:29 +00:00
|
|
|
sigaction(SIGHUP, &sa, NULL);
|
2020-07-25 18:52:08 +00:00
|
|
|
sigaction(SIGINT, &sa, NULL);
|
2020-07-24 21:33:29 +00:00
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
2020-07-25 18:52:08 +00:00
|
|
|
|
2020-07-03 21:04:11 +00:00
|
|
|
/* to ignore unused realtime signals */
|
2020-07-25 18:52:08 +00:00
|
|
|
// sa.sa_flags = SA_RESTART;
|
|
|
|
// sigemptyset(&sa.sa_mask);
|
2020-07-03 21:04:11 +00:00
|
|
|
sa.sa_handler = SIG_IGN;
|
2020-07-25 18:52:08 +00:00
|
|
|
for (int i = SIGRTMIN + 1; i <= SIGRTMAX; i++)
|
2020-07-03 21:04:11 +00:00
|
|
|
sigaction(i, &sa, NULL);
|
2020-07-25 18:52:08 +00:00
|
|
|
|
|
|
|
/* to prevent forked children from becoming zombies */
|
|
|
|
sa.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART;
|
|
|
|
// sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_handler = SIG_DFL;
|
|
|
|
sigaction(SIGCHLD, &sa, NULL);
|
|
|
|
|
2020-07-03 21:04:11 +00:00
|
|
|
/* to handle signals generated by dwm on click events */
|
2020-07-24 21:33:29 +00:00
|
|
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
2020-07-25 18:52:08 +00:00
|
|
|
// sigemptyset(&sa.sa_mask);
|
2020-07-24 21:33:29 +00:00
|
|
|
sa.sa_sigaction = buttonhandler;
|
|
|
|
sigaction(SIGRTMIN, &sa, NULL);
|
2020-07-25 18:52:08 +00:00
|
|
|
|
2020-07-03 21:04:11 +00:00
|
|
|
/* to handle update signals for individual blocks */
|
2020-07-25 18:52:08 +00:00
|
|
|
sa.sa_flags |= SA_NODEFER;
|
2020-07-29 13:15:08 +00:00
|
|
|
sa.sa_mask = blocksigmask;
|
2020-07-03 21:04:11 +00:00
|
|
|
sa.sa_sigaction = sighandler;
|
2020-11-15 07:54:15 +00:00
|
|
|
for (Block *block = blocks; block->pathu; block++)
|
|
|
|
if (block->signal > 0)
|
|
|
|
sigaction(SIGRTMIN + block->signal, &sa, NULL);
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-12-08 06:34:23 +00:00
|
|
|
sighandler(int sig, siginfo_t *info, void *ucontext)
|
2020-07-03 21:04:11 +00:00
|
|
|
{
|
2020-12-08 06:34:23 +00:00
|
|
|
sig -= SIGRTMIN;
|
2020-11-15 07:54:15 +00:00
|
|
|
for (Block *block = blocks; block->pathu; block++)
|
2020-12-08 06:34:23 +00:00
|
|
|
if (block->signal == sig)
|
|
|
|
getcmd(block, info->si_value.sival_int);
|
2020-07-25 20:32:38 +00:00
|
|
|
setroot();
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
statusloop()
|
|
|
|
{
|
2020-07-25 20:32:38 +00:00
|
|
|
int i;
|
2020-12-04 06:49:12 +00:00
|
|
|
struct timespec t;
|
2020-07-03 21:04:11 +00:00
|
|
|
|
2020-07-25 18:52:08 +00:00
|
|
|
/* first run */
|
2020-07-29 13:15:08 +00:00
|
|
|
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
|
2020-11-15 07:54:15 +00:00
|
|
|
for (Block *block = blocks; block->pathu; block++)
|
|
|
|
if (block->interval >= 0)
|
|
|
|
getcmd(block, NILL);
|
2020-07-25 20:32:38 +00:00
|
|
|
setroot();
|
2020-07-29 13:15:08 +00:00
|
|
|
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
|
2020-12-29 08:26:08 +00:00
|
|
|
t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
|
|
|
|
while (nanosleep(&t, &t) == -1)
|
|
|
|
if (errno != EINTR) {
|
|
|
|
perror("statusloop - nanosleep");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
i = 1;
|
2020-07-25 18:52:08 +00:00
|
|
|
/* main loop */
|
2020-12-29 08:26:08 +00:00
|
|
|
for (;; i++) {
|
2020-07-29 13:15:08 +00:00
|
|
|
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
|
2020-11-15 07:54:15 +00:00
|
|
|
for (Block *block = blocks; block->pathu; block++)
|
|
|
|
if (block->interval > 0 && i % block->interval == 0)
|
|
|
|
getcmd(block, NILL);
|
2020-07-25 20:32:38 +00:00
|
|
|
setroot();
|
2020-07-29 17:07:58 +00:00
|
|
|
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
|
2020-12-29 08:26:08 +00:00
|
|
|
t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
|
|
|
|
while (nanosleep(&t, &t) == -1);
|
2020-07-24 21:33:29 +00:00
|
|
|
}
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-12-08 06:34:23 +00:00
|
|
|
termhandler(int sig)
|
2020-07-03 21:04:11 +00:00
|
|
|
{
|
2020-11-24 20:11:43 +00:00
|
|
|
cleanup();
|
|
|
|
exit(0);
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 20:07:36 +00:00
|
|
|
/* returns whether block outputs have changed and updates statustext if they have */
|
2020-07-03 21:04:11 +00:00
|
|
|
int
|
|
|
|
updatestatus()
|
|
|
|
{
|
2020-11-24 20:07:36 +00:00
|
|
|
char *s = statustext;
|
2020-07-29 17:06:15 +00:00
|
|
|
char *c, *p; /* for cmdoutcur and cmdoutprv */
|
|
|
|
const char *d; /* for delimiter */
|
2020-11-15 07:54:15 +00:00
|
|
|
Block *block = blocks;
|
2020-07-03 21:04:11 +00:00
|
|
|
|
2020-07-29 17:06:15 +00:00
|
|
|
/* checking half of the function */
|
2020-09-20 10:17:36 +00:00
|
|
|
/* find the first non-empty block */
|
2020-11-15 07:54:15 +00:00
|
|
|
for (;; block++) {
|
2020-09-20 09:26:00 +00:00
|
|
|
/* all blocks are empty */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (!block->pathu)
|
2020-08-05 20:45:49 +00:00
|
|
|
return 0;
|
2020-11-15 07:54:15 +00:00
|
|
|
/* contents of the block changed */
|
|
|
|
if (*block->cmdoutcur != *block->cmdoutprv)
|
2020-09-20 09:26:00 +00:00
|
|
|
goto update0;
|
2020-10-23 13:27:13 +00:00
|
|
|
/* skip delimiter handler for the first non-empty block */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (*block->cmdoutcur != '\n' && *block->cmdoutcur != '\0')
|
2020-08-05 20:45:49 +00:00
|
|
|
goto skipdelimc;
|
2020-07-29 17:06:15 +00:00
|
|
|
}
|
|
|
|
/* main loop */
|
2020-11-15 07:54:15 +00:00
|
|
|
for (; block->pathu; block++) {
|
|
|
|
/* contents of the block changed */
|
|
|
|
if (*block->cmdoutcur != *block->cmdoutprv)
|
2020-09-20 09:26:00 +00:00
|
|
|
goto update1;
|
|
|
|
/* delimiter handler */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (*block->cmdoutcur != '\n' && *block->cmdoutcur != '\0')
|
2020-08-05 20:45:49 +00:00
|
|
|
s += delimlength;
|
2020-09-20 09:26:00 +00:00
|
|
|
/* skip over empty blocks */
|
|
|
|
else
|
2020-08-05 20:45:49 +00:00
|
|
|
continue;
|
2020-07-29 17:06:15 +00:00
|
|
|
skipdelimc:
|
2020-09-20 09:26:00 +00:00
|
|
|
/* checking for the first byte has been done */
|
2020-11-15 07:54:15 +00:00
|
|
|
c = block->cmdoutcur + 1, p = block->cmdoutprv + 1;
|
2020-08-05 20:45:49 +00:00
|
|
|
for (; *c != '\n' && *c != '\0'; c++, p++)
|
2020-11-15 07:54:15 +00:00
|
|
|
/* contents of the block changed */
|
2020-07-29 17:06:15 +00:00
|
|
|
if (*c != *p) {
|
2020-11-15 07:54:15 +00:00
|
|
|
s += c - block->cmdoutcur;
|
2020-08-05 20:45:49 +00:00
|
|
|
goto update2;
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
2020-11-15 07:54:15 +00:00
|
|
|
s += c - block->cmdoutcur;
|
2020-09-20 09:26:00 +00:00
|
|
|
/* byte containing info about signal number for the block */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (block->pathc && block->signal)
|
2020-07-29 17:06:15 +00:00
|
|
|
s++;
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
2020-07-25 11:50:09 +00:00
|
|
|
return 0;
|
2020-09-20 09:26:00 +00:00
|
|
|
|
2020-07-29 17:06:15 +00:00
|
|
|
/* updating half of the function */
|
2020-09-20 10:17:36 +00:00
|
|
|
/* find the first non-empty block */
|
2020-11-15 07:54:15 +00:00
|
|
|
for (;; block++) {
|
2020-09-20 09:26:00 +00:00
|
|
|
/* all blocks are empty */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (!block->pathu)
|
2020-08-05 20:45:49 +00:00
|
|
|
return 1;
|
2020-09-20 09:26:00 +00:00
|
|
|
update0:
|
2020-10-23 13:27:13 +00:00
|
|
|
/* don't add delimiter before the first non-empty block */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (*block->cmdoutcur != '\n' && *block->cmdoutcur != '\0')
|
2020-08-05 20:45:49 +00:00
|
|
|
goto skipdelimu;
|
2020-11-15 07:54:15 +00:00
|
|
|
*block->cmdoutprv = *block->cmdoutcur;
|
2020-07-29 17:06:15 +00:00
|
|
|
}
|
|
|
|
/* main loop */
|
2020-11-15 07:54:15 +00:00
|
|
|
for (; block->pathu; block++) {
|
2020-09-20 09:26:00 +00:00
|
|
|
update1:
|
|
|
|
/* delimiter handler */
|
2020-11-15 07:54:15 +00:00
|
|
|
if (*block->cmdoutcur != '\n' && *block->cmdoutcur != '\0') {
|
2020-08-05 20:45:49 +00:00
|
|
|
d = delim;
|
2020-08-12 07:20:04 +00:00
|
|
|
while (*d != '\0')
|
2020-08-05 20:45:49 +00:00
|
|
|
*(s++) = *(d++);
|
2020-12-27 15:29:38 +00:00
|
|
|
*(s++) = DELIMITERENDCHAR;
|
2020-09-20 09:26:00 +00:00
|
|
|
/* skip over empty blocks */
|
2020-08-05 20:45:49 +00:00
|
|
|
} else {
|
2020-11-15 07:54:15 +00:00
|
|
|
*block->cmdoutprv = *block->cmdoutcur;
|
2020-08-05 20:45:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-07-29 17:06:15 +00:00
|
|
|
skipdelimu:
|
2020-11-15 07:54:15 +00:00
|
|
|
c = block->cmdoutcur, p = block->cmdoutprv;
|
2020-08-05 20:45:49 +00:00
|
|
|
update2:
|
2020-07-03 21:04:11 +00:00
|
|
|
do {
|
2020-07-29 17:06:15 +00:00
|
|
|
*(s++) = *c;
|
|
|
|
*p = *c;
|
2020-09-20 09:27:46 +00:00
|
|
|
c++, p++;
|
2020-07-29 17:06:15 +00:00
|
|
|
} while (*c != '\n' && *c != '\0');
|
2020-11-15 07:54:15 +00:00
|
|
|
if (block->pathc && block->signal)
|
|
|
|
*(s++) = block->signal;
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
2020-08-03 17:58:23 +00:00
|
|
|
*s = '\0';
|
2020-07-25 11:50:09 +00:00
|
|
|
return 1;
|
2020-07-03 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
writepid()
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct flock fl;
|
|
|
|
|
|
|
|
fd = open(LOCKFILE, O_RDWR|O_CREAT, 0644);
|
|
|
|
if (fd == -1) {
|
2020-10-14 19:13:31 +00:00
|
|
|
perror("writepid - open");
|
2020-07-03 21:04:11 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fl.l_type = F_WRLCK;
|
|
|
|
fl.l_start = 0;
|
|
|
|
fl.l_whence = SEEK_SET;
|
|
|
|
fl.l_len = 0;
|
|
|
|
if (fcntl(fd, F_SETLK, &fl) == -1) {
|
|
|
|
if (errno == EACCES || errno == EAGAIN) {
|
|
|
|
fputs("Error: another instance of dwmblocks is already running.\n", stderr);
|
|
|
|
exit(2);
|
|
|
|
}
|
2020-07-24 16:25:56 +00:00
|
|
|
perror("writepid - fcntl");
|
2020-07-03 21:04:11 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (ftruncate(fd, 0) == -1) {
|
|
|
|
perror("writepid - ftruncate");
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-07-24 20:31:56 +00:00
|
|
|
if (dprintf(fd, "%ld", (long)getpid()) < 0) {
|
|
|
|
perror("writepid - dprintf");
|
2020-07-03 21:04:11 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
writepid();
|
2020-12-04 21:37:20 +00:00
|
|
|
if (argc == 3 && strcmp(argv[1], "-d") == 0) {
|
|
|
|
delim = argv[2];
|
|
|
|
delimlength = strlen(delim) + 1;
|
|
|
|
} else {
|
|
|
|
delim = DELIMITER;
|
2020-12-08 20:43:39 +00:00
|
|
|
delimlength = sizeof DELIMITER;
|
2020-12-04 21:37:20 +00:00
|
|
|
}
|
2020-07-03 21:04:11 +00:00
|
|
|
if (!(dpy = XOpenDisplay(NULL))) {
|
|
|
|
fputs("Error: could not open display.\n", stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-07-25 18:52:08 +00:00
|
|
|
setupsignals();
|
2020-07-24 21:33:29 +00:00
|
|
|
statusloop();
|
2020-11-24 20:11:43 +00:00
|
|
|
cleanup();
|
2020-07-03 21:04:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|