diff options
author | Kay Sievers <kay@vrfy.org> | 2014-11-14 20:46:11 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-11-14 20:46:11 -0500 |
commit | dacd994fda3fadeb1fa01accbd37d61d0359e0ee (patch) | |
tree | 165d90b9b0c99689d76fd5f7ec129901c82d05ea /src/libudev | |
parent | aec5d2b9b4159cab7357e311fd558790037cd04b (diff) |
udev: switch to systemd logging functions
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev')
-rw-r--r-- | src/libudev/libudev-device-private.c | 7 | ||||
-rw-r--r-- | src/libudev/libudev-device.c | 17 | ||||
-rw-r--r-- | src/libudev/libudev-hwdb.c | 20 | ||||
-rw-r--r-- | src/libudev/libudev-monitor.c | 32 | ||||
-rw-r--r-- | src/libudev/libudev-private.h | 16 | ||||
-rw-r--r-- | src/libudev/libudev-util.c | 4 | ||||
-rw-r--r-- | src/libudev/libudev.c | 102 | ||||
-rw-r--r-- | src/libudev/libudev.h | 6 |
8 files changed, 61 insertions, 143 deletions
diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 637d064819..df1fc0c9bf 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -102,7 +102,6 @@ static bool device_has_info(struct udev_device *udev_device) int udev_device_update_db(struct udev_device *udev_device) { - struct udev *udev = udev_device_get_udev(udev_device); bool has_info; const char *id; char filename[UTIL_PATH_SIZE]; @@ -130,8 +129,8 @@ int udev_device_update_db(struct udev_device *udev_device) mkdir_parents(filename_tmp, 0755); f = fopen(filename_tmp, "we"); if (f == NULL) { - udev_err(udev, "unable to create temporary db file '%s': %m\n", filename_tmp); - return -1; + log_debug("unable to create temporary db file '%s': %m\n", filename_tmp); + return -errno; } /* @@ -172,7 +171,7 @@ int udev_device_update_db(struct udev_device *udev_device) r = rename(filename_tmp, filename); if (r < 0) return -1; - udev_dbg(udev, "created %s file '%s' for '%s'\n", has_info ? "db" : "empty", + log_debug("created %s file '%s' for '%s'\n", has_info ? "db" : "empty", filename, udev_device_get_devpath(udev_device)); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 2699374072..37e75d280f 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -535,7 +535,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) f = fopen(dbfile, "re"); if (f == NULL) { - udev_dbg(udev_device->udev, "no db file to read %s: %m\n", dbfile); + log_debug("no db file to read %s: %m\n", dbfile); return -errno; } @@ -577,7 +577,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) } fclose(f); - udev_dbg(udev_device->udev, "device %p filled with db file data\n", udev_device); + log_debug("device %p filled with db file data\n", udev_device); return 0; } @@ -642,7 +642,6 @@ void udev_device_set_info_loaded(struct udev_device *device) struct udev_device *udev_device_new(struct udev *udev) { struct udev_device *udev_device; - struct udev_list_entry *list_entry; if (udev == NULL) { errno = EINVAL; @@ -662,11 +661,7 @@ struct udev_device *udev_device_new(struct udev *udev) udev_list_init(udev, &udev_device->sysattr_list, false); udev_list_init(udev, &udev_device->tags_list, true); udev_device->watch_handle = -1; - /* copy global properties */ - udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev)) - udev_device_add_property(udev_device, - udev_list_entry_get_name(list_entry), - udev_list_entry_get_value(list_entry)); + return udev_device; } @@ -704,7 +699,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con /* path starts in sys */ if (!startswith(syspath, "/sys")) { - udev_dbg(udev, "not in sys :%s\n", syspath); + log_debug("not in sys :%s\n", syspath); errno = EINVAL; return NULL; } @@ -739,7 +734,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; udev_device_set_syspath(udev_device, path); - udev_dbg(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); + log_debug("device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); return udev_device; } @@ -971,7 +966,7 @@ _public_ struct udev_device *udev_device_new_from_environment(struct udev *udev) udev_device_add_property_from_string_parse(udev_device, environ[i]); if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) { - udev_dbg(udev, "missing values, invalid device\n"); + log_debug("missing values, invalid device\n"); udev_device_unref(udev_device); udev_device = NULL; } diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index 06341a41ad..5eecd56f80 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -277,38 +277,38 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) { hwdb->f = fopen(UDEV_HWDB_BIN, "re"); if (!hwdb->f) { - udev_dbg(udev, UDEV_HWDB_BIN "does not exist, please run udevadm hwdb --update"); + log_debug(UDEV_HWDB_BIN "does not exist, please run udevadm hwdb --update"); udev_hwdb_unref(hwdb); return NULL; } if (fstat(fileno(hwdb->f), &hwdb->st) < 0 || (size_t)hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8) { - udev_dbg(udev, "error reading " UDEV_HWDB_BIN ": %m"); + log_debug("error reading " UDEV_HWDB_BIN ": %m"); udev_hwdb_unref(hwdb); return NULL; } hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0); if (hwdb->map == MAP_FAILED) { - udev_dbg(udev, "error mapping " UDEV_HWDB_BIN ": %m"); + log_debug("error mapping " UDEV_HWDB_BIN ": %m"); udev_hwdb_unref(hwdb); return NULL; } if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 || (size_t)hwdb->st.st_size != le64toh(hwdb->head->file_size)) { - udev_dbg(udev, "error recognizing the format of " UDEV_HWDB_BIN); + log_debug("error recognizing the format of " UDEV_HWDB_BIN); udev_hwdb_unref(hwdb); return NULL; } - udev_dbg(udev, "=== trie on-disk ===\n"); - udev_dbg(udev, "tool version: %"PRIu64, le64toh(hwdb->head->tool_version)); - udev_dbg(udev, "file size: %8"PRIu64" bytes\n", hwdb->st.st_size); - udev_dbg(udev, "header size %8"PRIu64" bytes\n", le64toh(hwdb->head->header_size)); - udev_dbg(udev, "strings %8"PRIu64" bytes\n", le64toh(hwdb->head->strings_len)); - udev_dbg(udev, "nodes %8"PRIu64" bytes\n", le64toh(hwdb->head->nodes_len)); + log_debug("=== trie on-disk ===\n"); + log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version)); + log_debug("file size: %8"PRIu64" bytes\n", hwdb->st.st_size); + log_debug("header size %8"PRIu64" bytes\n", le64toh(hwdb->head->header_size)); + log_debug("strings %8"PRIu64" bytes\n", le64toh(hwdb->head->strings_len)); + log_debug("nodes %8"PRIu64" bytes\n", le64toh(hwdb->head->nodes_len)); return hwdb; } diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 137ea148d7..366981abe2 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -121,7 +121,7 @@ static bool udev_has_devtmpfs(struct udev *udev) { r = name_to_handle_at(AT_FDCWD, "/dev", &h.handle, &mount_id, 0); if (r < 0) { if (errno != EOPNOTSUPP) - udev_err(udev, "name_to_handle_at on /dev: %m\n"); + log_debug("name_to_handle_at on /dev: %m\n"); return false; } @@ -174,7 +174,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c * will not receive any messages. */ if (access("/run/udev/control", F_OK) < 0 && !udev_has_devtmpfs(udev)) { - udev_dbg(udev, "the udev service seems not to be active, disable the monitor\n"); + log_debug("the udev service seems not to be active, disable the monitor\n"); group = UDEV_MONITOR_NONE; } else group = UDEV_MONITOR_UDEV; @@ -190,7 +190,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c if (fd < 0) { udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT); if (udev_monitor->sock == -1) { - udev_err(udev, "error getting socket: %m\n"); + log_debug("error getting socket: %m\n"); free(udev_monitor); return NULL; } @@ -407,14 +407,14 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) if (err == 0) udev_monitor->snl.nl.nl_pid = snl.nl.nl_pid; } else { - udev_err(udev_monitor->udev, "bind failed: %m\n"); + log_debug("bind failed: %m\n"); return -errno; } /* enable receiving of sender credentials */ err = setsockopt(udev_monitor->sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); if (err < 0) - udev_err(udev_monitor->udev, "setting SO_PASSCRED failed: %m\n"); + log_debug("setting SO_PASSCRED failed: %m\n"); return 0; } @@ -602,12 +602,12 @@ retry: buflen = recvmsg(udev_monitor->sock, &smsg, 0); if (buflen < 0) { if (errno != EINTR) - udev_dbg(udev_monitor->udev, "unable to receive message\n"); + log_debug("unable to receive message\n"); return NULL; } if (buflen < 32 || (size_t)buflen >= sizeof(buf)) { - udev_dbg(udev_monitor->udev, "invalid message length\n"); + log_debug("invalid message length\n"); return NULL; } @@ -615,12 +615,12 @@ retry: /* unicast message, check if we trust the sender */ if (udev_monitor->snl_trusted_sender.nl.nl_pid == 0 || snl.nl.nl_pid != udev_monitor->snl_trusted_sender.nl.nl_pid) { - udev_dbg(udev_monitor->udev, "unicast netlink message ignored\n"); + log_debug("unicast netlink message ignored\n"); return NULL; } } else if (snl.nl.nl_groups == UDEV_MONITOR_KERNEL) { if (snl.nl.nl_pid > 0) { - udev_dbg(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n", + log_debug("multicast kernel netlink message from pid %d ignored\n", snl.nl.nl_pid); return NULL; } @@ -628,13 +628,13 @@ retry: cmsg = CMSG_FIRSTHDR(&smsg); if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) { - udev_dbg(udev_monitor->udev, "no sender credentials received, message ignored\n"); + log_debug("no sender credentials received, message ignored\n"); return NULL; } cred = (struct ucred *)CMSG_DATA(cmsg); if (cred->uid != 0) { - udev_dbg(udev_monitor->udev, "sender uid=%d, message ignored\n", cred->uid); + log_debug("sender uid=%d, message ignored\n", cred->uid); return NULL; } @@ -648,7 +648,7 @@ retry: /* udev message needs proper version magic */ nlh = (struct udev_monitor_netlink_header *) buf; if (nlh->magic != htonl(UDEV_MONITOR_MAGIC)) { - udev_err(udev_monitor->udev, "unrecognized message signature (%x != %x)\n", + log_debug("unrecognized message signature (%x != %x)\n", nlh->magic, htonl(UDEV_MONITOR_MAGIC)); udev_device_unref(udev_device); return NULL; @@ -666,14 +666,14 @@ retry: /* kernel message with header */ bufpos = strlen(buf) + 1; if ((size_t)bufpos < sizeof("a@/d") || bufpos >= buflen) { - udev_dbg(udev_monitor->udev, "invalid message length\n"); + log_debug("invalid message length\n"); udev_device_unref(udev_device); return NULL; } /* check message header */ if (strstr(buf, "@/") == NULL) { - udev_dbg(udev_monitor->udev, "unrecognized message header\n"); + log_debug("unrecognized message header\n"); udev_device_unref(udev_device); return NULL; } @@ -694,7 +694,7 @@ retry: } if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) { - udev_dbg(udev_monitor->udev, "missing values, invalid device\n"); + log_debug("missing values, invalid device\n"); udev_device_unref(udev_device); return NULL; } @@ -778,7 +778,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, smsg.msg_name = &udev_monitor->snl_destination; smsg.msg_namelen = sizeof(struct sockaddr_nl); count = sendmsg(udev_monitor->sock, &smsg, 0); - udev_dbg(udev_monitor->udev, "passed %zi bytes to netlink monitor %p\n", count, udev_monitor); + log_debug("passed %zi bytes to netlink monitor %p\n", count, udev_monitor); return count; } diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 51dfb38512..64f132f91d 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -26,7 +26,6 @@ #include "libudev.h" #include "macro.h" -#include "time-util.h" #include "util.h" #include "mkdir.h" #include "strxcpyx.h" @@ -34,23 +33,8 @@ #define READ_END 0 #define WRITE_END 1 -/* avoid (sometimes expensive) calculations of parameters for debug output */ -#define udev_log_cond(udev, prio, arg...) \ - do { \ - if (udev_get_log_priority(udev) >= prio) \ - udev_log(udev, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \ - } while (0) - -#define udev_dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg) -#define udev_err(udev, arg...) udev_log_cond(udev, LOG_ERR, ## arg) - /* libudev.c */ -void udev_log(struct udev *udev, - int priority, const char *file, int line, const char *fn, - const char *format, ...) _printf_(6, 7); int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]); -struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value); -struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev); /* libudev-device.c */ struct udev_device *udev_device_new(struct udev *udev); diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index e30bdc2434..8f3b6ff8aa 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -96,7 +96,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, strscpy(result, maxsize, val); else result[0] = '\0'; - udev_dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); + log_debug("value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); } else { size_t l; char *s; @@ -105,7 +105,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, l = strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL); if (attr != NULL) strpcpyl(&s, l, "/", attr, NULL); - udev_dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); + log_debug("path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); } udev_device_unref(dev); return 0; diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index f9a192b62b..3ce13d2f76 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -1,7 +1,7 @@ /*** This file is part of systemd. - Copyright 2008-2012 Kay Sievers <kay@vrfy.org> + Copyright 2008-2014 Kay Sievers <kay@vrfy.org> systemd is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -50,41 +50,18 @@ struct udev { int priority, const char *file, int line, const char *fn, const char *format, va_list args); void *userdata; - struct udev_list properties_list; - int log_priority; }; -void udev_log(struct udev *udev, - int priority, const char *file, int line, const char *fn, - const char *format, ...) -{ - va_list args; - - va_start(args, format); - udev->log_fn(udev, priority, file, line, fn, format, args); - va_end(args); -} - -_printf_(6,0) -static void log_stderr(struct udev *udev, - int priority, const char *file, int line, const char *fn, - const char *format, va_list args) -{ - fprintf(stderr, "libudev: %s: ", fn); - vfprintf(stderr, format, args); -} - /** * udev_get_userdata: * @udev: udev library context * * Retrieve stored data pointer from library context. This might be useful - * to access from callbacks like a custom log function. + * to access from callbacks. * * Returns: stored userdata **/ -_public_ void *udev_get_userdata(struct udev *udev) -{ +_public_ void *udev_get_userdata(struct udev *udev) { if (udev == NULL) return NULL; return udev->userdata; @@ -97,8 +74,7 @@ _public_ void *udev_get_userdata(struct udev *udev) * * Store custom @userdata in the library context. **/ -_public_ void udev_set_userdata(struct udev *udev, void *userdata) -{ +_public_ void udev_set_userdata(struct udev *udev, void *userdata) { if (udev == NULL) return; udev->userdata = userdata; @@ -115,8 +91,7 @@ _public_ void udev_set_userdata(struct udev *udev, void *userdata) * * Returns: a new udev library context **/ -_public_ struct udev *udev_new(void) -{ +_public_ struct udev *udev_new(void) { struct udev *udev; _cleanup_fclose_ FILE *f = NULL; @@ -124,9 +99,6 @@ _public_ struct udev *udev_new(void) if (udev == NULL) return NULL; udev->refcount = 1; - udev->log_fn = log_stderr; - udev->log_priority = LOG_INFO; - udev_list_init(udev, &udev->properties_list, true); f = fopen( UDEV_CONF_FILE, "re"); if (f != NULL) { @@ -152,7 +124,7 @@ _public_ struct udev *udev_new(void) /* split key/value */ val = strchr(key, '='); if (val == NULL) { - udev_err(udev, UDEV_CONF_FILE ":%u: missing assignment, skipping line.\n", line_nr); + log_debug(UDEV_CONF_FILE ":%u: missing assignment, skipping line.\n", line_nr); continue; } val[0] = '\0'; @@ -184,7 +156,7 @@ _public_ struct udev *udev_new(void) /* unquote */ if (val[0] == '"' || val[0] == '\'') { if (val[len-1] != val[0]) { - udev_err(udev, UDEV_CONF_FILE ":%u: inconsistent quoting, skipping line.\n", line_nr); + log_debug(UDEV_CONF_FILE ":%u: inconsistent quoting, skipping line.\n", line_nr); continue; } val[len-1] = '\0'; @@ -196,9 +168,9 @@ _public_ struct udev *udev_new(void) prio = util_log_priority(val); if (prio < 0) - udev_err(udev, "/etc/udev/udev.conf:%u: invalid log level '%s', ignoring.\n", line_nr, val); + log_debug("/etc/udev/udev.conf:%u: invalid log level '%s', ignoring.\n", line_nr, val); else - udev_set_log_priority(udev, prio); + log_set_max_level(prio); continue; } } @@ -215,8 +187,7 @@ _public_ struct udev *udev_new(void) * * Returns: the passed udev library context **/ -_public_ struct udev *udev_ref(struct udev *udev) -{ +_public_ struct udev *udev_ref(struct udev *udev) { if (udev == NULL) return NULL; udev->refcount++; @@ -232,14 +203,12 @@ _public_ struct udev *udev_ref(struct udev *udev) * * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise. **/ -_public_ struct udev *udev_unref(struct udev *udev) -{ +_public_ struct udev *udev_unref(struct udev *udev) { if (udev == NULL) return NULL; udev->refcount--; if (udev->refcount > 0) return udev; - udev_list_cleanup(&udev->properties_list); free(udev); return NULL; } @@ -249,31 +218,25 @@ _public_ struct udev *udev_unref(struct udev *udev) * @udev: udev library context * @log_fn: function to be called for log messages * - * The built-in logging writes to stderr. It can be - * overridden by a custom function, to plug log messages - * into the users' log functionality. + * This function is deprecated. * **/ _public_ void udev_set_log_fn(struct udev *udev, void (*log_fn)(struct udev *udev, int priority, const char *file, int line, const char *fn, - const char *format, va_list args)) -{ - udev->log_fn = log_fn; - udev_dbg(udev, "custom log function %p registered\n", log_fn); + const char *format, va_list args)) { + return; } /** * udev_get_log_priority: * @udev: udev library context * - * The initial log level is read from the udev config file at startup. + * This function is deprecated. * - * Returns: the current log level **/ -_public_ int udev_get_log_priority(struct udev *udev) -{ - return udev->log_priority; +_public_ int udev_get_log_priority(struct udev *udev) { + return log_get_max_level(); } /** @@ -281,32 +244,9 @@ _public_ int udev_get_log_priority(struct udev *udev) * @udev: udev library context * @priority: the new log priority * - * Set the log level. This value controls which messages are logged. + * This function is deprecated. + * **/ -_public_ void udev_set_log_priority(struct udev *udev, int priority) -{ - char num[32]; - - udev->log_priority = priority; - snprintf(num, sizeof(num), "%u", udev->log_priority); - udev_add_property(udev, "UDEV_LOG", num); -} - -struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) -{ - if (value == NULL) { - struct udev_list_entry *list_entry; - - list_entry = udev_get_properties_list_entry(udev); - list_entry = udev_list_entry_get_by_name(list_entry, key); - if (list_entry != NULL) - udev_list_entry_delete(list_entry); - return NULL; - } - return udev_list_entry_add(&udev->properties_list, key, value); -} - -struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev) -{ - return udev_list_get_entry(&udev->properties_list); +_public_ void udev_set_log_priority(struct udev *udev, int priority) { + log_set_max_level(priority); } diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 4f2f11502c..a94505c09e 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -41,9 +41,9 @@ struct udev *udev_new(void); void udev_set_log_fn(struct udev *udev, void (*log_fn)(struct udev *udev, int priority, const char *file, int line, const char *fn, - const char *format, va_list args)); -int udev_get_log_priority(struct udev *udev); -void udev_set_log_priority(struct udev *udev, int priority); + const char *format, va_list args)) __attribute__ ((deprecated)); +int udev_get_log_priority(struct udev *udev) __attribute__ ((deprecated)); +void udev_set_log_priority(struct udev *udev, int priority) __attribute__ ((deprecated)); void *udev_get_userdata(struct udev *udev); void udev_set_userdata(struct udev *udev, void *userdata); |