132
129
snprintf(file, len, "%s/%s", confdir, dirent->d_name);
134
/* allow only regular files and symlinks to these */
131
/* allow only regular files and symlinks to files */
135
132
if (stat(file, &stat_buf) != 0) {
136
acpid_log(LOG_ERR, "stat(%s): %s\n", file, strerror(errno));
133
acpid_log(LOG_ERR, "stat(%s): %s\n", file,
136
continue; /* keep trying the rest of the files */
140
138
if (!S_ISREG(stat_buf.st_mode)) {
141
139
acpid_log(LOG_DEBUG, "skipping non-file %s\n", file);
143
continue; /* skip subdirs */
141
continue; /* skip non-regular files */
146
/* check for run-parts style filename */
147
basen = basename(file);
148
if (regcomp(&preg, "^[a-zA-Z0-9_-]+$", RULE_REGEX_FLAGS) == 0){
149
if (regexec(&preg, basen, 0, NULL, 0) == 0){
150
r = parse_file(file);
152
enlist_rule(&cmd_list, r);
156
acpid_log(LOG_DEBUG, "ignoring conf file %s\n", file);
144
r = parse_file(file);
146
enlist_rule(&cmd_list, r);
291
280
rv = regcomp(r->event, val, RULE_REGEX_FLAGS);
294
regerror(rv, r->event, buf, sizeof(buf));
295
acpid_log(LOG_ERR, "regcomp(): %s\n", buf);
283
regerror(rv, r->event, rbuf, sizeof(rbuf));
284
acpid_log(LOG_ERR, "regcomp(): %s\n", rbuf);
533
523
struct rule *pnext = p->next;
534
524
if (!regexec(p->event, event, 0, NULL, 0)) {
526
if (acpid_debug && logevents) {
537
527
acpid_log(LOG_DEBUG,
538
528
"rule from %s matched\n",
554
if (acpid_debug && logevents) {
565
555
acpid_log(LOG_DEBUG, "%d total rule%s matched\n",
566
556
nrules, (nrules == 1)?"":"s");
573
563
static sigset_t *
574
564
signals_handled(void)
576
static sigset_t sigset;
578
sigemptyset(&sigset);
579
sigaddset(&sigset, SIGHUP);
580
sigaddset(&sigset, SIGTERM);
581
sigaddset(&sigset, SIGQUIT);
582
sigaddset(&sigset, SIGINT);
569
sigaddset(&set, SIGHUP);
570
sigaddset(&set, SIGTERM);
571
sigaddset(&set, SIGQUIT);
572
sigaddset(&set, SIGINT);
621
611
case 0: /* child */
622
612
/* parse the commandline, doing any substitutions needed */
623
613
action = parse_cmd(rule->action.cmd, event);
624
acpid_log(LOG_INFO, "executing action \"%s\"\n", action);
616
"executing action \"%s\"\n", action);
626
619
/* reset signals */
627
620
signal(SIGHUP, SIG_DFL);
631
624
signal(SIGPIPE, SIG_DFL);
632
625
sigprocmask(SIG_UNBLOCK, signals_handled(), NULL);
627
if (acpid_debug && logevents) {
635
628
fprintf(stdout, "BEGIN HANDLER MESSAGES\n");
636
630
execl("/bin/sh", "/bin/sh", "-c", action, NULL);
637
631
/* should not get here */
638
632
acpid_log(LOG_ERR, "execl(): %s\n", strerror(errno));
643
637
waitpid(pid, &status, 0);
638
if (acpid_debug && logevents) {
645
639
fprintf(stdout, "END HANDLER MESSAGES\n");
646
if (WIFEXITED(status)) {
647
acpid_log(LOG_INFO, "action exited with status %d\n",
648
WEXITSTATUS(status));
649
} else if (WIFSIGNALED(status)) {
650
acpid_log(LOG_INFO, "action exited on signal %d\n",
653
acpid_log(LOG_INFO, "action exited with status %d\n",
643
if (WIFEXITED(status)) {
644
acpid_log(LOG_INFO, "action exited with status %d\n",
645
WEXITSTATUS(status));
646
} else if (WIFSIGNALED(status)) {
647
acpid_log(LOG_INFO, "action exited on signal %d\n",
650
acpid_log(LOG_INFO, "action exited with status %d\n",
664
662
int client = rule->action.fd;
666
acpid_log(LOG_INFO, "notifying client %s\n", rule->origin);
665
acpid_log(LOG_INFO, "notifying client %s\n", rule->origin);
668
668
r = safe_write(client, event, strlen(event));
669
669
if (r < 0 && errno == EPIPE) {
670
670
struct ucred cred;
672
acpid_log(LOG_NOTICE, "client has disconnected\n");
672
acpid_log(LOG_NOTICE,
673
"client %s has disconnected\n", rule->origin);
673
674
delist_rule(&client_list, rule);
674
675
ud_get_peercred(rule->action.fd, &cred);
675
676
if (cred.uid != 0) {
736
737
/* handle an event expansion */
737
int size = sizeof(buf) - i;
738
size_t size = sizeof(buf) - i;
738
739
size = snprintf(buf+i, size, "%s", event);