+
+/* Check program exists and is executable on $PATH. Actually, we
+ * just assume PATH contains the default entries (see main() above).
+ */
+int
+prog_exists (const char *prog)
+{
+ static const char * const dirs[] =
+ { "/sbin", "/usr/sbin", "/bin", "/usr/bin" };
+ size_t i;
+ char buf[1024];
+
+ for (i = 0; i < sizeof dirs / sizeof dirs[0]; ++i) {
+ snprintf (buf, sizeof buf, "%s/%s", dirs[i], prog);
+ if (access (buf, X_OK) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+/* LVM and other commands aren't synchronous, especially when udev is
+ * involved. eg. You can create or remove some device, but the /dev
+ * device node won't appear until some time later. This means that
+ * you get an error if you run one command followed by another.
+ *
+ * Use 'udevadm settle' after certain commands, but don't be too
+ * fussed if it fails.
+ *
+ * 'udevsettle' was the old name for this command (RHEL 5). This was
+ * deprecated in favour of 'udevadm settle'. The old 'udevsettle'
+ * command was left as a symlink. Then in Fedora 13 the old symlink
+ * remained but it stopped working (RHBZ#548121), so we have to be
+ * careful not to assume that we can use 'udevsettle' if it exists.
+ */
+void
+udev_settle (void)
+{
+ (void) command (NULL, NULL, "udevadm", "settle", NULL);
+ (void) command (NULL, NULL, "udevsettle", NULL);
+}