multipath: Deprecate 'getuid' configuration variable
[multipath-tools/.git] / libmultipath / discovery.c
index 6af5083..fcb8e4f 100644 (file)
@@ -20,6 +20,7 @@
 #include "structs.h"
 #include "config.h"
 #include "blacklist.h"
+#include "callout.h"
 #include "debug.h"
 #include "propsel.h"
 #include "sg_include.h"
@@ -974,9 +975,9 @@ static int
 get_uid (struct path * pp)
 {
        char *c;
-       const char *value;
+       const char *origin;
 
-       if (!pp->uid_attribute)
+       if (!pp->uid_attribute && !pp->getuid)
                select_getuid(pp);
 
        if (!pp->udev) {
@@ -985,23 +986,41 @@ get_uid (struct path * pp)
        }
 
        memset(pp->wwid, 0, WWID_SIZE);
-       value = udev_device_get_property_value(pp->udev, pp->uid_attribute);
-       if ((!value || strlen(value) == 0) && conf->dry_run == 2)
-               value = getenv(pp->uid_attribute);
-       if (value && strlen(value)) {
-               size_t len = WWID_SIZE;
-
-               if (strlen(value) + 1 > WWID_SIZE) {
-                       condlog(0, "%s: wwid overflow", pp->dev);
-               } else {
-                       len = strlen(value);
+       if (pp->getuid) {
+               char buff[CALLOUT_MAX_SIZE];
+
+               /* Use 'getuid' callout, deprecated */
+               condlog(1, "%s: using deprecated getuid callout", pp->dev);
+               if (apply_format(pp->getuid, &buff[0], pp)) {
+                       condlog(0, "error formatting uid callout command");
+                       memset(pp->wwid, 0, WWID_SIZE);
+               } else if (execute_program(buff, pp->wwid, WWID_SIZE)) {
+                       condlog(3, "error calling out %s", buff);
+                       memset(pp->wwid, 0, WWID_SIZE);
                }
-               strncpy(pp->wwid, value, len);
+               origin = "callout";
        } else {
-               condlog(3, "%s: no %s attribute", pp->dev,
-                       pp->uid_attribute);
+               const char *value;
+
+               value = udev_device_get_property_value(pp->udev,
+                                                      pp->uid_attribute);
+               if ((!value || strlen(value) == 0) && conf->dry_run == 2)
+                       value = getenv(pp->uid_attribute);
+               if (value && strlen(value)) {
+                       size_t len = WWID_SIZE;
+
+                       if (strlen(value) + 1 > WWID_SIZE) {
+                               condlog(0, "%s: wwid overflow", pp->dev);
+                       } else {
+                               len = strlen(value);
+                       }
+                       strncpy(pp->wwid, value, len);
+               } else {
+                       condlog(3, "%s: no %s attribute", pp->dev,
+                               pp->uid_attribute);
+               }
+               origin = "udev";
        }
-
        /* Strip any trailing blanks */
        c = strchr(pp->wwid, '\0');
        c--;
@@ -1009,8 +1028,8 @@ get_uid (struct path * pp)
                *c = '\0';
                c--;
        }
-       condlog(3, "%s: uid = %s (udev)", pp->dev,
-               *pp->wwid == '\0' ? "<empty>" : pp->wwid);
+       condlog(3, "%s: uid = %s (%s)", pp->dev,
+               *pp->wwid == '\0' ? "<empty>" : pp->wwid, origin);
        return 0;
 }