return EXIT_SUCCESS;
}
+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)
{
return EXIT_SUCCESS;
printf("no... waiting\n");
- sleep(REMOVABLE_SLEEP_DELAY);
+ detach_and_sleep(REMOVABLE_SLEEP_DELAY);
}
/* Fall back to bare open() */
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");
- sleep(REMOVABLE_SLEEP_DELAY);
+ detach_and_sleep(REMOVABLE_SLEEP_DELAY);
}
/* Fall back to bare open() */
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))
;
- sleep(1);
+ detach_and_sleep(1);
}
}
char *dev_path, *action;
int rc;
- /*if (fork())
- return EXIT_SUCCESS;
- */
action = getenv("ACTION");
logf = stdout;