diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2015-09-21 16:33:15 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2015-09-21 16:33:15 +0200 |
commit | f03dbad2932e6d49a4372c4086a684b0e25ede6d (patch) | |
tree | 131bab7dae4d9222f801a7e199dc692937a37ebc | |
parent | 4529911b8da55cdda1998b660d56468e1733f1a8 (diff) | |
download | nlplug-f03dbad2932e6d49a4372c4086a684b0e25ede6d.tar.bz2 nlplug-f03dbad2932e6d49a4372c4086a684b0e25ede6d.tar.xz |
nlplug: support searching UUID and LABEL
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | nlplug.c | 48 |
2 files changed, 52 insertions, 5 deletions
@@ -6,13 +6,17 @@ PKGCONFIG ?= pkg-config LIBKMOD_CFLAGS := $(shell $(PKGCONFIG) --cflags libkmod) LIBKMOD_LIBS := $(shell $(PKGCONFIG) --libs libkmod) +BLKID_CFLAGS := $(shell $(PKGCONFIG) --cflags blkid) +BLKID_LIBS := $(shell $(PKGCONFIG) --libs blkid) + nlsockd_SRCS = nlsockd.c nlsockd_OBJS = $(nlsockd_SRCS:%.c=%.o) nlplug_SRCS = nlplug.c nlplug_OBJS = $(nlplug_SRCS:%.c=%.o) -nlplug_CFLAGS = $(LIBKMOD_CFLAGS) -nlplug_LIBS = $(LIBKMOD_LIBS) +nlplug_LIBS = $(LIBKMOD_LIBS) $(BLKID_LIBS) + +CFLAGS += $(LIBKMOD_CFLAGS) $(BLKID_CFLAGS) handler_SRCS = handler.c handler_OBJS = $(handler_SRCS:%.c=%.o) @@ -25,6 +29,7 @@ handler: $(handler_OBJS) handler nlsockd nlplug: + echo $(BLKID_CFLAGS) $(CC) -o $@ $(CFLAGS) $($@_CFLAGS) $($@_OBJS) $(LDFLAGS) $($@_LIBS) clean: @@ -22,6 +22,7 @@ #include <linux/netlink.h> #include <libkmod.h> +#include <blkid.h> #include "arg.h" @@ -116,14 +117,54 @@ int load_kmod(const char *modalias) int is_searchdev(const char *devname, const char *searchdev) { + static blkid_cache cache = NULL; + char *type = NULL, *label = NULL, *uuid = NULL; if (searchdev == NULL) return 0; - - if (strcmp(devname, searchdev) == 0) { - dbg("FOUND %s", searchdev); +// printf("DEBUG: devname=%s\n", devname); + if (strcmp(devname, searchdev) == 0) return 1; + + if (cache == NULL) + blkid_get_cache(&cache, NULL); + + if (strncmp("LABEL=", searchdev, 6) == 0) { + label = blkid_get_tag_value(cache, "LABEL", devname); + if (label && strcmp(label, searchdev+6) == 0) { + free(label); + return 1; + } + } else if (strncmp("UUID=", searchdev, 5) == 0) { + uuid = blkid_get_tag_value(cache, "UUID", devname); + if (uuid && strcmp(uuid, searchdev+5) == 0) { + free(uuid); + return 1; + } } + type = blkid_get_tag_value(cache, "TYPE", devname); +// uuid = blkid_get_tag_value(cache, "UUID", devname); + if (type || label || uuid) { + printf("DEBUG:%s: (%s)\n" + "\ttype='%s'\n" + "\tlabel='%s'\n" + "\tuuid='%s'\n", devname, searchdev, + type ? type : NULL, + label ? label : NULL, + uuid ? uuid : NULL); + } + + if (type) { + load_kmod(type); + free(type); + } + + if (label) + free(label); + + if (uuid) + free(uuid); + return 0; } @@ -238,6 +279,7 @@ int main(int argc, char *argv[]) if (argv[0] == NULL) usage(); + chdir("/dev"); fds.fd = 0; /* stdin */ fds.events = POLLIN; while ((r = poll(&fds, 1, EVENT_TIMEOUT)) > 0) { |