---------- patch start ----------
--- a/src/wait-for-root.c
+++ b/src/wait-for-root.c
@@ -88,7 +88,9 @@ main (int argc,
/* When the device doesn't exist yet, or is still being processed
* by udev, use the monitor socket to wait it to be done.
*/
- while ((udev_device = udev_monitor_receive_device (udev_monitor)) != NULL) {
+ while (1) {
+ while ((udev_device = udev_monitor_receive_device (udev_monitor)) == NULL)
+ sleep (1);
if (matching_device (udev_device, devpath)) {
type = udev_device_get_property_value (udev_device, "ID_FS_TYPE");
if (type) {
---------- patch end ----------
But why need to handle udev_monitor_receive_device() errors?
I think that wait-for-root.c could be written as short as below code.
I confirmed that below patch fixes my problem.
---------- patch start ---------- for-root. c for-root. c receive_ device (udev_monitor)) != NULL) { receive_ device (udev_monitor)) == NULL) get_property_ value (udev_device, "ID_FS_TYPE");
--- a/src/wait-
+++ b/src/wait-
@@ -88,7 +88,9 @@ main (int argc,
/* When the device doesn't exist yet, or is still being processed
* by udev, use the monitor socket to wait it to be done.
*/
- while ((udev_device = udev_monitor_
+ while (1) {
+ while ((udev_device = udev_monitor_
+ sleep (1);
if (matching_device (udev_device, devpath)) {
type = udev_device_
if (type) {
---------- patch end ----------
But why need to handle udev_monitor_ receive_ device( ) errors?
I think that wait-for-root.c could be written as short as below code.
---------- simplified wait-for-root.c start ----------
#include <libudev.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static void alarm_handler(int signum)
{
exit(1);
}
int main(int argc, char *argv[])
{
const char *devpath;
char path[PATH_MAX];
struct udev *udev;
if (argc != 3) {
fprintf(stderr, "Usage: %s DEVICE TIMEOUT\n", argv[0]);
exit(2);
}
devpath = argv[1]; by-uuid/ %s", devpath + 5); by-label/ %s", devpath + 6);
if (!strncmp(devpath, "UUID=", 5))
snprintf(path, sizeof(path), "/dev/disk/
else if (!strncmp(devpath, "LABEL=", 6))
snprintf(path, sizeof(path), "/dev/disk/
else
snprintf(path, sizeof(path), "%s", devpath);
signal(SIGALRM, alarm_handler); atoi(argv[ 2]));
alarm(
udev = udev_new(); devstat. st_mode) ) { new_from_ devnum( udev, 'b', devstat.st_rdev); get_property_ value(udev_ device, "ID_FS_TYPE"); device_ unref(udev_ device) ;
while (1) {
struct stat devstat;
const char *type;
struct udev_device *udev_device;
if (stat(path, &devstat) || !S_ISBLK(
sleep(1);
continue;
}
udev_device = udev_device_
if (!udev_device) {
sleep(1);
continue;
}
type = udev_device_
if (type)
printf("%s\n", type);
udev_
if (type)
break;
}
udev_unref(udev);
exit(0);
}
---------- simplified wait-for-root.c end ----------