From 87bd704cbfb9d5b191d6a0f73e9f022bccf812db Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 24 Sep 2013 15:36:15 +0200 Subject: rework action handling, always add additional info if available --- udev-block-notify.c | 91 +++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/udev-block-notify.c b/udev-block-notify.c index 4a8f439..9a4ad6f 100644 --- a/udev-block-notify.c +++ b/udev-block-notify.c @@ -96,7 +96,7 @@ char * appendstr(const char *text, char *notifystr, char *property, const char * /*** main ***/ int main (int argc, char ** argv) { - char action; + const char *action = NULL; char *device = NULL, *icon = NULL, *notifystr = NULL; const char *value = NULL; fd_set readfds; @@ -165,57 +165,44 @@ int main (int argc, char ** argv) { # if DEBUG printf("%s: Processing device %d:%d\n", argv[0], major, minor); # endif - action = udev_device_get_action(dev)[0]; - switch(action) { - case 'a': - // a: add - notifystr = newstr(TEXT_ADD, device, major, minor); - break; - case 'r': - // r: remove - notifystr = newstr(TEXT_REMOVE, device, major, minor); - break; - case 'm': - // m: move - notifystr = newstr(TEXT_MOVE, device, major, minor); - break; - case 'c': - // c: change - notifystr = newstr(TEXT_CHANGE, device, major, minor); - break; - default: - // we should never get here I think... - notifystr = newstr(TEXT_DEFAULT, device, major, minor); - } - - if (action != 'r') { - /* Get possible values with: - * $ udevadm info --query=all --name=/path/to/dev - * Values available differs from device type and content */ - - /* file system */ - if ((value = udev_device_get_property_value(dev, "ID_FS_LABEL")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Label", value); - if ((value = udev_device_get_property_value(dev, "ID_FS_TYPE")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Type", value); - if ((value = udev_device_get_property_value(dev, "ID_FS_USAGE")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Usage", value); - if ((value = udev_device_get_property_value(dev, "ID_FS_UUID")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "UUID", value); - - /* partition */ - if ((value = udev_device_get_property_value(dev, "ID_PART_TABLE_TYPE")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Partition Table Type", value); - if ((value = udev_device_get_property_value(dev, "ID_PART_TABLE_NAME")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Partition Name", value); - if ((value = udev_device_get_property_value(dev, "ID_PART_ENTRY_TYPE")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Partition Type", value); - - /* device mapper */ - if ((value = udev_device_get_property_value(dev, "DM_NAME")) != NULL) - notifystr = appendstr(TEXT_TAG, notifystr, "Device mapper name", value); - - } + action = udev_device_get_action(dev); + if (strcmp(action, "add") == 0) + notifystr = newstr(TEXT_ADD, device, major, minor); + else if (strcmp(action, "remove") == 0) + notifystr = newstr(TEXT_REMOVE, device, major, minor); + else if (strcmp(action, "move") == 0) + notifystr = newstr(TEXT_MOVE, device, major, minor); + else if (strcmp(action, "change") == 0) + notifystr = newstr(TEXT_CHANGE, device, major, minor); + else + /* we should never get here I think... */ + notifystr = newstr(TEXT_DEFAULT, device, major, minor); + + /* Get possible values with: + * $ udevadm info --query=all --name=/path/to/dev + * Values available differs from device type and content */ + + /* file system */ + if ((value = udev_device_get_property_value(dev, "ID_FS_LABEL")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Label", value); + if ((value = udev_device_get_property_value(dev, "ID_FS_TYPE")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Type", value); + if ((value = udev_device_get_property_value(dev, "ID_FS_USAGE")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Usage", value); + if ((value = udev_device_get_property_value(dev, "ID_FS_UUID")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "UUID", value); + + /* partition */ + if ((value = udev_device_get_property_value(dev, "ID_PART_TABLE_TYPE")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Partition Table Type", value); + if ((value = udev_device_get_property_value(dev, "ID_PART_TABLE_NAME")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Partition Name", value); + if ((value = udev_device_get_property_value(dev, "ID_PART_ENTRY_TYPE")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Partition Type", value); + + /* device mapper */ + if ((value = udev_device_get_property_value(dev, "DM_NAME")) != NULL) + notifystr = appendstr(TEXT_TAG, notifystr, "Device mapper name", value); # if DEBUG printf("%s: %s\n", argv[0], notifystr); -- cgit v1.2.3-54-g00ecf