|
Zdenek Prikryl |
ab8f3c |
diff -up acpid-1.0.6/acpid.8.socket acpid-1.0.6/acpid.8
|
|
Zdenek Prikryl |
ab8f3c |
--- acpid-1.0.6/acpid.8.socket 2007-05-25 06:35:31.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
+++ acpid-1.0.6/acpid.8 2009-05-27 08:06:52.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
@@ -57,6 +57,10 @@ All the default file and directories can
|
|
Zdenek Prikryl |
ab8f3c |
This option changes the directory in which \fBacpid\fP looks for rule
|
|
Zdenek Prikryl |
ab8f3c |
configuration files. Default is \fI/etc/acpi/events\fP.
|
|
Zdenek Prikryl |
ab8f3c |
.TP 12
|
|
Zdenek Prikryl |
ab8f3c |
+.BI \-C "\fR, \fP" \--clientmax " number"
|
|
Zdenek Prikryl |
ab8f3c |
+This option changes the maximum number of non-root socket connections which
|
|
Zdenek Prikryl |
ab8f3c |
+can be made to the \fBacpid\fP socket. Default is \fI256\fP.
|
|
Zdenek Prikryl |
ab8f3c |
+.TP 12
|
|
Zdenek Prikryl |
ab8f3c |
.BI \-d "\fR, \fP" \--debug
|
|
Zdenek Prikryl |
ab8f3c |
This option increases the \fBacpid\fP debug level by one. If the debug level
|
|
Zdenek Prikryl |
ab8f3c |
is non-zero, \fBacpid\fP will run in the foreground, and will log to
|
|
Zdenek Prikryl |
ab8f3c |
diff -up acpid-1.0.6/acpid.c.socket acpid-1.0.6/acpid.c
|
|
Zdenek Prikryl |
ab8f3c |
--- acpid-1.0.6/acpid.c.socket 2009-05-27 08:06:43.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
+++ acpid-1.0.6/acpid.c 2009-05-27 08:14:32.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
@@ -43,12 +43,16 @@ static void close_fds(void);
|
|
Zdenek Prikryl |
ab8f3c |
static int daemonize(void);
|
|
Zdenek Prikryl |
ab8f3c |
static int open_log(void);
|
|
Zdenek Prikryl |
ab8f3c |
static void clean_exit(int sig);
|
|
Zdenek Prikryl |
ab8f3c |
+static void clean_exit_with_status(int status);
|
|
Zdenek Prikryl |
ab8f3c |
static void reload_conf(int sig);
|
|
Zdenek Prikryl |
ab8f3c |
static char *read_line(int fd);
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
/* global debug level */
|
|
Zdenek Prikryl |
ab8f3c |
int acpid_debug;
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
+/* the number of non-root clients that are connected */
|
|
Zdenek Prikryl |
ab8f3c |
+int non_root_clients;
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
static const char *progname;
|
|
Zdenek Prikryl |
ab8f3c |
static const char *confdir = ACPI_CONFDIR;
|
|
Zdenek Prikryl |
ab8f3c |
static const char *eventfile = ACPI_EVENTFILE;
|
|
Zdenek Prikryl |
ab8f3c |
@@ -57,6 +61,7 @@ static int nosocket;
|
|
Zdenek Prikryl |
ab8f3c |
static const char *socketgroup;
|
|
Zdenek Prikryl |
ab8f3c |
static mode_t socketmode = ACPI_SOCKETMODE;
|
|
Zdenek Prikryl |
ab8f3c |
static int foreground;
|
|
Zdenek Prikryl |
ab8f3c |
+static int clientmax = ACPID_CLIENTMAX;
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
int
|
|
Zdenek Prikryl |
ab8f3c |
main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
@@ -77,7 +82,7 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
/* actually open the event file */
|
|
Zdenek Prikryl |
ab8f3c |
event_fd = open(eventfile, O_RDONLY);
|
|
Zdenek Prikryl |
ab8f3c |
if (event_fd < 0) {
|
|
Zdenek Prikryl |
ab8f3c |
- fprintf(stderr, "%s: can't open %s: %s\n", progname,
|
|
Zdenek Prikryl |
ab8f3c |
+ fprintf(stderr, "%s: can't open %s: %s\n", progname,
|
|
Zdenek Prikryl |
ab8f3c |
eventfile, strerror(errno));
|
|
Zdenek Prikryl |
ab8f3c |
exit(EXIT_FAILURE);
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
@@ -104,11 +109,11 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
fl = fcntl(event_fd, F_GETFL);
|
|
Zdenek Prikryl |
ab8f3c |
fcntl(event_fd, F_SETFL, fl | O_NONBLOCK);
|
|
Zdenek Prikryl |
ab8f3c |
if (read(event_fd, &buf, 1) == 0) {
|
|
Zdenek Prikryl |
ab8f3c |
- fprintf(stderr,
|
|
Zdenek Prikryl |
ab8f3c |
+ fprintf(stderr,
|
|
Zdenek Prikryl |
ab8f3c |
"%s: this kernel does not support proper "
|
|
Zdenek Prikryl |
ab8f3c |
"event file handling.\n"
|
|
Zdenek Prikryl |
ab8f3c |
"Please get the patch from "
|
|
Zdenek Prikryl |
ab8f3c |
- "http://acpid.sourceforge.net\n",
|
|
Zdenek Prikryl |
ab8f3c |
+ "http://acpid.sourceforge.net\n",
|
|
Zdenek Prikryl |
ab8f3c |
progname);
|
|
Zdenek Prikryl |
ab8f3c |
exit(EXIT_FAILURE);
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
@@ -175,7 +180,7 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
struct pollfd ar[2];
|
|
Zdenek Prikryl |
ab8f3c |
int r;
|
|
Zdenek Prikryl |
ab8f3c |
int fds = 0;
|
|
Zdenek Prikryl |
ab8f3c |
-
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
/* poll for the socket and the event file */
|
|
Zdenek Prikryl |
ab8f3c |
ar[0].fd = event_fd; ar[0].events = POLLIN; fds++;
|
|
Zdenek Prikryl |
ab8f3c |
if (!nosocket) {
|
|
Zdenek Prikryl |
ab8f3c |
@@ -190,10 +195,13 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
continue;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
+ /* house keeping */
|
|
Zdenek Prikryl |
ab8f3c |
+ acpid_close_dead_clients();
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
/* was it an event? */
|
|
Zdenek Prikryl |
ab8f3c |
if (ar[0].revents) {
|
|
Zdenek Prikryl |
ab8f3c |
char *event;
|
|
Zdenek Prikryl |
ab8f3c |
-
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
/* this shouldn't happen */
|
|
Zdenek Prikryl |
ab8f3c |
if (!ar[0].revents & POLLIN) {
|
|
Zdenek Prikryl |
ab8f3c |
acpid_log(LOG_DEBUG,
|
|
Zdenek Prikryl |
ab8f3c |
@@ -227,13 +235,14 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
break;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
- }
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
/* was it a new connection? */
|
|
Zdenek Prikryl |
ab8f3c |
if (!nosocket && ar[1].revents) {
|
|
Zdenek Prikryl |
ab8f3c |
int cli_fd;
|
|
Zdenek Prikryl |
ab8f3c |
struct ucred creds;
|
|
Zdenek Prikryl |
ab8f3c |
char buf[32];
|
|
Zdenek Prikryl |
ab8f3c |
+ static int accept_errors;
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
/* this shouldn't happen */
|
|
Zdenek Prikryl |
ab8f3c |
if (!ar[1].revents & POLLIN) {
|
|
Zdenek Prikryl |
ab8f3c |
@@ -248,8 +257,23 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
if (cli_fd < 0) {
|
|
Zdenek Prikryl |
ab8f3c |
acpid_log(LOG_ERR, "can't accept client: %s\n",
|
|
Zdenek Prikryl |
ab8f3c |
strerror(errno));
|
|
Zdenek Prikryl |
ab8f3c |
+ accept_errors++;
|
|
Zdenek Prikryl |
ab8f3c |
+ if (accept_errors >= 5) {
|
|
Zdenek Prikryl |
ab8f3c |
+ acpid_log(LOG_ERR, "giving up\n");
|
|
Zdenek Prikryl |
ab8f3c |
+ clean_exit_with_status(EXIT_FAILURE);
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
+ continue;
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
+ accept_errors = 0;
|
|
Zdenek Prikryl |
ab8f3c |
+ if (creds.uid != 0 && non_root_clients >= clientmax) {
|
|
Zdenek Prikryl |
ab8f3c |
+ close(cli_fd);
|
|
Zdenek Prikryl |
ab8f3c |
+ acpid_log(LOG_ERR,
|
|
Zdenek Prikryl |
ab8f3c |
+ "too many non-root clients\n");
|
|
Zdenek Prikryl |
ab8f3c |
continue;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
+ if (creds.uid != 0) {
|
|
Zdenek Prikryl |
ab8f3c |
+ non_root_clients++;
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
fcntl(cli_fd, F_SETFD, FD_CLOEXEC);
|
|
Zdenek Prikryl |
ab8f3c |
snprintf(buf, sizeof(buf)-1, "%d[%d:%d]",
|
|
Zdenek Prikryl |
ab8f3c |
creds.pid, creds.uid, creds.gid);
|
|
Zdenek Prikryl |
ab8f3c |
@@ -257,7 +281,7 @@ main(int argc, char **argv)
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
- clean_exit(EXIT_SUCCESS);
|
|
Zdenek Prikryl |
ab8f3c |
+ clean_exit_with_status(EXIT_SUCCESS);
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
return 0;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
@@ -270,6 +294,7 @@ handle_cmdline(int *argc, char ***argv)
|
|
Zdenek Prikryl |
ab8f3c |
{
|
|
Zdenek Prikryl |
ab8f3c |
struct option opts[] = {
|
|
Zdenek Prikryl |
ab8f3c |
{"confdir", 1, 0, 'c'},
|
|
Zdenek Prikryl |
ab8f3c |
+ {"clientmax", 1, 0, 'C'},
|
|
Zdenek Prikryl |
ab8f3c |
{"debug", 0, 0, 'd'},
|
|
Zdenek Prikryl |
ab8f3c |
{"eventfile", 1, 0, 'e'},
|
|
Zdenek Prikryl |
ab8f3c |
{"foreground", 0, 0, 'f'},
|
|
Zdenek Prikryl |
ab8f3c |
@@ -283,6 +308,7 @@ handle_cmdline(int *argc, char ***argv)
|
|
Zdenek Prikryl |
ab8f3c |
};
|
|
Zdenek Prikryl |
ab8f3c |
const char *opts_help[] = {
|
|
Zdenek Prikryl |
ab8f3c |
"Set the configuration directory.", /* confdir */
|
|
Zdenek Prikryl |
ab8f3c |
+ "Set the limit on non-root socket connections.",/* clientmax */
|
|
Zdenek Prikryl |
ab8f3c |
"Increase debugging level (implies -f).",/* debug */
|
|
Zdenek Prikryl |
ab8f3c |
"Use the specified file for events.", /* eventfile */
|
|
Zdenek Prikryl |
ab8f3c |
"Run in the foreground.", /* foreground */
|
|
Zdenek Prikryl |
ab8f3c |
@@ -299,7 +325,7 @@ handle_cmdline(int *argc, char ***argv)
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
for (;;) {
|
|
Zdenek Prikryl |
ab8f3c |
int i;
|
|
Zdenek Prikryl |
ab8f3c |
- i = getopt_long(*argc, *argv, "c:de:fg:m:s:Svh", opts, NULL);
|
|
Zdenek Prikryl |
ab8f3c |
+ i = getopt_long(*argc, *argv, "c:C:de:fg:m:s:Svh", opts, NULL);
|
|
Zdenek Prikryl |
ab8f3c |
if (i == -1) {
|
|
Zdenek Prikryl |
ab8f3c |
break;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
@@ -307,6 +333,9 @@ handle_cmdline(int *argc, char ***argv)
|
|
Zdenek Prikryl |
ab8f3c |
case 'c':
|
|
Zdenek Prikryl |
ab8f3c |
confdir = optarg;
|
|
Zdenek Prikryl |
ab8f3c |
break;
|
|
Zdenek Prikryl |
ab8f3c |
+ case 'C':
|
|
Zdenek Prikryl |
ab8f3c |
+ clientmax = strtol(optarg, NULL, 0);
|
|
Zdenek Prikryl |
ab8f3c |
+ break;
|
|
Zdenek Prikryl |
ab8f3c |
case 'd':
|
|
Zdenek Prikryl |
ab8f3c |
foreground = 1;
|
|
Zdenek Prikryl |
ab8f3c |
acpid_debug++;
|
|
Zdenek Prikryl |
ab8f3c |
@@ -404,7 +433,7 @@ open_log(void)
|
|
Zdenek Prikryl |
ab8f3c |
/* open /dev/null */
|
|
Zdenek Prikryl |
ab8f3c |
nullfd = open("/dev/null", O_RDONLY);
|
|
Zdenek Prikryl |
ab8f3c |
if (nullfd < 0) {
|
|
Zdenek Prikryl |
ab8f3c |
- fprintf(stderr, "%s: can't open %s: %s\n", progname,
|
|
Zdenek Prikryl |
ab8f3c |
+ fprintf(stderr, "%s: can't open %s: %s\n", progname,
|
|
Zdenek Prikryl |
ab8f3c |
"/dev/null", strerror(errno));
|
|
Zdenek Prikryl |
ab8f3c |
return -1;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
@@ -435,11 +464,17 @@ open_log(void)
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
static void
|
|
Zdenek Prikryl |
ab8f3c |
-clean_exit(int sig)
|
|
Zdenek Prikryl |
ab8f3c |
+clean_exit_with_status(int status)
|
|
Zdenek Prikryl |
ab8f3c |
{
|
|
Zdenek Prikryl |
ab8f3c |
acpid_cleanup_rules(1);
|
|
Zdenek Prikryl |
ab8f3c |
acpid_log(LOG_NOTICE, "exiting\n");
|
|
Zdenek Prikryl |
ab8f3c |
- exit(EXIT_SUCCESS);
|
|
Zdenek Prikryl |
ab8f3c |
+ exit(status);
|
|
Zdenek Prikryl |
ab8f3c |
+}
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+static void
|
|
Zdenek Prikryl |
ab8f3c |
+clean_exit(int sig __attribute__((unused)))
|
|
Zdenek Prikryl |
ab8f3c |
+{
|
|
Zdenek Prikryl |
ab8f3c |
+ clean_exit_with_status(EXIT_SUCCESS);
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
static void
|
|
Zdenek Prikryl |
ab8f3c |
@@ -450,7 +485,7 @@ reload_conf(int sig)
|
|
Zdenek Prikryl |
ab8f3c |
acpid_read_conf(confdir);
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
-int
|
|
Zdenek Prikryl |
ab8f3c |
+int
|
|
Zdenek Prikryl |
ab8f3c |
acpid_log(int level, const char *fmt, ...)
|
|
Zdenek Prikryl |
ab8f3c |
{
|
|
Zdenek Prikryl |
ab8f3c |
va_list args;
|
|
Zdenek Prikryl |
ab8f3c |
@@ -462,7 +497,7 @@ acpid_log(int level, const char *fmt, ..
|
|
Zdenek Prikryl |
ab8f3c |
return 0;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
-/*
|
|
Zdenek Prikryl |
ab8f3c |
+/*
|
|
Zdenek Prikryl |
ab8f3c |
* This depends on fixes in linux ACPI after 2.4.8
|
|
Zdenek Prikryl |
ab8f3c |
*/
|
|
Zdenek Prikryl |
ab8f3c |
#define MAX_BUFLEN 1024
|
|
Zdenek Prikryl |
ab8f3c |
@@ -507,7 +542,7 @@ read_line(int fd)
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
if (buflen >= MAX_BUFLEN) {
|
|
Zdenek Prikryl |
ab8f3c |
break;
|
|
Zdenek Prikryl |
ab8f3c |
- }
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
buflen *= 2;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
diff -up acpid-1.0.6/acpid.h.socket acpid-1.0.6/acpid.h
|
|
Zdenek Prikryl |
ab8f3c |
--- acpid-1.0.6/acpid.h.socket 2007-05-24 08:33:33.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
+++ acpid-1.0.6/acpid.h 2009-05-27 08:11:07.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
@@ -34,6 +34,7 @@
|
|
Zdenek Prikryl |
ab8f3c |
#define ACPI_CONFDIR "/etc/acpi/events"
|
|
Zdenek Prikryl |
ab8f3c |
#define ACPI_SOCKETFILE "/var/run/acpid.socket"
|
|
Zdenek Prikryl |
ab8f3c |
#define ACPI_SOCKETMODE 0666
|
|
Zdenek Prikryl |
ab8f3c |
+#define ACPID_CLIENTMAX 256
|
|
Zdenek Prikryl |
ab8f3c |
#define ACPI_MAX_ERRS 5
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
#define PACKAGE "acpid"
|
|
Zdenek Prikryl |
ab8f3c |
@@ -42,6 +43,7 @@
|
|
Zdenek Prikryl |
ab8f3c |
* acpid.c
|
|
Zdenek Prikryl |
ab8f3c |
*/
|
|
Zdenek Prikryl |
ab8f3c |
extern int acpid_debug;
|
|
Zdenek Prikryl |
ab8f3c |
+extern int non_root_clients;
|
|
Zdenek Prikryl |
ab8f3c |
extern int acpid_log(int level, const char *fmt, ...);
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
/*
|
|
Zdenek Prikryl |
ab8f3c |
@@ -51,5 +53,6 @@ extern int acpid_read_conf(const char *c
|
|
Zdenek Prikryl |
ab8f3c |
extern int acpid_add_client(int client, const char *origin);
|
|
Zdenek Prikryl |
ab8f3c |
extern int acpid_cleanup_rules(int do_detach);
|
|
Zdenek Prikryl |
ab8f3c |
extern int acpid_handle_event(const char *event);
|
|
Zdenek Prikryl |
ab8f3c |
+extern void acpid_close_dead_clients(void);
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
#endif /* ACPID_H__ */
|
|
Zdenek Prikryl |
ab8f3c |
diff -up acpid-1.0.6/event.c.socket acpid-1.0.6/event.c
|
|
Zdenek Prikryl |
ab8f3c |
--- acpid-1.0.6/event.c.socket 2009-05-27 08:06:43.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
+++ acpid-1.0.6/event.c 2009-05-27 08:10:07.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
@@ -23,6 +23,7 @@
|
|
Zdenek Prikryl |
ab8f3c |
#include <sys/types.h>
|
|
Zdenek Prikryl |
ab8f3c |
#include <sys/stat.h>
|
|
Zdenek Prikryl |
ab8f3c |
#include <sys/wait.h>
|
|
Zdenek Prikryl |
ab8f3c |
+#include <sys/poll.h>
|
|
Zdenek Prikryl |
ab8f3c |
#include <fcntl.h>
|
|
Zdenek Prikryl |
ab8f3c |
#include <unistd.h>
|
|
Zdenek Prikryl |
ab8f3c |
#include <stdio.h>
|
|
Zdenek Prikryl |
ab8f3c |
@@ -35,6 +36,7 @@
|
|
Zdenek Prikryl |
ab8f3c |
#include <signal.h>
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
#include "acpid.h"
|
|
Zdenek Prikryl |
ab8f3c |
+#include "ud_socket.h"
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
/*
|
|
Zdenek Prikryl |
ab8f3c |
* What is a rule? It's polymorphic, pretty much.
|
|
Zdenek Prikryl |
ab8f3c |
@@ -347,7 +349,7 @@ acpid_add_client(int clifd, const char *
|
|
Zdenek Prikryl |
ab8f3c |
acpid_log(LOG_INFO, "%d client rule%s loaded\n",
|
|
Zdenek Prikryl |
ab8f3c |
nrules, (nrules == 1)?"":"s");
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
-
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
return 0;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
@@ -458,6 +460,55 @@ free_rule(struct rule *r)
|
|
Zdenek Prikryl |
ab8f3c |
free(r);
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
+static int
|
|
Zdenek Prikryl |
ab8f3c |
+client_is_dead(int fd)
|
|
Zdenek Prikryl |
ab8f3c |
+{
|
|
Zdenek Prikryl |
ab8f3c |
+ struct pollfd pfd;
|
|
Zdenek Prikryl |
ab8f3c |
+ int r;
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+ /* check the fd to see if it is dead */
|
|
Zdenek Prikryl |
ab8f3c |
+ pfd.fd = fd;
|
|
Zdenek Prikryl |
ab8f3c |
+ pfd.events = POLLERR | POLLHUP;
|
|
Zdenek Prikryl |
ab8f3c |
+ r = poll(&pfd, 1, 0);
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+ if (r < 0) {
|
|
Zdenek Prikryl |
ab8f3c |
+ acpid_log(LOG_ERR, "poll(): %s\n", strerror(errno));
|
|
Zdenek Prikryl |
ab8f3c |
+ return 0;
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+ return pfd.revents;
|
|
Zdenek Prikryl |
ab8f3c |
+}
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+void
|
|
Zdenek Prikryl |
ab8f3c |
+acpid_close_dead_clients(void)
|
|
Zdenek Prikryl |
ab8f3c |
+{
|
|
Zdenek Prikryl |
ab8f3c |
+ struct rule *p;
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+ lock_rules();
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+ /* scan our client list */
|
|
Zdenek Prikryl |
ab8f3c |
+ p = client_list.head;
|
|
Zdenek Prikryl |
ab8f3c |
+ while (p) {
|
|
Zdenek Prikryl |
ab8f3c |
+ struct rule *next = p->next;
|
|
Zdenek Prikryl |
ab8f3c |
+ if (client_is_dead(p->action.fd)) {
|
|
Zdenek Prikryl |
ab8f3c |
+ struct ucred cred;
|
|
Zdenek Prikryl |
ab8f3c |
+ /* closed */
|
|
Zdenek Prikryl |
ab8f3c |
+ acpid_log(LOG_NOTICE,
|
|
Zdenek Prikryl |
ab8f3c |
+ "client %s has disconnected\n", p->origin);
|
|
Zdenek Prikryl |
ab8f3c |
+ delist_rule(&client_list, p);
|
|
Zdenek Prikryl |
ab8f3c |
+ ud_get_peercred(p->action.fd, &cred);
|
|
Zdenek Prikryl |
ab8f3c |
+ if (cred.uid != 0) {
|
|
Zdenek Prikryl |
ab8f3c |
+ non_root_clients--;
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
+ close(p->action.fd);
|
|
Zdenek Prikryl |
ab8f3c |
+ free_rule(p);
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
+ p = next;
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
+ unlock_rules();
|
|
Zdenek Prikryl |
ab8f3c |
+}
|
|
Zdenek Prikryl |
ab8f3c |
+
|
|
Zdenek Prikryl |
ab8f3c |
/*
|
|
Zdenek Prikryl |
ab8f3c |
* the main hook for propogating events
|
|
Zdenek Prikryl |
ab8f3c |
*/
|
|
Zdenek Prikryl |
ab8f3c |
@@ -624,9 +675,14 @@ do_client_rule(struct rule *rule, const
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
r = safe_write(client, event, strlen(event));
|
|
Zdenek Prikryl |
ab8f3c |
if (r < 0 && errno == EPIPE) {
|
|
Zdenek Prikryl |
ab8f3c |
+ struct ucred cred;
|
|
Zdenek Prikryl |
ab8f3c |
/* closed */
|
|
Zdenek Prikryl |
ab8f3c |
acpid_log(LOG_NOTICE, "client has disconnected\n");
|
|
Zdenek Prikryl |
ab8f3c |
delist_rule(&client_list, rule);
|
|
Zdenek Prikryl |
ab8f3c |
+ ud_get_peercred(rule->action.fd, &cred);
|
|
Zdenek Prikryl |
ab8f3c |
+ if (cred.uid != 0) {
|
|
Zdenek Prikryl |
ab8f3c |
+ non_root_clients--;
|
|
Zdenek Prikryl |
ab8f3c |
+ }
|
|
Zdenek Prikryl |
ab8f3c |
close(rule->action.fd);
|
|
Zdenek Prikryl |
ab8f3c |
free_rule(rule);
|
|
Zdenek Prikryl |
ab8f3c |
return -1;
|
|
Zdenek Prikryl |
ab8f3c |
diff -up acpid-1.0.6/ud_socket.c.socket acpid-1.0.6/ud_socket.c
|
|
Zdenek Prikryl |
ab8f3c |
--- acpid-1.0.6/ud_socket.c.socket 2007-01-17 08:57:51.000000000 +0100
|
|
Zdenek Prikryl |
ab8f3c |
+++ acpid-1.0.6/ud_socket.c 2009-05-27 08:06:52.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
@@ -1,5 +1,5 @@
|
|
Zdenek Prikryl |
ab8f3c |
/*
|
|
Zdenek Prikryl |
ab8f3c |
- * $Id: acpid-1.0.6-socket.patch,v 1.1 2009/05/27 06:34:22 zprikryl Exp $
|
|
Zdenek Prikryl |
ab8f3c |
+ * $Id: acpid-1.0.6-socket.patch,v 1.1 2009/05/27 06:34:22 zprikryl Exp $
|
|
Zdenek Prikryl |
ab8f3c |
* A few routines for handling UNIX domain sockets
|
|
Zdenek Prikryl |
ab8f3c |
*/
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
@@ -103,3 +103,10 @@ ud_connect(const char *name)
|
|
Zdenek Prikryl |
ab8f3c |
return fd;
|
|
Zdenek Prikryl |
ab8f3c |
}
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
+int
|
|
Zdenek Prikryl |
ab8f3c |
+ud_get_peercred(int fd, struct ucred *cred)
|
|
Zdenek Prikryl |
ab8f3c |
+{
|
|
Zdenek Prikryl |
ab8f3c |
+ socklen_t len = sizeof(struct ucred);
|
|
Zdenek Prikryl |
ab8f3c |
+ getsockopt(fd, SOL_SOCKET, SO_PEERCRED, cred, &len;;
|
|
Zdenek Prikryl |
ab8f3c |
+ return 0;
|
|
Zdenek Prikryl |
ab8f3c |
+}
|
|
Zdenek Prikryl |
ab8f3c |
diff -up acpid-1.0.6/ud_socket.h.socket acpid-1.0.6/ud_socket.h
|
|
Zdenek Prikryl |
ab8f3c |
--- acpid-1.0.6/ud_socket.h.socket 2007-01-17 08:57:51.000000000 +0100
|
|
Zdenek Prikryl |
ab8f3c |
+++ acpid-1.0.6/ud_socket.h 2009-05-27 08:06:52.000000000 +0200
|
|
Zdenek Prikryl |
ab8f3c |
@@ -1,5 +1,5 @@
|
|
Zdenek Prikryl |
ab8f3c |
/*
|
|
Zdenek Prikryl |
ab8f3c |
- *$Id: acpid-1.0.6-socket.patch,v 1.1 2009/05/27 06:34:22 zprikryl Exp $
|
|
Zdenek Prikryl |
ab8f3c |
+ *$Id: acpid-1.0.6-socket.patch,v 1.1 2009/05/27 06:34:22 zprikryl Exp $
|
|
Zdenek Prikryl |
ab8f3c |
*/
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
#ifndef UD_SOCKET_H__
|
|
Zdenek Prikryl |
ab8f3c |
@@ -11,5 +11,6 @@
|
|
Zdenek Prikryl |
ab8f3c |
int ud_create_socket(const char *name);
|
|
Zdenek Prikryl |
ab8f3c |
int ud_accept(int sock, struct ucred *cred);
|
|
Zdenek Prikryl |
ab8f3c |
int ud_connect(const char *name);
|
|
Zdenek Prikryl |
ab8f3c |
+int ud_get_peercred(int fd, struct ucred *cred);
|
|
Zdenek Prikryl |
ab8f3c |
|
|
Zdenek Prikryl |
ab8f3c |
#endif
|