mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-25 10:04:17 +03:00
working dm_get_registered_device(). dmevent.c update to use it.
This commit is contained in:
parent
3e940f80c7
commit
40e896bc5b
@ -27,7 +27,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static enum event_type events = ALL_ERRORS; /* All until we can distinguish. */
|
static enum event_type events = ALL_ERRORS; /* All until we can distinguish. */
|
||||||
static char *default_dso_name = "noop"; /* default DSO is noop */
|
static char default_dso_name[] = "noop"; /* default DSO is noop */
|
||||||
static int default_reg = 1; /* default action is register */
|
static int default_reg = 1; /* default action is register */
|
||||||
|
|
||||||
/* Display help. */
|
/* Display help. */
|
||||||
@ -58,7 +58,9 @@ static int parse_argv(int argc, char **argv,
|
|||||||
while ((c = getopt(argc, argv, options)) != -1) {
|
while ((c = getopt(argc, argv, options)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
*dso_name = optarg;
|
if (!(*dso_name = strdup(optarg)))
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
@ -80,14 +82,16 @@ static int parse_argv(int argc, char **argv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*list) {
|
if (!*dso_name && !(*dso_name = strdup(default_dso_name)))
|
||||||
if (optind >= argc) {
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
if (optind >= argc) {
|
||||||
|
if (!*list) {
|
||||||
fprintf(stderr, "You need to specify a device.\n");
|
fprintf(stderr, "You need to specify a device.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
} else if (!(*device = strdup(argv[optind])))
|
||||||
*device = argv[optind];
|
exit(EXIT_FAILURE);
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -95,43 +99,58 @@ static int parse_argv(int argc, char **argv,
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int list = 0, next = 0, ret, reg = default_reg;
|
int list = 0, next = 0, ret, reg = default_reg;
|
||||||
char *device = NULL, *dso_name = default_dso_name, *dso_name_arg = NULL;
|
char *device = NULL, *device_arg, *dso_name = NULL, *dso_name_arg;
|
||||||
|
|
||||||
if (!parse_argv(argc, argv, &dso_name_arg, &device, ®, &list))
|
if (!parse_argv(argc, argv, &dso_name, &device, ®, &list))
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
device_arg = device;
|
||||||
|
dso_name_arg = dso_name;
|
||||||
|
|
||||||
if (list) {
|
if (list) {
|
||||||
dso_name = dso_name_arg;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* FIXME: dso_name and/or device name given. */
|
|
||||||
if (!(ret= dm_get_registered_device(&dso_name,
|
if (!(ret= dm_get_registered_device(&dso_name,
|
||||||
&device,
|
&device,
|
||||||
&events, next))) {
|
&events, next))) {
|
||||||
printf("%s %s 0x%x\n",
|
printf("%s %s 0x%x\n",
|
||||||
dso_name, device, events);
|
dso_name, device, events);
|
||||||
|
|
||||||
|
if (device_arg)
|
||||||
|
break;
|
||||||
|
|
||||||
next = 1;
|
next = 1;
|
||||||
}
|
}
|
||||||
} while (!ret);
|
} while (!ret);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
if (dso_name)
|
||||||
}
|
free(dso_name);
|
||||||
|
|
||||||
if (dso_name_arg)
|
if (device)
|
||||||
dso_name = dso_name_arg;
|
free(device);
|
||||||
|
|
||||||
|
ret = (ret && device_arg) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = reg ? dm_register_for_event(dso_name, device, events) :
|
if ((ret = reg ? dm_register_for_event(dso_name, device, events) :
|
||||||
dm_unregister_for_event(dso_name, device, events))) {
|
dm_unregister_for_event(dso_name, device, events))) {
|
||||||
fprintf(stderr, "Failed to %sregister %s: %s\n",
|
fprintf(stderr, "Failed to %sregister %s: %s\n",
|
||||||
reg ? "": "un", device, strerror(-ret));
|
reg ? "": "un", device, strerror(-ret));
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
exit(EXIT_FAILURE);
|
} else {
|
||||||
|
printf("%s %sregistered successfully.\n",
|
||||||
|
device, reg ? "" : "un");
|
||||||
|
ret = EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s %sregistered successfully.\n", device, reg ? "" : "un");
|
out:
|
||||||
|
if (device_arg)
|
||||||
|
free(device_arg);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
if (dso_name_arg)
|
||||||
|
free(dso_name_arg);
|
||||||
|
|
||||||
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user