Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * simple ACPI events listener |
| 4 | * |
| 5 | * Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com> |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 8 | */ |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 9 | |
| 10 | //usage:#define acpid_trivial_usage |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 11 | //usage: "[-df] [-c CONFDIR] [-l LOGFILE] [-a ACTIONFILE] [-M MAPFILE] [-e PROC_EVENT_FILE] [-p PIDFILE]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 12 | //usage:#define acpid_full_usage "\n\n" |
| 13 | //usage: "Listen to ACPI events and spawn specific helpers on event arrival\n" |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 14 | //usage: "\n -d Log to stderr, not log file (implies -f)" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 15 | //usage: "\n -f Run in foreground" |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 16 | //usage: "\n -c DIR Config directory [/etc/acpi]" |
| 17 | //usage: "\n -e FILE /proc event file [/proc/acpi/event]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 18 | //usage: "\n -l FILE Log file [/var/log/acpid.log]" |
| 19 | //usage: "\n -p FILE Pid file [/var/run/acpid.pid]" |
| 20 | //usage: "\n -a FILE Action file [/etc/acpid.conf]" |
| 21 | //usage: "\n -M FILE Map file [/etc/acpi.map]" |
| 22 | //usage: IF_FEATURE_ACPID_COMPAT( |
| 23 | //usage: "\n\nAccept and ignore compatibility options -g -m -s -S -v" |
| 24 | //usage: ) |
| 25 | //usage: |
| 26 | //usage:#define acpid_example_usage |
| 27 | //usage: "Without -e option, acpid uses all /dev/input/event* files\n" |
| 28 | //usage: "# acpid\n" |
| 29 | //usage: "# acpid -l /var/log/my-acpi-log\n" |
| 30 | //usage: "# acpid -e /proc/acpi/event\n" |
| 31 | |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 32 | #include "libbb.h" |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 33 | #include <syslog.h> |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 34 | #include <linux/input.h> |
Denys Vlasenko | 6af732b | 2010-07-12 06:20:11 +0200 | [diff] [blame] | 35 | |
Denys Vlasenko | 14bd16a | 2011-07-08 08:49:40 +0200 | [diff] [blame] | 36 | #ifndef EV_SW |
| 37 | # define EV_SW 0x05 |
| 38 | #endif |
| 39 | #ifndef EV_KEY |
| 40 | # define EV_KEY 0x01 |
| 41 | #endif |
| 42 | #ifndef SW_LID |
| 43 | # define SW_LID 0x00 |
| 44 | #endif |
| 45 | #ifndef SW_RFKILL_ALL |
| 46 | # define SW_RFKILL_ALL 0x03 |
| 47 | #endif |
| 48 | #ifndef KEY_POWER |
| 49 | # define KEY_POWER 116 /* SC System Power Down */ |
| 50 | #endif |
| 51 | #ifndef KEY_SLEEP |
| 52 | # define KEY_SLEEP 142 /* SC System Sleep */ |
| 53 | #endif |
| 54 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 55 | enum { |
| 56 | OPT_c = (1 << 0), |
| 57 | OPT_d = (1 << 1), |
| 58 | OPT_e = (1 << 2), |
| 59 | OPT_f = (1 << 3), |
| 60 | OPT_l = (1 << 4), |
Denys Vlasenko | 26777aa | 2010-11-22 23:49:10 +0100 | [diff] [blame] | 61 | OPT_a = (1 << 5), |
| 62 | OPT_M = (1 << 6), |
| 63 | OPT_p = (1 << 7) * ENABLE_FEATURE_PIDFILE, |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct acpi_event { |
| 67 | const char *s_type; |
| 68 | uint16_t n_type; |
| 69 | const char *s_code; |
| 70 | uint16_t n_code; |
| 71 | uint32_t value; |
| 72 | const char *desc; |
| 73 | }; |
| 74 | |
| 75 | static const struct acpi_event f_evt_tab[] = { |
| 76 | { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRF 00000080" }, |
| 77 | { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRB 00000080" }, |
Eric Martin | 5345b8d | 2012-07-07 19:06:50 +0200 | [diff] [blame] | 78 | { "EV_SW", 0x05, "SW_LID", 0x00, 1, "button/lid LID0 00000080" }, |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | struct acpi_action { |
| 82 | const char *key; |
| 83 | const char *action; |
| 84 | }; |
| 85 | |
| 86 | static const struct acpi_action f_act_tab[] = { |
| 87 | { "PWRF", "PWRF/00000080" }, |
| 88 | { "LID0", "LID/00000080" }, |
| 89 | }; |
| 90 | |
| 91 | struct globals { |
| 92 | struct acpi_action *act_tab; |
| 93 | int n_act; |
| 94 | struct acpi_event *evt_tab; |
| 95 | int n_evt; |
| 96 | } FIX_ALIASING; |
| 97 | #define G (*ptr_to_globals) |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 98 | #define act_tab (G.act_tab) |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 99 | #define n_act (G.n_act ) |
| 100 | #define evt_tab (G.evt_tab) |
| 101 | #define n_evt (G.n_evt ) |
| 102 | #define INIT_G() do { \ |
| 103 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
| 104 | } while (0) |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * acpid listens to ACPI events coming either in textual form |
| 108 | * from /proc/acpi/event (though it is marked deprecated, |
| 109 | * it is still widely used and _is_ a standard) or in binary form |
| 110 | * from specified evdevs (just use /dev/input/event*). |
| 111 | * It parses the event to retrieve ACTION and a possible PARAMETER. |
| 112 | * It then spawns /etc/acpi/<ACTION>[/<PARAMETER>] either via run-parts |
| 113 | * (if the resulting path is a directory) or directly. |
| 114 | * If the resulting path does not exist it logs it via perror |
| 115 | * and continues listening. |
| 116 | */ |
| 117 | |
| 118 | static void process_event(const char *event) |
| 119 | { |
| 120 | struct stat st; |
| 121 | char *handler = xasprintf("./%s", event); |
| 122 | const char *args[] = { "run-parts", handler, NULL }; |
| 123 | |
Serj Kalichev | 1eafd44 | 2015-02-23 15:26:47 +0100 | [diff] [blame] | 124 | // log the event |
| 125 | bb_error_msg("%s", event); |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 126 | |
| 127 | // spawn handler |
| 128 | // N.B. run-parts would require scripts to have #!/bin/sh |
| 129 | // handler is directory? -> use run-parts |
| 130 | // handler is file? -> run it directly |
| 131 | if (0 == stat(event, &st)) |
| 132 | spawn((char **)args + (0==(st.st_mode & S_IFDIR))); |
| 133 | else |
| 134 | bb_simple_perror_msg(event); |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 135 | |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 136 | free(handler); |
| 137 | } |
| 138 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 139 | static const char *find_action(struct input_event *ev, const char *buf) |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 140 | { |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 141 | const char *action = NULL; |
| 142 | int i; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 143 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 144 | // map event |
| 145 | for (i = 0; i < n_evt; i++) { |
| 146 | if (ev) { |
| 147 | if (ev->type == evt_tab[i].n_type && ev->code == evt_tab[i].n_code && ev->value == evt_tab[i].value) { |
| 148 | action = evt_tab[i].desc; |
| 149 | break; |
| 150 | } |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 153 | if (buf) { |
Denys Vlasenko | 8dff01d | 2015-03-12 17:48:34 +0100 | [diff] [blame^] | 154 | if (is_prefixed_with(evt_tab[i].desc, buf)) { |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 155 | action = evt_tab[i].desc; |
| 156 | break; |
| 157 | } |
| 158 | } |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 161 | // get action |
| 162 | if (action) { |
| 163 | for (i = 0; i < n_act; i++) { |
| 164 | if (strstr(action, act_tab[i].key)) { |
| 165 | action = act_tab[i].action; |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | } |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 170 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 171 | return action; |
| 172 | } |
| 173 | |
| 174 | static void parse_conf_file(const char *filename) |
| 175 | { |
| 176 | parser_t *parser; |
| 177 | char *tokens[2]; |
| 178 | |
| 179 | parser = config_open2(filename, fopen_for_read); |
| 180 | |
| 181 | if (parser) { |
| 182 | while (config_read(parser, tokens, 2, 2, "# \t", PARSE_NORMAL)) { |
| 183 | act_tab = xrealloc_vector(act_tab, 1, n_act); |
| 184 | act_tab[n_act].key = xstrdup(tokens[0]); |
| 185 | act_tab[n_act].action = xstrdup(tokens[1]); |
| 186 | n_act++; |
| 187 | } |
| 188 | config_close(parser); |
| 189 | } else { |
| 190 | act_tab = (void*)f_act_tab; |
| 191 | n_act = ARRAY_SIZE(f_act_tab); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | static void parse_map_file(const char *filename) |
| 196 | { |
| 197 | parser_t *parser; |
| 198 | char *tokens[6]; |
| 199 | |
| 200 | parser = config_open2(filename, fopen_for_read); |
| 201 | |
| 202 | if (parser) { |
| 203 | while (config_read(parser, tokens, 6, 6, "# \t", PARSE_NORMAL)) { |
| 204 | evt_tab = xrealloc_vector(evt_tab, 1, n_evt); |
| 205 | evt_tab[n_evt].s_type = xstrdup(tokens[0]); |
| 206 | evt_tab[n_evt].n_type = xstrtou(tokens[1], 16); |
| 207 | evt_tab[n_evt].s_code = xstrdup(tokens[2]); |
| 208 | evt_tab[n_evt].n_code = xatou16(tokens[3]); |
| 209 | evt_tab[n_evt].value = xatoi_positive(tokens[4]); |
| 210 | evt_tab[n_evt].desc = xstrdup(tokens[5]); |
| 211 | n_evt++; |
| 212 | } |
| 213 | config_close(parser); |
| 214 | } else { |
| 215 | evt_tab = (void*)f_evt_tab; |
| 216 | n_evt = ARRAY_SIZE(f_evt_tab); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * acpid [-c conf_dir] [-r conf_file ] [-a map_file ] [-l log_file] [-e proc_event_file] |
| 222 | */ |
| 223 | |
| 224 | int acpid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 225 | int acpid_main(int argc UNUSED_PARAM, char **argv) |
| 226 | { |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 227 | int nfd; |
| 228 | int opts; |
| 229 | struct pollfd *pfd; |
| 230 | const char *opt_dir = "/etc/acpi"; |
| 231 | const char *opt_input = "/dev/input/event"; |
| 232 | const char *opt_logfile = "/var/log/acpid.log"; |
| 233 | const char *opt_action = "/etc/acpid.conf"; |
| 234 | const char *opt_map = "/etc/acpi.map"; |
| 235 | #if ENABLE_FEATURE_PIDFILE |
Anthony G. Basile | 12677ac | 2012-12-10 14:49:39 -0500 | [diff] [blame] | 236 | const char *opt_pidfile = CONFIG_PID_FILE_PATH "/acpid.pid"; |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 237 | #endif |
| 238 | |
| 239 | INIT_G(); |
| 240 | |
| 241 | opt_complementary = "df:e--e"; |
Denys Vlasenko | 26777aa | 2010-11-22 23:49:10 +0100 | [diff] [blame] | 242 | opts = getopt32(argv, "c:de:fl:a:M:" IF_FEATURE_PIDFILE("p:") IF_FEATURE_ACPID_COMPAT("g:m:s:S:v"), |
| 243 | &opt_dir, &opt_input, &opt_logfile, &opt_action, &opt_map |
| 244 | IF_FEATURE_PIDFILE(, &opt_pidfile) |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 245 | IF_FEATURE_ACPID_COMPAT(, NULL, NULL, NULL, NULL) |
| 246 | ); |
| 247 | |
| 248 | if (!(opts & OPT_f)) { |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 249 | /* No -f "Foreground", we go to background */ |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 250 | bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); |
| 251 | } |
| 252 | |
| 253 | if (!(opts & OPT_d)) { |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 254 | /* No -d "Debug", we log to log file. |
| 255 | * This includes any output from children. |
| 256 | */ |
Serj Kalichev | 1eafd44 | 2015-02-23 15:26:47 +0100 | [diff] [blame] | 257 | xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_APPEND), STDOUT_FILENO); |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 258 | xdup2(STDOUT_FILENO, STDERR_FILENO); |
| 259 | /* Also, acpid's messages (but not children) will go to syslog too */ |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 260 | openlog(applet_name, LOG_PID, LOG_DAEMON); |
| 261 | logmode = LOGMODE_SYSLOG | LOGMODE_STDIO; |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 262 | } |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 263 | /* else: -d "Debug", log is not redirected */ |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 264 | |
| 265 | parse_conf_file(opt_action); |
| 266 | parse_map_file(opt_map); |
| 267 | |
| 268 | xchdir(opt_dir); |
| 269 | |
Denys Vlasenko | bbf1e3c | 2012-02-05 15:08:08 +0100 | [diff] [blame] | 270 | /* We spawn children but don't wait for them. Prevent zombies: */ |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 271 | bb_signals((1 << SIGCHLD), SIG_IGN); |
Denys Vlasenko | bbf1e3c | 2012-02-05 15:08:08 +0100 | [diff] [blame] | 272 | // If you enable this, (1) explain why, (2) |
| 273 | // make sure while(poll) loop below is still interruptible |
| 274 | // by SIGTERM et al: |
| 275 | //bb_signals(BB_FATAL_SIGS, record_signo); |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 276 | |
| 277 | pfd = NULL; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 278 | nfd = 0; |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 279 | while (1) { |
| 280 | int fd; |
| 281 | char *dev_event; |
| 282 | |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 283 | dev_event = xasprintf((opts & OPT_e) ? "%s" : "%s%u", opt_input, nfd); |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 284 | fd = open(dev_event, O_RDONLY | O_NONBLOCK); |
| 285 | if (fd < 0) { |
| 286 | if (nfd == 0) |
| 287 | bb_simple_perror_msg_and_die(dev_event); |
| 288 | break; |
| 289 | } |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 290 | free(dev_event); |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 291 | pfd = xrealloc_vector(pfd, 1, nfd); |
| 292 | pfd[nfd].fd = fd; |
| 293 | pfd[nfd].events = POLLIN; |
| 294 | nfd++; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 297 | write_pidfile(opt_pidfile); |
| 298 | |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 299 | while (safe_poll(pfd, nfd, -1) > 0) { |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 300 | int i; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 301 | for (i = 0; i < nfd; i++) { |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 302 | const char *event; |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 303 | |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 304 | if (!(pfd[i].revents & POLLIN)) { |
| 305 | if (pfd[i].revents == 0) |
| 306 | continue; /* this fd has nothing */ |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 307 | |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 308 | /* Likely POLLERR, POLLHUP, POLLNVAL. |
| 309 | * Do not listen on this fd anymore. |
| 310 | */ |
| 311 | close(pfd[i].fd); |
| 312 | nfd--; |
| 313 | for (; i < nfd; i++) |
| 314 | pfd[i].fd = pfd[i + 1].fd; |
| 315 | break; /* do poll() again */ |
| 316 | } |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 317 | |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 318 | event = NULL; |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 319 | if (option_mask32 & OPT_e) { |
| 320 | char *buf; |
| 321 | int len; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 322 | |
Denys Vlasenko | 80c5b68 | 2011-05-08 21:21:10 +0200 | [diff] [blame] | 323 | buf = xmalloc_reads(pfd[i].fd, NULL); |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 324 | /* buf = "button/power PWRB 00000080 00000000" */ |
| 325 | len = strlen(buf) - 9; |
| 326 | if (len >= 0) |
| 327 | buf[len] = '\0'; |
| 328 | event = find_action(NULL, buf); |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 329 | free(buf); |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 330 | } else { |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 331 | struct input_event ev; |
| 332 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 333 | if (sizeof(ev) != full_read(pfd[i].fd, &ev, sizeof(ev))) |
| 334 | continue; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 335 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 336 | if (ev.value != 1 && ev.value != 0) |
| 337 | continue; |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 338 | |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 339 | event = find_action(&ev, NULL); |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 340 | } |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 341 | if (!event) |
| 342 | continue; |
Denys Vlasenko | bbf1e3c | 2012-02-05 15:08:08 +0100 | [diff] [blame] | 343 | /* spawn event handler */ |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 344 | process_event(event); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | if (ENABLE_FEATURE_CLEAN_UP) { |
Denys Vlasenko | 982fdaf | 2012-01-09 05:01:25 +0100 | [diff] [blame] | 349 | while (nfd--) |
| 350 | close(pfd[nfd].fd); |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 351 | free(pfd); |
| 352 | } |
Souf Oued | ccb7a43 | 2010-09-26 12:40:05 +0200 | [diff] [blame] | 353 | remove_pidfile(opt_pidfile); |
Denis Vlasenko | d16950d | 2008-11-29 09:05:50 +0000 | [diff] [blame] | 354 | |
| 355 | return EXIT_SUCCESS; |
| 356 | } |