From: Pavel Rochnyack Date: Wed, 25 May 2016 07:54:46 +0000 (+0600) Subject: disk plugin: Initialize udev context only once, not per each read X-Git-Tag: collectd-5.6.0~297^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=baec98579514cae9888f15af623dc59c0e89e434;p=collectd.git disk plugin: Initialize udev context only once, not per each read --- diff --git a/src/disk.c b/src/disk.c index 07383c75..255d4db6 100644 --- a/src/disk.c +++ b/src/disk.c @@ -230,7 +230,16 @@ static int disk_init (void) /* #endif HAVE_IOKIT_IOKITLIB_H */ #elif KERNEL_LINUX - /* do nothing */ +#if HAVE_LIBUDEV + if (conf_udev_name_attr != NULL) + { + handle_udev = udev_new(); + if (handle_udev == NULL) { + ERROR ("disk plugin: udev_new() failed!"); + return (-1); + } + } +#endif /* HAVE_LIBUDEV */ /* #endif KERNEL_LINUX */ #elif KERNEL_FREEBSD @@ -272,6 +281,17 @@ static int disk_init (void) return (0); } /* int disk_init */ +static int disk_shutdown (void) +{ +#if KERNEL_LINUX +#if HAVE_LIBUDEV + if (handle_udev != NULL) + udev_unref(handle_udev); +#endif /* HAVE_LIBUDEV */ +#endif /* KERNEL_LINUX */ + return (0); +} /* int disk_shutdown */ + static void disk_submit (const char *plugin_instance, const char *type, derive_t read, derive_t write) @@ -690,10 +710,6 @@ static int disk_read (void) fieldshift = 1; } -#if HAVE_LIBUDEV - handle_udev = udev_new(); -#endif - while (fgets (buffer, sizeof (buffer), fh) != NULL) { char *disk_name; @@ -908,9 +924,6 @@ static int disk_read (void) #endif } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */ -#if HAVE_LIBUDEV - udev_unref(handle_udev); -#endif fclose (fh); /* #endif defined(KERNEL_LINUX) */ @@ -1061,5 +1074,6 @@ void module_register (void) plugin_register_config ("disk", disk_config, config_keys, config_keys_num); plugin_register_init ("disk", disk_init); + plugin_register_shutdown ("disk", disk_shutdown); plugin_register_read ("disk", disk_read); } /* void module_register */