#include #include #include #include #include #include "util.h" void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); if (fmt[0] && fmt[strlen(fmt)-1] == ':') { fputc(' ', stderr); perror(NULL); } else { fputc('\n', stderr); } exit(1); } void sendnotif(const char *appname, const char *title, const char *body) { notify_init(appname); NotifyNotification *n; n = notify_notification_new(title, body, NULL); notify_notification_show(n, NULL); g_object_unref(G_OBJECT(n)); notify_uninit(); } int getbtnint(const char *blkbtn) { char *endptr; int errno; long val; errno = 0; if (blkbtn == NULL) return 0; val = strtol(blkbtn, &endptr, 10); if (errno == 0 && *endptr == '\0' && val >= 1 && val <= 8) return (int)val; return 0; } void spawn(const char *const argv[]) { if (fork() == 0) { dup2(STDERR_FILENO, STDOUT_FILENO); setsid(); execvp(argv[0], (char * const *)argv); die("spawn %s failed:", (argv)[0]); } }