If udev-helper is going to sleep(), then detach from the main udev
process first. Previously, this meant that new devices were 'stuck'
behind polling helpers.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
+static void detach_and_sleep(int sec)
+{
+ static int forked = 0;
+ int rc = 0;
+
+ if (sec <= 0)
+ return;
+
+ if (!forked) {
+ log("running in background...");
+ rc = fork();
+ forked = 1;
+ }
+
+ if (rc == 0) {
+ sleep(sec);
+
+ } else if (rc == -1) {
+ perror("fork()");
+ exit(EXIT_FAILURE);
+ } else {
+ exit(EXIT_SUCCESS);
+ }
+}
+
static int poll_device_plug(const char *dev_path,
int *optical)
{
static int poll_device_plug(const char *dev_path,
int *optical)
{
return EXIT_SUCCESS;
printf("no... waiting\n");
return EXIT_SUCCESS;
printf("no... waiting\n");
- sleep(REMOVABLE_SLEEP_DELAY);
+ detach_and_sleep(REMOVABLE_SLEEP_DELAY);
}
/* Fall back to bare open() */
}
/* Fall back to bare open() */
if (fd >= 0)
return EXIT_SUCCESS;
printf("no... waiting\n");
if (fd >= 0)
return EXIT_SUCCESS;
printf("no... waiting\n");
- sleep(REMOVABLE_SLEEP_DELAY);
+ detach_and_sleep(REMOVABLE_SLEEP_DELAY);
if (rc != CDS_DISC_OK)
return EXIT_SUCCESS;
printf("no... waiting\n");
if (rc != CDS_DISC_OK)
return EXIT_SUCCESS;
printf("no... waiting\n");
- sleep(REMOVABLE_SLEEP_DELAY);
+ detach_and_sleep(REMOVABLE_SLEEP_DELAY);
}
/* Fall back to bare open() */
}
/* Fall back to bare open() */
if (fd < 0)
return EXIT_SUCCESS;
printf("no... waiting\n");
if (fd < 0)
return EXIT_SUCCESS;
printf("no... waiting\n");
- sleep(REMOVABLE_SLEEP_DELAY);
+ detach_and_sleep(REMOVABLE_SLEEP_DELAY);
/* Unmount it repeatedly, if needs be */
while (mounted && !unmount_device(dev_path))
;
/* Unmount it repeatedly, if needs be */
while (mounted && !unmount_device(dev_path))
;
char *dev_path, *action;
int rc;
char *dev_path, *action;
int rc;
- /*if (fork())
- return EXIT_SUCCESS;
- */
action = getenv("ACTION");
logf = stdout;
action = getenv("ACTION");
logf = stdout;