Add udev_settle_file() to run 'udevadm settle' with --exit-if-exists option. It
will slightly reduce the waiting-time for pending events if we need to wait
for events related to a particular device/file.
Signed-off-by: Pavel Butsykin <pbutsykin(a)virtuozzo.com>
---
daemon/daemon.h | 2 ++
daemon/guestfsd.c | 31 ++++++++++++++++++++++++-------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 79a5288f6..90ebaafbe 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -141,6 +141,8 @@ extern int parse_btrfsvol (const char *desc, mountable_t *mountable);
extern int prog_exists (const char *prog);
+extern void udev_settle_file (const char *file);
+
extern void udev_settle (void);
extern int random_name (char *template);
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 85ce5d2ad..635f5b1d2 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -63,6 +63,8 @@
#include "daemon.h"
+#define MAX_ARGS 64
+
GUESTFSD_EXT_CMD(str_udevadm, udevadm);
GUESTFSD_EXT_CMD(str_uuidgen, uuidgen);
@@ -1213,22 +1215,37 @@ random_name (char *template)
* fussed if it fails.
*/
void
-udev_settle (void)
+udev_settle_file (const char *file)
{
- char cmd[80];
+ const char *argv[MAX_ARGS];
+ CLEANUP_FREE char *err = NULL;
+ size_t i = 0;
int r;
- snprintf (cmd, sizeof cmd, "%s%s settle",
- str_udevadm, verbose ? " --debug" : "");
+ ADD_ARG (argv, i, str_udevadm);
if (verbose)
- printf ("%s\n", cmd);
- r = system (cmd);
+ ADD_ARG (argv, i, "--debug");
+
+ ADD_ARG (argv, i, "settle");
+ if (file) {
+ ADD_ARG (argv, i, "-E");
+ ADD_ARG (argv, i, file);
+ }
+ ADD_ARG (argv, i, NULL);
+
+ r = commandrv (NULL, &err, argv);
if (r == -1)
- perror ("system");
+ fprintf (stderr, "%s\n", err);
else if (!WIFEXITED (r) || WEXITSTATUS (r) != 0)
fprintf (stderr, "warning: udevadm command failed\n");
}
+void
+udev_settle (void)
+{
+ udev_settle_file (NULL);
+}
+
char *
get_random_uuid (void)
{
--
2.11.0