From: Kay Sievers Date: Mon, 21 Apr 2008 17:00:54 +0000 (+0200) Subject: add OPTIONS+="event_timeout=" X-Git-Tag: 174~1721 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf50425b58da6f112197f79241dd6d64af2e9ea7;p=systemd add OPTIONS+="event_timeout=" --- diff --git a/test-udev.c b/test-udev.c index e341b74f..4ac2d5a8 100644 --- a/test-udev.c +++ b/test-udev.c @@ -105,7 +105,7 @@ int main(int argc, char *argv[], char *envp[]) sigaction(SIGTERM, &act, NULL); /* trigger timeout to prevent hanging processes */ - alarm(UDEV_ALARM_TIMEOUT); + alarm(UDEV_EVENT_TIMEOUT); action = getenv("ACTION"); devpath = getenv("DEVPATH"); @@ -154,6 +154,10 @@ int main(int argc, char *argv[], char *envp[]) retval = udev_device_event(&rules, udev); + /* rules may change/disable the timeout */ + if (udev->event_timeout >= 0) + alarm(udev->event_timeout); + if (retval == 0 && !udev->ignore_device && udev_run) udev_rules_run(udev); diff --git a/udev.7 b/udev.7 index 1cad58d1..096bf385 100644 --- a/udev.7 +++ b/udev.7 @@ -291,6 +291,11 @@ Specify the priority of the created symlinks\. Devices with higher priorities ov Create the device nodes for all available partitions of a block device\. This may be useful for removable media devices where media changes are not detected\. .RE .PP +\fBevent_timeout=\fR +.RS 4 +Number of seconds an event will wait for operations to finish, before it will terminate itself\. +.RE +.PP \fBstring_escape=\fR\fB\fInone|replace\fR\fR .RS 4 Usually control and other possibly unsafe characters are replaced in strings used for device naming\. The mode of replacement can be specified with this option\. diff --git a/udev.h b/udev.h index e6e953b2..e1b7ac0d 100644 --- a/udev.h +++ b/udev.h @@ -39,7 +39,7 @@ #define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?," #define DEFAULT_PARTITIONS_COUNT 15 -#define UDEV_ALARM_TIMEOUT 180 +#define UDEV_EVENT_TIMEOUT 180 #define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b)) @@ -93,6 +93,7 @@ struct udevice { int ignore_remove; char program_result[PATH_SIZE]; int link_priority; + int event_timeout; int test_run; }; diff --git a/udev.xml b/udev.xml index 15651e00..ac3676e4 100644 --- a/udev.xml +++ b/udev.xml @@ -441,6 +441,13 @@ detected. + + + + Number of seconds an event will wait for operations to finish, before it + will terminate itself. + + diff --git a/udev_device.c b/udev_device.c index 6546db48..cf21191c 100644 --- a/udev_device.c +++ b/udev_device.c @@ -53,6 +53,8 @@ struct udevice *udev_device_init(struct udevice *udev) strcpy(udev->owner, "root"); strcpy(udev->group, "root"); + udev->event_timeout = -1; + return udev; } diff --git a/udev_rules.c b/udev_rules.c index d476e699..55a079be 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -1397,6 +1397,10 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev) udev->link_priority = rule->link_priority; info("link_priority=%i\n", udev->link_priority); } + if (rule->event_timeout >= 0) { + udev->event_timeout = rule->event_timeout; + info("event_timeout=%i\n", udev->event_timeout); + } /* apply all_partitions option only at a main block device */ if (rule->partitions && strcmp(udev->dev->subsystem, "block") == 0 && udev->dev->kernel_number[0] == '\0') { diff --git a/udev_rules.h b/udev_rules.h index a84b0de8..da5ac3ea 100644 --- a/udev_rules.h +++ b/udev_rules.h @@ -97,6 +97,7 @@ struct udev_rule { enum escape_type string_escape; unsigned int link_priority; + int event_timeout; unsigned int partitions; unsigned int last_rule:1, run_ignore_error:1, diff --git a/udev_rules_parse.c b/udev_rules_parse.c index b586df13..5119b7e8 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -245,6 +245,7 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena memset(buf, 0x00, sizeof(buf)); rule = (struct udev_rule *) buf; + rule->event_timeout = -1; linepos = line; valid = 0; @@ -604,6 +605,11 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena rule->link_priority = atoi(&pos[strlen("link_priority=")]); dbg("link priority=%i\n", rule->link_priority); } + pos = strstr(value, "event_timeout="); + if (pos != NULL) { + rule->event_timeout = atoi(&pos[strlen("event_timeout=")]); + dbg("event timout=%i\n", rule->event_timeout); + } pos = strstr(value, "string_escape="); if (pos != NULL) { pos = &pos[strlen("string_escape=")]; diff --git a/udevd.c b/udevd.c index 66a410ec..c895c1dc 100644 --- a/udevd.c +++ b/udevd.c @@ -115,7 +115,7 @@ static int udev_event_process(struct udevd_uevent_msg *msg) sigaction(SIGHUP, &act, NULL); /* trigger timeout to prevent hanging processes */ - alarm(UDEV_ALARM_TIMEOUT); + alarm(UDEV_EVENT_TIMEOUT); /* reconstruct event environment from message */ for (i = 0; msg->envp[i]; i++) @@ -131,6 +131,10 @@ static int udev_event_process(struct udevd_uevent_msg *msg) retval = udev_device_event(&rules, udev); + /* rules may change/disable the timeout */ + if (udev->event_timeout >= 0) + alarm(udev->event_timeout); + /* run programs collected by RUN-key*/ if (retval == 0 && !udev->ignore_device && udev_run) retval = udev_rules_run(udev); diff --git a/udevtest.c b/udevtest.c index 8beba217..d5e90b02 100644 --- a/udevtest.c +++ b/udevtest.c @@ -183,6 +183,10 @@ int udevtest(int argc, char *argv[], char *envp[]) info("looking at device '%s' from subsystem '%s'\n", udev->dev->devpath, udev->dev->subsystem); retval = udev_device_event(&rules, udev); + + if (udev->event_timeout >= 0) + info("custom event timeout: %i\n", udev->event_timeout); + if (retval == 0 && !udev->ignore_device && udev_run) { struct name_entry *name_loop;