chiark / gitweb /
volume_id: provide a custom debug function
[elogind.git] / extras / edd_id / edd_id.c
index 504aac36e64b78f0c23904202a71550ffea7f640..8fc690a49c6ff82214f90349b0d20e0298f7b20c 100644 (file)
@@ -7,7 +7,6 @@
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
- *
  */
 
 #ifndef _GNU_SOURCE
 #include <unistd.h>
 #include <fcntl.h>
 #include <ctype.h>
+#include <string.h>
 #include <errno.h>
 #include <dirent.h>
 #include <stdint.h>
 
-#include "../../logging.h"
-#include "../../udev_utils.h"
+#include "../../udev.h"
 
 #ifdef USE_LOG
 void log_message(int priority, const char *format, ...)
@@ -63,6 +62,7 @@ int main(int argc, char *argv[])
        int sysfs_fd;
        DIR *dir = NULL;
        int rc = 1;
+       char *match = NULL;
 
        logging_init("edd_id");
 
@@ -165,14 +165,23 @@ int main(int argc, char *argv[])
 
                sysfs_id = strtoul(sysfs_id_buf, NULL, 16);
                if (disk_id == sysfs_id) {
+                       if (!match) {
+                               match = dent->d_name;
+                       } else {
+                               info("'%s' does not have a unique signature", node);
+                               fprintf(stderr, "'%s' does not have a unique signature\n", node);
+                               rc=10;
+                               goto exit;
+                       }
+               }
+
+       }
+
                        if (export)
-                               printf("ID_EDD=%s\n", dent->d_name);
+               printf("ID_EDD=%s\n", match);
                        else
-                               printf("%s\n", dent->d_name);
+               printf("%s\n", match);
                        rc = 0;
-                       break;
-               }
-       }
 
 close:
        close(disk_fd);