mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon: run 'udevadm settle' with --exit-if-exists option
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@virtuozzo.com> RWMJ: - Use local variable for MAX_ARGS. - Use commandv instead of commandrv, fix checking of return code.
This commit is contained in:
committed by
Richard W.M. Jones
parent
bf547aac70
commit
93664d38d2
@@ -142,6 +142,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);
|
||||
|
||||
@@ -1213,20 +1213,34 @@ random_name (char *template)
|
||||
* fussed if it fails.
|
||||
*/
|
||||
void
|
||||
udev_settle (void)
|
||||
udev_settle_file (const char *file)
|
||||
{
|
||||
char cmd[80];
|
||||
const size_t MAX_ARGS = 64;
|
||||
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 = commandv (NULL, &err, argv);
|
||||
if (r == -1)
|
||||
perror ("system");
|
||||
else if (!WIFEXITED (r) || WEXITSTATUS (r) != 0)
|
||||
fprintf (stderr, "warning: udevadm command failed\n");
|
||||
fprintf (stderr, "udevadm settle: %s\n", err);
|
||||
}
|
||||
|
||||
void
|
||||
udev_settle (void)
|
||||
{
|
||||
udev_settle_file (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
|
||||
Reference in New Issue
Block a user