Main Page | Class List | File List | Class Members | File Members

acpid.h File Reference

#include <unistd.h>
#include <syslog.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>

Go to the source code of this file.

Defines

#define ACPI_PROCDIR   "/proc/acpi"
#define ACPI_EVENTFILE   ACPI_PROCDIR "/event"
#define ACPI_CONFDIR   "/etc/acpi/events"
#define ACPI_LOGFILE   "/var/log/acpid"
#define ACPI_SOCKETFILE   "/var/run/acpid.socket"
#define ACPI_SOCKETMODE   0666
#define ACPI_MAX_ERRS   5
#define PACKAGE   "acpid"

Functions

int acpid_log (const char *fmt,...)
int acpid_read_conf (const char *confdir)
int acpid_add_client (int client, const char *origin)
int acpid_cleanup_rules (void)
int acpid_handle_event (const char *event)

Variables

int acpid_debug


Define Documentation

#define ACPI_CONFDIR   "/etc/acpi/events"
 

Definition at line 33 of file acpid.h.

#define ACPI_EVENTFILE   ACPI_PROCDIR "/event"
 

Definition at line 32 of file acpid.h.

#define ACPI_LOGFILE   "/var/log/acpid"
 

Definition at line 34 of file acpid.h.

#define ACPI_MAX_ERRS   5
 

Definition at line 37 of file acpid.h.

Referenced by main().

#define ACPI_PROCDIR   "/proc/acpi"
 

Definition at line 31 of file acpid.h.

#define ACPI_SOCKETFILE   "/var/run/acpid.socket"
 

Definition at line 35 of file acpid.h.

#define ACPI_SOCKETMODE   0666
 

Definition at line 36 of file acpid.h.

#define PACKAGE   "acpid"
 

Definition at line 39 of file acpid.h.

Referenced by handle_cmdline().


Function Documentation

int acpid_add_client int  client,
const char *  origin
 

Definition at line 313 of file event.c.

References acpid_log(), enlist_rule(), rule::origin, and parse_client().

Referenced by main().

00314 {
00315         struct rule *r;
00316         int nrules = 0;
00317 
00318         acpid_log("client connected from %s\n", origin);
00319 
00320         r = parse_client(clifd);
00321         if (r) {
00322                 r->origin = strdup(origin);
00323                 enlist_rule(&client_list, r);
00324                 nrules++;
00325         }
00326 
00327         acpid_log("%d client rule%s loaded\n", nrules, (nrules == 1)?"":"s");
00328 
00329         return 0;
00330 }

int acpid_cleanup_rules void   ) 
 

Definition at line 157 of file event.c.

References acpid_debug, acpid_log(), rule::action, delist_rule(), free_rule(), rule_list::head, lock_rules(), rule::next, and unlock_rules().

Referenced by clean_exit(), and reload_conf().

00158 {
00159         struct rule *p;
00160         struct rule *next;
00161 
00162         lock_rules();
00163 
00164         if (acpid_debug >= 3) {
00165                 acpid_log("DBG: cleaning up rules\n");
00166         }
00167 
00168         /* tell our clients to buzz off */
00169         p = client_list.head;
00170         while (p) {
00171                 next = p->next;
00172                 delist_rule(&client_list, p);
00173                 close(p->action.fd);
00174                 free_rule(p);
00175                 p = next;
00176         }
00177 
00178         /* clear out our conf rules */
00179         p = cmd_list.head;
00180         while (p) {
00181                 next = p->next;
00182                 delist_rule(&cmd_list, p);
00183                 free_rule(p);
00184                 p = next;
00185         }
00186 
00187         unlock_rules();
00188 
00189         return 0;
00190 }

int acpid_handle_event const char *  event  ) 
 

Definition at line 443 of file event.c.

References acpid_debug, acpid_log(), do_client_rule(), do_cmd_rule(), rule::event, rule_list::head, lock_rules(), rule::next, rule::origin, rule::RULE_CLIENT, rule::RULE_CMD, rule::type, and unlock_rules().

Referenced by main().

00444 {
00445         struct rule *p;
00446         int nrules = 0;
00447         struct rule_list *ar[] = { &client_list, &cmd_list, NULL };
00448         struct rule_list **lp;
00449 
00450         /* make an event be atomic wrt known signals */
00451         lock_rules();
00452 
00453         /* scan each rule list for any rules that care about this event */
00454         for (lp = ar; *lp; lp++) {
00455                 struct rule_list *l = *lp;
00456                 p = l->head;
00457                 while (p) {
00458                         /* the list can change underneath us */
00459                         struct rule *pnext = p->next;
00460                         if (!regexec(p->event, event, 0, NULL, 0)) {
00461                                 /* a match! */
00462                                 if (acpid_debug) {
00463                                         acpid_log("DBG: rule from %s matched\n",
00464                                                 p->origin);
00465                                 }
00466                                 nrules++;
00467                                 if (p->type == RULE_CMD) {
00468                                         do_cmd_rule(p, event);
00469                                 } else if (p->type == RULE_CLIENT) {
00470                                         do_client_rule(p, event);
00471                                 } else {
00472                                         acpid_log("unknown rule type: %d\n",
00473                                                 p->type);
00474                                 }
00475                         } else {
00476                                 if (acpid_debug >= 3) {
00477                                         acpid_log("DBG: rule from %s did not "
00478                                                 "match\n", p->origin);
00479                                 }
00480                         }
00481                         p = pnext;
00482                 }
00483         }
00484 
00485         unlock_rules();
00486 
00487         if (acpid_debug) {
00488                 acpid_log("DBG: %d total rule%s matched\n",
00489                         nrules, (nrules == 1)?"":"s");
00490         }
00491 
00492         return 0;
00493 }

int acpid_log const char *  fmt,
  ...
 

Definition at line 450 of file acpid.c.

Referenced by acpid_add_client(), acpid_cleanup_rules(), acpid_handle_event(), acpid_read_conf(), check_escapes(), clean_exit(), do_client_rule(), do_cmd_rule(), lock_rules(), main(), new_rule(), parse_client(), parse_cmd(), parse_file(), path_is_dir(), read_line(), reload_conf(), safe_write(), and unlock_rules().

00451 {
00452         va_list args;
00453         int len = 0;
00454         time_t curtime;
00455         char *timestr;
00456 
00457         va_start(args, fmt);
00458         curtime = time(NULL);
00459         timestr = ctime(&curtime);
00460         timestr[strlen(timestr)-1] = '\0';
00461         len += fprintf(stderr, "[%s] ", timestr);
00462         len += vfprintf(stderr, fmt, args);
00463         va_end(args);
00464 
00465         return 0;
00466 }

int acpid_read_conf const char *  confdir  ) 
 

Definition at line 99 of file event.c.

References acpid_log(), enlist_rule(), lock_rules(), parse_file(), path_is_dir(), and unlock_rules().

Referenced by main(), and reload_conf().

00100 {
00101         DIR *dir;
00102         struct dirent *dirent;
00103         char *file = NULL;
00104         int nrules = 0;
00105 
00106         lock_rules();
00107 
00108         dir = opendir(confdir);
00109         if (!dir) {
00110                 acpid_log("ERR: opendir(%s): %s\n",
00111                         confdir, strerror(errno));
00112                 unlock_rules();
00113                 return -1;
00114         }
00115 
00116         /* scan all the files */
00117         while ((dirent = readdir(dir))) {
00118                 int len;
00119                 struct rule *r;
00120 
00121                 if (dirent->d_name[0] == '.')
00122                         continue; /* skip dotfiles */
00123 
00124                 len = strlen(dirent->d_name) + strlen(confdir) + 2;
00125                 file = (char *)malloc(len);
00126                 if (!file) {
00127                         acpid_log("ERR: malloc(): %s\n", strerror(errno));
00128                         unlock_rules();
00129                         return -1;
00130                 }
00131                 snprintf(file, len, "%s/%s", confdir, dirent->d_name);
00132 
00133                 if (path_is_dir(file)) {
00134                         free(file);
00135                         continue; /* skip subdirs */
00136                 }
00137 
00138                 r = parse_file(file);
00139                 if (r) {
00140                         enlist_rule(&cmd_list, r);
00141                         nrules++;
00142                 }
00143                 free(file);
00144         }
00145         closedir(dir);
00146         unlock_rules();
00147 
00148         acpid_log("%d rule%s loaded\n", nrules, (nrules == 1)?"":"s");
00149 
00150         return 0;
00151 }


Variable Documentation

int acpid_debug
 

Definition at line 48 of file acpid.c.

Referenced by acpid_cleanup_rules(), acpid_handle_event(), handle_cmdline(), lock_rules(), main(), parse_cmd(), parse_file(), safe_write(), and unlock_rules().


© sourcejam.com 2005-2008