mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-11-23 23:10:57 +07:00
udev: switch to systemd logging functions
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
This commit is contained in:
parent
aec5d2b9b4
commit
dacd994fda
@ -73,14 +73,6 @@
|
||||
#define LONG(x) ((x)/BITS_PER_LONG)
|
||||
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
|
||||
|
||||
_printf_(6,0)
|
||||
static void log_fn(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
ORIENTATION_UNDEFINED,
|
||||
ORIENTATION_NORMAL,
|
||||
@ -236,8 +228,6 @@ int main (int argc, char** argv)
|
||||
if (udev == NULL)
|
||||
return 1;
|
||||
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
/* CLI argument parsing */
|
||||
while (1) {
|
||||
int option;
|
||||
@ -250,7 +240,6 @@ int main (int argc, char** argv)
|
||||
case 'd':
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
log_open();
|
||||
break;
|
||||
case 'h':
|
||||
|
@ -409,14 +409,6 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_printf_(6,0)
|
||||
static void log_fn(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct udev *udev;
|
||||
@ -445,8 +437,6 @@ int main(int argc, char *argv[])
|
||||
if (udev == NULL)
|
||||
goto exit;
|
||||
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
while (1) {
|
||||
int option;
|
||||
|
||||
|
@ -41,14 +41,6 @@
|
||||
#include "libudev.h"
|
||||
#include "libudev-private.h"
|
||||
|
||||
_printf_(6,0)
|
||||
static void log_fn(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
/* device info */
|
||||
static unsigned int cd_cd_rom;
|
||||
static unsigned int cd_cd_r;
|
||||
@ -878,8 +870,6 @@ int main(int argc, char *argv[])
|
||||
if (udev == NULL)
|
||||
goto exit;
|
||||
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
while (1) {
|
||||
int option;
|
||||
|
||||
@ -900,7 +890,6 @@ int main(int argc, char *argv[])
|
||||
case 'd':
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
log_open();
|
||||
break;
|
||||
case 'h':
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -67,14 +67,6 @@ static char model_enc_str[256];
|
||||
static char revision_str[16];
|
||||
static char type_str[16];
|
||||
|
||||
_printf_(6,0)
|
||||
static void log_fn(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
static void set_type(const char *from, char *to, size_t len)
|
||||
{
|
||||
int type_num;
|
||||
@ -394,7 +386,6 @@ static int set_options(struct udev *udev,
|
||||
case 'v':
|
||||
log_set_target(LOG_TARGET_CONSOLE);
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
log_open();
|
||||
break;
|
||||
|
||||
@ -594,8 +585,6 @@ int main(int argc, char **argv)
|
||||
if (udev == NULL)
|
||||
goto exit;
|
||||
|
||||
udev_set_log_fn(udev, log_fn);
|
||||
|
||||
/*
|
||||
* Get config file options.
|
||||
*/
|
||||
|
@ -677,7 +677,6 @@ int udev_event_spawn(struct udev_event *event,
|
||||
usec_t timeout_warn_usec,
|
||||
const char *cmd, char **envp, const sigset_t *sigmask,
|
||||
char *result, size_t ressize) {
|
||||
struct udev *udev = event->udev;
|
||||
int outpipe[2] = {-1, -1};
|
||||
int errpipe[2] = {-1, -1};
|
||||
pid_t pid;
|
||||
@ -690,14 +689,14 @@ int udev_event_spawn(struct udev_event *event,
|
||||
udev_build_argv(event->udev, arg, NULL, argv);
|
||||
|
||||
/* pipes from child to parent */
|
||||
if (result != NULL || udev_get_log_priority(udev) >= LOG_INFO) {
|
||||
if (result != NULL || log_get_max_level() >= LOG_INFO) {
|
||||
if (pipe2(outpipe, O_NONBLOCK) != 0) {
|
||||
err = -errno;
|
||||
log_error("pipe failed: %m");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (udev_get_log_priority(udev) >= LOG_INFO) {
|
||||
if (log_get_max_level() >= LOG_INFO) {
|
||||
if (pipe2(errpipe, O_NONBLOCK) != 0) {
|
||||
err = -errno;
|
||||
log_error("pipe failed: %m");
|
||||
|
@ -26,12 +26,6 @@
|
||||
|
||||
#include "udev.h"
|
||||
|
||||
void udev_main_log(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args) {
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
static int adm_version(struct udev *udev, int argc, char *argv[]) {
|
||||
printf("%s\n", UDEV_VERSION);
|
||||
return 0;
|
||||
@ -97,7 +91,6 @@ int main(int argc, char *argv[]) {
|
||||
goto out;
|
||||
|
||||
log_open();
|
||||
udev_set_log_fn(udev, udev_main_log);
|
||||
mac_selinux_init("/dev");
|
||||
|
||||
while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0)
|
||||
@ -105,7 +98,6 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
case 'd':
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
|
@ -53,12 +53,6 @@
|
||||
#include "dev-setup.h"
|
||||
#include "fileio.h"
|
||||
|
||||
void udev_main_log(struct udev *udev, int priority,
|
||||
const char *file, int line, const char *fn,
|
||||
const char *format, va_list args) {
|
||||
log_metav(priority, file, line, fn, format, args);
|
||||
}
|
||||
|
||||
static struct udev_rules *rules;
|
||||
static struct udev_ctrl *udev_ctrl;
|
||||
static struct udev_monitor *monitor;
|
||||
@ -80,6 +74,7 @@ static sigset_t sigmask_orig;
|
||||
static UDEV_LIST(event_list);
|
||||
static UDEV_LIST(worker_list);
|
||||
static char *udev_cgroup;
|
||||
static struct udev_list properties_list;
|
||||
static bool udev_exit;
|
||||
|
||||
enum event_state {
|
||||
@ -636,7 +631,6 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) {
|
||||
if (i >= 0) {
|
||||
log_debug("udevd message (SET_LOG_LEVEL) received, log_priority=%i", i);
|
||||
log_set_max_level(i);
|
||||
udev_set_log_priority(udev, i);
|
||||
worker_kill(udev);
|
||||
}
|
||||
|
||||
@ -669,10 +663,10 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) {
|
||||
val = &val[1];
|
||||
if (val[0] == '\0') {
|
||||
log_debug("udevd message (ENV) received, unset '%s'", key);
|
||||
udev_add_property(udev, key, NULL);
|
||||
udev_list_entry_add(&properties_list, key, NULL);
|
||||
} else {
|
||||
log_debug("udevd message (ENV) received, set '%s=%s'", key, val);
|
||||
udev_add_property(udev, key, val);
|
||||
udev_list_entry_add(&properties_list, key, val);
|
||||
}
|
||||
} else {
|
||||
log_error("wrong key format '%s'", key);
|
||||
@ -1011,7 +1005,6 @@ static void kernel_cmdline_options(struct udev *udev) {
|
||||
|
||||
prio = util_log_priority(value);
|
||||
log_set_max_level(prio);
|
||||
udev_set_log_priority(udev, prio);
|
||||
} else if ((value = startswith(opt, "udev.children-max="))) {
|
||||
r = safe_atoi(value, &arg_children_max);
|
||||
if (r < 0)
|
||||
@ -1146,19 +1139,14 @@ int main(int argc, char *argv[]) {
|
||||
log_set_target(LOG_TARGET_AUTO);
|
||||
log_open();
|
||||
|
||||
udev_set_log_fn(udev, udev_main_log);
|
||||
log_set_max_level(udev_get_log_priority(udev));
|
||||
|
||||
r = parse_argv(argc, argv);
|
||||
if (r <= 0)
|
||||
goto exit;
|
||||
|
||||
kernel_cmdline_options(udev);
|
||||
|
||||
if (arg_debug) {
|
||||
if (arg_debug)
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
udev_set_log_priority(udev, LOG_DEBUG);
|
||||
}
|
||||
|
||||
if (getuid() != 0) {
|
||||
log_error("root privileges required");
|
||||
@ -1180,6 +1168,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
umask(022);
|
||||
|
||||
udev_list_init(udev, &properties_list, true);
|
||||
|
||||
r = mkdir("/run/udev", 0755);
|
||||
if (r < 0 && errno != EEXIST) {
|
||||
log_error("could not create /run/udev: %m");
|
||||
|
Loading…
Reference in New Issue
Block a user