acpid
PATCH 1/1 acpid
Hi
Well, PATCHES speak better then me,
1 - sample.conf make power button works is very useful when a machine hangs if power button send event we can shutdown machine without abrupt power off
2 - acpid.init and acpid.spec updated with work of Redhat/Fedora guys.
3 - I don't know if you know but just in case, redhat modify your source and eliminated all stuff about "Check that the kernel supports the proper semantics, or die.". I don't know if it is because knows that kernel are updated or if reads with other technique, anyway it is working on Fedora core 1.
thanks,
Signature · 1 line
Sérgio M. B.
acpid.c +91 -132
@@ -61,6 +61,8 @@ {int event_fd;int sock_fd; +int max_fd_num; +fd_set readfds, testfds;/* learn who we really are */ progname = (const char *)strrchr (argv[0 ],'/' );
@@ -78,39 +80,6 @@ }fcntl (event_fd,F_SETFD ,FD_CLOEXEC ); -/* -* if there is data, and the kernel is NOT broken, this eats 1 byte. We -* can't have that. This is ifdef'ed out on the assumption that old kernels -* are out of popular use, by now. -*/ -#ifdef TEST_FOR_BAD_KERNELS -/* -* Older kernels did not support read() properly or poll() at all -* Check that the kernel supports the proper semantics, or die. -* -* Good kernels will respect O_NONBLOCK and return -1. Bad kernels -* will ignore O_NONBLOCK and return 0. Really bad kernels will block -* and overflow the buffer. Can't deal with the really bad ones. -*/ - { -int fl; -char buf; - - fl =fcntl (event_fd,F_GETFL ); -fcntl (event_fd,F_SETFL , fl |O_NONBLOCK ); -if (read (event_fd, &buf,1 ) ==0 ) { -fprintf (stderr, -"%s: this kernel does not support proper " -"event file handling.\n" -"Please get the patch from " -"http://acpid.sourceforge.net\n" , - progname); -exit (EXIT_FAILURE ); - } -fcntl (event_fd,F_SETFL , fl); - } -#endif -/* open our socket */ if (!nosocket) { sock_fd =ud_create_socket (socketfile);
@@ -166,77 +135,83 @@/* read in our configuration */ acpid_read_conf (confdir); +/* setup the fds for select() */ + max_fd_num = ((event_fd > sock_fd)?event_fd:sock_fd); +FD_ZERO (&readfds); +FD_SET (event_fd, &readfds); +FD_SET (sock_fd, &readfds); +/* main loop */ while (1 ) { -struct pollfd ar[2 ];int r;int fds =0 ; - -/* poll for the socket and the event file */ - ar[0 ].fd = event_fd; ar[0 ].events =POLLIN ; fds++; -if (!nosocket) { - ar[1 ].fd = sock_fd; ar[1 ].events =POLLIN ; fds++; - } - r =poll (ar, fds,-1 ); - -if (r <0 && errno ==EINTR ) { -continue ; - }else if (r <0 ) { -acpid_log ("ERR: poll(): %s\n" ,strerror (errno)); -continue ; - } - -/* was it an event? */ -if (ar[0 ].revents) { -char *event; - -/* this shouldn't happen */ -if (!ar[0 ].revents &POLLIN ) { -acpid_log ("odd, poll set flags 0x%x\n" , - ar[0 ].revents); -continue ; - } -/* read and handle an event */ - event =read_line (event_fd); -if (event) { -acpid_log ("received event \"%s\"\n" , event); -acpid_handle_event (event); -acpid_log ("completed event \"%s\"\n" , event); - }else { -static int nerrs; -if (++nerrs >=ACPI_MAX_ERRS ) { -acpid_log ("too many errors reading " -"events file - aborting\n" ); -break ; - } - } - } - -/* was it a new connection? */ -if (!nosocket && ar[1 ].revents) { -int cli_fd; -struct ucred creds; -char buf[32 ]; - -/* this shouldn't happen */ -if (!ar[1 ].revents &POLLIN ) { -acpid_log ("odd, poll set flags 0x%x\n" , - ar[1 ].revents); -continue ; - } - -/* accept and add to our lists */ - cli_fd =ud_accept (sock_fd, &creds); -if (cli_fd <0 ) { -acpid_log ("ERR: can't accept client: %s\n" , -strerror (errno)); -continue ; - } -snprintf (buf,sizeof (buf)-1 ,"%d[%d:%d]" , - creds.pid, creds.uid, creds.gid); -acpid_add_client (cli_fd, buf); - } +/* wait until somebody has some input for us */ + testfds = readfds; + r =select (max_fd_num +1 , &testfds,NULL ,NULL ,NULL ); + +/* check for error conditions */ +if (r <0 ) +switch (errno) { +case EINVAL : +case EBADF : +/* we shouldn't be here */ +acpid_log ("unrecoverable internal error with select()\n" ); +clean_exit (errno); +break ; +case EINTR : +default : +/* just go back to waiting */ +continue ; +break ; + } + +/* handle the fds that have input */ +while (r >0 ) { +/* see if the fd is set */ +if (FD_ISSET (fds, &testfds)) { +/* one less to handle */ + r--; + +if (fds == event_fd) { +/* read an acpi event */ +char *event; + + event =read_line (event_fd); +if (event) { +acpid_log ("received event \"%s\"\n" , event); +acpid_handle_event (event); +acpid_log ("completed event \"%s\"\n" , event); + }else { +static int nerrs; +if (++nerrs >=ACPI_MAX_ERRS ) { +acpid_log ("too many errors reading " +"events file - aborting\n" ); +break ; + } + } + } +if (fds == sock_fd) { +/* a client is trying to connect */ +int cli_fd; +struct ucred creds; +char buf[32 ]; + + cli_fd =ud_accept (sock_fd, &creds); +if (cli_fd <0 ) { +acpid_log ("ERR: can't accept client: %s\n" , +strerror (errno)); +continue ; + } +snprintf (buf,sizeof (buf)-1 ,"%d[%d:%d]" , + creds.pid, creds.uid, creds.gid); +acpid_add_client (cli_fd, buf); + } + } + +/* next */ + fds++; + } }clean_exit (EXIT_SUCCESS );
@@ -450,43 +425,27 @@* This depends on fixes in linux ACPI after 2.4.8 */ #define MAX_BUFLEN 1024 +static char *read_line (int fd) { -static char *buf; -int buflen =64 ; -int i =0 ; -int r; -int searching =1 ; - -while (searching) { - buf =realloc (buf, buflen); -if (!buf) { -acpid_log ("ERR: malloc(%d): %s\n" , - buflen,strerror (errno)); -return NULL ; - } -memset (buf+i,0 , buflen-i); +static char buf[MAX_BUFLEN ] ="" ; +int r =0 ; -while (i < buflen) { - r =read (fd, buf+i,1 ); -if (r <0 && errno !=EINTR ) { -/* we should do something with the data */ -return NULL ; - }else if (r ==1 ) { -if (buf[i] =='\n' ) { - searching =0 ; - buf[i] ='\0' ; -break ; - } - i++; - } - } -if (buflen >=MAX_BUFLEN ) { -break ; - } - buflen *=2 ; - } +/* get a buffer full of data */ +while (r ==0 ) + { + r =read (fd, buf,MAX_BUFLEN -1 ); + +if (r ==0 ) +continue ; +else if (r <0 ) +return NULL ; + } + +/* strip eol */ +if (buf[r -1 ] =='\n' ) + buf[r -1 ] ='\0' ;return buf; }
acpid-1.0.3.spec +134 -0
134 lines not on this page · raw message
Changelog +4 -0
@@ -1,4 +1,8 @@ %changelog +* Sun May 30 2004 Sérgio Basto <[email protected]> + - with acpid-1.0.2-5.src.rpm from Fedora Core 1, rebuild redhat dir + - put 'make rpm' again + * Fri Feb 13 2004 Tim Hockin <[email protected]> - dump debian/ and redhat/ dirs -- too much hassle - change 'make rpm' to 'make dist'
Makefile +18 -0
@@ -2,6 +2,7 @@ # update these numbers for new releases VERSION = 1.0.3 +RELEASE = 1 INSTPREFIX = BINDIR = $(INSTPREFIX)/usr/bin
@@ -36,6 +37,7 @@ install: $(PROGS) man mkdir -p $(SBINDIR) install -m 750 acpid $(SBINDIR) + mkdir -p $(BINDIR) install -m 755 acpi_listen $(BINDIR) mkdir -p $(MAN8DIR) install -m 644 $(MAN8GZ) $(MAN8DIR)
@@ -50,6 +52,22 @@ tar -C $(DISTTMP) -zcvf acpid-$(VERSION).tar.gz acpid-$(VERSION) rm -rf $(DISTTMP)/acpid-$(VERSION) +RPMTMP=/tmp +rpm: + make clean + rm -rf $(RPMTMP)/acpid-$(VERSION) + mkdir -p $(RPMTMP)/acpid-$(VERSION) + sed -e 's/@@RPMVER@@/$(VERSION)/' -e 's/@@RPMREL@@/$(RELEASE)/' \ + redhat/acpid.spec.in > acpid-$(VERSION).spec + cat Changelog >> acpid-$(VERSION).spec + cp -a * $(RPMTMP)/acpid-$(VERSION) + find $(RPMTMP)/acpid-$(VERSION) -type d -name CVS | xargs rm -rf + tar -C $(RPMTMP) -zcvf $(RPMTMP)/acpid-$(VERSION).tar.gz \ + acpid-$(VERSION) + rpmbuild -ta $(RPMTMP)/acpid-$(VERSION).tar.gz + rm -rf $(RPMTMP)/acpid-$(VERSION) + rm -rf $(RPMTMP)/acpid-$(VERSION).tar.gz + clean: $(RM) $(PROGS) $(MAN8GZ) *.o
redhat/acpid.init +83 -0
83 lines not on this page · raw message
redhat/acpid.spec.in +73 -0
73 lines not on this page · raw message
samples/sample.conf +2 -2
@@ -1,4 +1,4 @@ # This is a sample ACPID configuration -# event=button power.* -# action=/usr/local/bin/power.sh "%e" +event=button/power.* +action=/sbin/shutdown -h now