Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux/acpid.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/util-linux/acpid.c
r2725 r3232 7 7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define acpid_trivial_usage 11 //usage: "[-df] [-c CONFDIR] [-l LOGFILE] [-a ACTIONFILE] [-M MAPFILE] [-e PROC_EVENT_FILE] [-p PIDFILE]" 12 //usage:#define acpid_full_usage "\n\n" 13 //usage: "Listen to ACPI events and spawn specific helpers on event arrival\n" 14 //usage: "\n -d Log to stderr, not log file (implies -f)" 15 //usage: "\n -f Run in foreground" 16 //usage: "\n -c DIR Config directory [/etc/acpi]" 17 //usage: "\n -e FILE /proc event file [/proc/acpi/event]" 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 9 32 #include "libbb.h" 10 33 #include <syslog.h> 11 34 #include <linux/input.h> 35 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 12 54 13 55 enum { … … 34 76 { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRF 00000080" }, 35 77 { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRB 00000080" }, 78 { "EV_SW", 0x05, "SW_LID", 0x00, 1, "button/lid LID0 00000080" }, 36 79 }; 37 80 … … 184 227 int acpid_main(int argc UNUSED_PARAM, char **argv) 185 228 { 186 struct input_event ev;187 229 int nfd; 188 230 int opts; … … 194 236 const char *opt_map = "/etc/acpi.map"; 195 237 #if ENABLE_FEATURE_PIDFILE 196 const char *opt_pidfile = "/var/run/acpid.pid";238 const char *opt_pidfile = CONFIG_PID_FILE_PATH "/acpid.pid"; 197 239 #endif 198 240 … … 207 249 208 250 if (!(opts & OPT_f)) { 251 /* No -f "Foreground", we go to background */ 209 252 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); 210 253 } 211 254 212 255 if (!(opts & OPT_d)) { 256 /* No -d "Debug", we log to log file. 257 * This includes any output from children. 258 */ 259 xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO); 260 xdup2(STDOUT_FILENO, STDERR_FILENO); 261 /* Also, acpid's messages (but not children) will go to syslog too */ 213 262 openlog(applet_name, LOG_PID, LOG_DAEMON); 214 263 logmode = LOGMODE_SYSLOG | LOGMODE_STDIO; 215 } else { 216 xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO); 217 } 264 } 265 /* else: -d "Debug", log is not redirected */ 218 266 219 267 parse_conf_file(opt_action); … … 222 270 xchdir(opt_dir); 223 271 272 /* We spawn children but don't wait for them. Prevent zombies: */ 224 273 bb_signals((1 << SIGCHLD), SIG_IGN); 225 bb_signals(BB_FATAL_SIGS, record_signo); 274 // If you enable this, (1) explain why, (2) 275 // make sure while(poll) loop below is still interruptible 276 // by SIGTERM et al: 277 //bb_signals(BB_FATAL_SIGS, record_signo); 226 278 227 279 pfd = NULL; … … 231 283 char *dev_event; 232 284 233 dev_event = xasprintf((opt ion_mask32& OPT_e) ? "%s" : "%s%u", opt_input, nfd);285 dev_event = xasprintf((opts & OPT_e) ? "%s" : "%s%u", opt_input, nfd); 234 286 fd = open(dev_event, O_RDONLY | O_NONBLOCK); 235 287 if (fd < 0) { … … 238 290 break; 239 291 } 292 free(dev_event); 240 293 pfd = xrealloc_vector(pfd, 1, nfd); 241 294 pfd[nfd].fd = fd; … … 246 299 write_pidfile(opt_pidfile); 247 300 248 while ( poll(pfd, nfd, -1) > 0) {301 while (safe_poll(pfd, nfd, -1) > 0) { 249 302 int i; 250 303 for (i = 0; i < nfd; i++) { 251 const char *event = NULL; 252 253 memset(&ev, 0, sizeof(ev)); 254 255 if (!(pfd[i].revents & POLLIN)) 256 continue; 257 304 const char *event; 305 306 if (!(pfd[i].revents & POLLIN)) { 307 if (pfd[i].revents == 0) 308 continue; /* this fd has nothing */ 309 310 /* Likely POLLERR, POLLHUP, POLLNVAL. 311 * Do not listen on this fd anymore. 312 */ 313 close(pfd[i].fd); 314 nfd--; 315 for (; i < nfd; i++) 316 pfd[i].fd = pfd[i + 1].fd; 317 break; /* do poll() again */ 318 } 319 320 event = NULL; 258 321 if (option_mask32 & OPT_e) { 259 322 char *buf; 260 323 int len; 261 324 262 buf = xmalloc_reads(pfd[i].fd, NULL , NULL);325 buf = xmalloc_reads(pfd[i].fd, NULL); 263 326 /* buf = "button/power PWRB 00000080 00000000" */ 264 327 len = strlen(buf) - 9; … … 266 329 buf[len] = '\0'; 267 330 event = find_action(NULL, buf); 331 free(buf); 268 332 } else { 333 struct input_event ev; 334 269 335 if (sizeof(ev) != full_read(pfd[i].fd, &ev, sizeof(ev))) 270 336 continue; … … 277 343 if (!event) 278 344 continue; 279 / / spawn event handler345 /* spawn event handler */ 280 346 process_event(event); 281 347 } … … 283 349 284 350 if (ENABLE_FEATURE_CLEAN_UP) { 285 while (nfd--) { 286 if (pfd[nfd].fd) { 287 close(pfd[nfd].fd); 288 } 289 } 351 while (nfd--) 352 close(pfd[nfd].fd); 290 353 free(pfd); 291 354 }
Note:
See TracChangeset
for help on using the changeset viewer.