X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Fedd_id%2Fedd_id.c;h=4ba89ede8927f91d7ae6166374970bb3a26ce529;hb=596714857b0c6b2779e861e4069d63f0fa27aa28;hp=504aac36e64b78f0c23904202a71550ffea7f640;hpb=077ed27c55a9ea661262d7b3ec8be184445ab82e;p=elogind.git diff --git a/extras/edd_id/edd_id.c b/extras/edd_id/edd_id.c index 504aac36e..4ba89ede8 100644 --- a/extras/edd_id/edd_id.c +++ b/extras/edd_id/edd_id.c @@ -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 @@ -19,12 +18,12 @@ #include #include #include +#include #include #include #include -#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[NAME_MAX] = ""; logging_init("edd_id"); @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) } else node = arg; } - if (!node) { + if (node == NULL) { err("no node specified"); fprintf(stderr, "no node specified\n"); goto exit; @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) /* check for kernel support */ dir = opendir("/sys/firmware/edd"); - if (!dir) { + if (dir == NULL) { info("no kernel EDD support"); fprintf(stderr, "no kernel EDD support\n"); rc = 2; @@ -156,24 +156,37 @@ int main(int argc, char *argv[]) size = read(sysfs_fd, sysfs_id_buf, sizeof(sysfs_id_buf)-1); close(sysfs_fd); - if (size < 0) { + if (size <= 0) { info("read sysfs '%s' failed", file); continue; } sysfs_id_buf[size] = '\0'; info("read '%s' from '%s'", sysfs_id_buf, file); - sysfs_id = strtoul(sysfs_id_buf, NULL, 16); + + /* look for matching value, that appears only once */ if (disk_id == sysfs_id) { - if (export) - printf("ID_EDD=%s\n", dent->d_name); - else - printf("%s\n", dent->d_name); - rc = 0; - break; + if (match[0] == '\0') { + /* store id */ + strlcpy(match, dent->d_name, sizeof(match)); + } else { + /* error, same signature for another device */ + 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 (match[0] != '\0') { + if (export) + printf("ID_EDD=%s\n", match); + else + printf("%s\n", match); + rc = 0; + } + close: close(disk_fd); closedir: