summaryrefslogtreecommitdiff
path: root/udevmonitor.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2005-08-25 00:38:25 +0200
committerKay Sievers <kay.sievers@suse.de>2005-08-25 00:38:25 +0200
commit9ae611be33c29d5d9b51bca281408d407dcf007f (patch)
tree053aeed7505e08cc1e3bd6c855899b734d45d1b1 /udevmonitor.c
parent8d77c6a383ed1b308ce73e97b9f02f767b012921 (diff)
udevmonitor: cleanup on exit
We want to write the output buffer before we exit, otherwise redirection to a file does not work correctly. Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'udevmonitor.c')
-rw-r--r--udevmonitor.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/udevmonitor.c b/udevmonitor.c
index 9fe6da906f..33dff2a13c 100644
--- a/udevmonitor.c
+++ b/udevmonitor.c
@@ -25,6 +25,7 @@
#include <fcntl.h>
#include <time.h>
#include <errno.h>
+#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/select.h>
@@ -38,6 +39,7 @@
static int uevent_netlink_sock;
static int udev_monitor_sock;
+static volatile int udev_exit;
static int init_udev_monitor_socket(void)
{
@@ -101,8 +103,15 @@ static int init_uevent_netlink_sock(void)
return 0;
}
+static void asmlinkage sig_handler(int signum)
+{
+ if (signum == SIGINT || signum == SIGTERM)
+ udev_exit = 1;
+}
+
int main(int argc, char *argv[])
{
+ struct sigaction act;
int env = 0;
fd_set readfds;
int i;
@@ -129,6 +138,14 @@ int main(int argc, char *argv[])
exit(2);
}
+ /* set signal handlers */
+ memset(&act, 0x00, sizeof(struct sigaction));
+ act.sa_handler = (void (*)(int)) sig_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_RESTART;
+ sigaction(SIGINT, &act, NULL);
+ sigaction(SIGTERM, &act, NULL);
+
retval = init_udev_monitor_socket();
if (retval)
goto out;
@@ -139,7 +156,7 @@ int main(int argc, char *argv[])
printf("udevmonitor prints the received event from the kernel [UEVENT]\n"
"and the event which udev sends out after rule processing [UDEV]\n\n");
- while (1) {
+ while (!udev_exit) {
static char buf[UEVENT_BUFFER_SIZE*2];
ssize_t buflen;
int fdcount;