Merge pull request #10498 from yuwata/udev-builtin-log

udev-builtin: use log_device_*() macros
This commit is contained in:
Lennart Poettering 2018-10-24 10:53:35 +02:00 committed by GitHub
commit e7b48c45ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 144 additions and 155 deletions

View file

@ -46,14 +46,14 @@
_subsystem ? "SUBSYSTEM=" : NULL, _subsystem, ##__VA_ARGS__); \
})
#define log_device_debug(link, ...) log_device_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
#define log_device_info(link, ...) log_device_full(link, LOG_INFO, 0, ##__VA_ARGS__)
#define log_device_notice(link, ...) log_device_full(link, LOG_NOTICE, 0, ##__VA_ARGS__)
#define log_device_warning(link, ...) log_device_full(link, LOG_WARNING, 0, ##__VA_ARGS__)
#define log_device_error(link, ...) log_device_full(link, LOG_ERR, 0, ##__VA_ARGS__)
#define log_device_debug(device, ...) log_device_full(device, LOG_DEBUG, 0, ##__VA_ARGS__)
#define log_device_info(device, ...) log_device_full(device, LOG_INFO, 0, ##__VA_ARGS__)
#define log_device_notice(device, ...) log_device_full(device, LOG_NOTICE, 0, ##__VA_ARGS__)
#define log_device_warning(device, ...) log_device_full(device, LOG_WARNING, 0, ##__VA_ARGS__)
#define log_device_error(device, ...) log_device_full(device, LOG_ERR, 0, ##__VA_ARGS__)
#define log_device_debug_errno(link, error, ...) log_device_full(link, LOG_DEBUG, error, ##__VA_ARGS__)
#define log_device_info_errno(link, error, ...) log_device_full(link, LOG_INFO, error, ##__VA_ARGS__)
#define log_device_notice_errno(link, error, ...) log_device_full(link, LOG_NOTICE, error, ##__VA_ARGS__)
#define log_device_warning_errno(link, error, ...) log_device_full(link, LOG_WARNING, error, ##__VA_ARGS__)
#define log_device_error_errno(link, error, ...) log_device_full(link, LOG_ERR, error, ##__VA_ARGS__)
#define log_device_debug_errno(device, error, ...) log_device_full(device, LOG_DEBUG, error, ##__VA_ARGS__)
#define log_device_info_errno(device, error, ...) log_device_full(device, LOG_INFO, error, ##__VA_ARGS__)
#define log_device_notice_errno(device, error, ...) log_device_full(device, LOG_NOTICE, error, ##__VA_ARGS__)
#define log_device_warning_errno(device, error, ...) log_device_full(device, LOG_WARNING, error, ##__VA_ARGS__)
#define log_device_error_errno(device, error, ...) log_device_full(device, LOG_ERR, error, ##__VA_ARGS__)

View file

@ -326,7 +326,7 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
else if (errno == ENOENT)
continue;
else
return log_debug_errno(errno, "error reading %s: %m", hwdb_bin_path);
return log_debug_errno(errno, "Failed to open %s: %m", hwdb_bin_path);
}
if (!hwdb->f) {
@ -335,16 +335,16 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
}
if (fstat(fileno(hwdb->f), &hwdb->st) < 0 ||
(size_t)hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8)
return log_debug_errno(errno, "error reading %s: %m", hwdb_bin_path);
(size_t) hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8)
return log_debug_errno(errno, "Failed to read %s: %m", hwdb_bin_path);
hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0);
if (hwdb->map == MAP_FAILED)
return log_debug_errno(errno, "error mapping %s: %m", hwdb_bin_path);
return log_debug_errno(errno, "Failed to map %s: %m", hwdb_bin_path);
if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 ||
(size_t)hwdb->st.st_size != le64toh(hwdb->head->file_size)) {
log_debug("error recognizing the format of %s", hwdb_bin_path);
(size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size)) {
log_debug("Failed to recognize the format of %s", hwdb_bin_path);
return -EINVAL;
}

View file

@ -18,6 +18,7 @@
#include "alloc-util.h"
#include "blkid-util.h"
#include "device-util.h"
#include "efivars.h"
#include "fd-util.h"
#include "gpt.h"
@ -237,9 +238,9 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) {
case 'o':
r = safe_atoi64(optarg, &offset);
if (r < 0)
return r;
return log_device_error_errno(dev, r, "Failed to parse '%s' as an integer: %m", optarg);
if (offset < 0)
return -ERANGE;
return log_device_error_errno(dev, -ERANGE, "Invalid offset %"PRIi64": %m", offset);
break;
case 'R':
noraid = true;
@ -250,7 +251,7 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) {
errno = 0;
pr = blkid_new_probe();
if (!pr)
return errno > 0 ? -errno : -ENOMEM;
return log_device_debug_errno(dev, errno > 0 ? errno : ENOMEM, "Failed to create blkid prober: %m");
blkid_probe_set_superblocks_flags(pr,
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
@ -262,32 +263,33 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) {
r = sd_device_get_devname(dev, &devnode);
if (r < 0)
return r;
return log_device_debug_errno(dev, r, "Failed to get device name: %m");
fd = open(devnode, O_RDONLY|O_CLOEXEC);
if (fd < 0)
return log_debug_errno(errno, "Failure opening block device %s: %m", devnode);
return log_device_debug_errno(dev, errno, "Failed to open block device %s: %m", devnode);
errno = 0;
r = blkid_probe_set_device(pr, fd, offset, 0);
if (r < 0)
return errno > 0 ? -errno : -ENOMEM;
return log_device_debug_errno(dev, errno > 0 ? errno : ENOMEM, "Failed to set device to blkid prober: %m");
log_debug("probe %s %sraid offset=%"PRIi64,
devnode,
noraid ? "no" : "", offset);
log_device_debug(dev, "Probe %s with %sraid and offset=%"PRIi64, devnode, noraid ? "no" : "", offset);
r = probe_superblocks(pr);
if (r < 0)
return r;
return log_device_debug_errno(dev, r, "Failed to probe superblocks: %m");
/* If we are a partition then our parent passed on the root
* partition UUID to us */
/* If the device is a partition then its parent passed the root partition UUID to the device */
(void) sd_device_get_property_value(dev, "ID_PART_GPT_AUTO_ROOT_UUID", &root_partition);
errno = 0;
nvals = blkid_probe_numof_values(pr);
if (nvals < 0)
return log_device_debug_errno(dev, errno > 0 ? errno : ENOMEM, "Failed to get number of probed values: %m");
for (i = 0; i < nvals; i++) {
if (blkid_probe_get_value(pr, i, &name, &data, NULL))
if (blkid_probe_get_value(pr, i, &name, &data, NULL) < 0)
continue;
print_property(dev, test, name, data);
@ -297,7 +299,7 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) {
is_gpt = true;
/* Is this a partition that matches the root partition
* property we inherited from our parent? */
* property inherited from the parent? */
if (root_partition && streq(name, "PART_ENTRY_UUID") && streq(data, root_partition))
udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT", "1");
}

View file

@ -8,6 +8,7 @@
#include <linux/btrfs.h>
#endif
#include "device-util.h"
#include "fd-util.h"
#include "missing.h"
#include "string-util.h"
@ -21,16 +22,16 @@ static int builtin_btrfs(sd_device *dev, int argc, char *argv[], bool test) {
int r;
if (argc != 3 || !streq(argv[1], "ready"))
return -EINVAL;
return log_device_error_errno(dev, EINVAL, "Invalid arguments");
fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
if (fd < 0)
return -errno;
return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
strscpy(args.name, sizeof(args.name), argv[2]);
r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
if (r < 0)
return -errno;
return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(r == 0));
return 0;

View file

@ -9,6 +9,7 @@
#include "sd-hwdb.h"
#include "alloc-util.h"
#include "device-util.h"
#include "hwdb-util.h"
#include "parse-util.h"
#include "string-util.h"
@ -159,17 +160,28 @@ static int builtin_hwdb(sd_device *dev, int argc, char *argv[], bool test) {
}
/* query a specific key given as argument */
if (argv[optind])
return udev_builtin_hwdb_lookup(dev, prefix, argv[optind], filter, test);
if (argv[optind]) {
r = udev_builtin_hwdb_lookup(dev, prefix, argv[optind], filter, test);
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to lookup hwdb: %m");
if (r == 0)
return log_device_debug_errno(dev, ENOENT, "No entry found from hwdb: %m");
return r;
}
/* read data from another device than the device we will store the data */
if (device) {
r = sd_device_new_from_device_id(&srcdev, device);
if (r < 0)
return r;
return log_device_debug_errno(dev, r, "Failed to create sd_device object '%s': %m", device);
}
return udev_builtin_hwdb_search(dev, srcdev, subsystem, prefix, filter, test);
r = udev_builtin_hwdb_search(dev, srcdev, subsystem, prefix, filter, test);
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to lookup hwdb: %m");
if (r == 0)
return log_device_debug_errno(dev, ENOENT, "No entry found from hwdb: %m");
return r;
}
/* called at udev startup and reload */

View file

@ -15,6 +15,7 @@
#include <linux/limits.h>
#include <linux/input.h>
#include "device-util.h"
#include "fd-util.h"
#include "missing.h"
#include "stdio-util.h"
@ -75,8 +76,7 @@ static void extract_info(sd_device *dev, const char *devpath, bool test) {
* @param attr sysfs attribute name (e. g. "capabilities/key")
* @param bitmask: Output array which has a sizeof of bitmask_size
*/
static void get_cap_mask(sd_device *dev,
sd_device *pdev, const char* attr,
static void get_cap_mask(sd_device *pdev, const char* attr,
unsigned long *bitmask, size_t bitmask_size,
bool test) {
const char *v;
@ -89,16 +89,16 @@ static void get_cap_mask(sd_device *dev,
v = "";
xsprintf(text, "%s", v);
log_debug("%s raw kernel attribute: %s", attr, text);
log_device_debug(pdev, "%s raw kernel attribute: %s", attr, text);
memzero(bitmask, bitmask_size);
i = 0;
while ((word = strrchr(text, ' ')) != NULL) {
val = strtoul (word+1, NULL, 16);
if (i < bitmask_size/sizeof(unsigned long))
val = strtoul(word+1, NULL, 16);
if (i < bitmask_size / sizeof(unsigned long))
bitmask[i] = val;
else
log_debug("ignoring %s block %lX which is larger than maximum size", attr, val);
log_device_debug(pdev, "Ignoring %s block %lX which is larger than maximum size", attr, val);
*word = '\0';
++i;
}
@ -106,20 +106,20 @@ static void get_cap_mask(sd_device *dev,
if (i < bitmask_size / sizeof(unsigned long))
bitmask[i] = val;
else
log_debug("ignoring %s block %lX which is larger than maximum size", attr, val);
log_device_debug(pdev, "Ignoring %s block %lX which is larger than maximum size", attr, val);
if (test) {
/* printf pattern with the right unsigned long number of hex chars */
xsprintf(text, " bit %%4u: %%0%zulX\n",
2 * sizeof(unsigned long));
log_debug("%s decoded bit map:", attr);
log_device_debug(pdev, "%s decoded bit map:", attr);
val = bitmask_size / sizeof (unsigned long);
/* skip over leading zeros */
while (bitmask[val-1] == 0 && val > 0)
--val;
for (i = 0; i < val; ++i) {
DISABLE_WARNING_FORMAT_NONLITERAL;
log_debug(text, i * BITS_PER_LONG, bitmask[i]);
log_device_debug(pdev, text, i * BITS_PER_LONG, bitmask[i]);
REENABLE_WARNING;
}
}
@ -259,7 +259,7 @@ static bool test_key(sd_device *dev,
/* do we have any KEY_* capability? */
if (!test_bit(EV_KEY, bitmask_ev)) {
log_debug("test_key: no EV_KEY capability");
log_device_debug(dev, "test_key: no EV_KEY capability");
return false;
}
@ -267,7 +267,7 @@ static bool test_key(sd_device *dev,
found = 0;
for (i = 0; i < BTN_MISC/BITS_PER_LONG; ++i) {
found |= bitmask_key[i];
log_debug("test_key: checking bit block %lu for any keys; found=%i", (unsigned long)i*BITS_PER_LONG, found > 0);
log_device_debug(dev, "test_key: checking bit block %lu for any keys; found=%i", (unsigned long)i*BITS_PER_LONG, found > 0);
}
/* If there are no keys in the lower block, check the higher blocks */
if (!found) {
@ -275,7 +275,7 @@ static bool test_key(sd_device *dev,
for (block = 0; block < (sizeof(high_key_blocks) / sizeof(struct range)); ++block) {
for (i = high_key_blocks[block].start; i < high_key_blocks[block].end; ++i) {
if (test_bit(i, bitmask_key)) {
log_debug("test_key: Found key %x in high block", i);
log_device_debug(dev, "test_key: Found key %x in high block", i);
found = 1;
break;
}
@ -331,11 +331,11 @@ static int builtin_input_id(sd_device *dev, int argc, char *argv[], bool test) {
/* Use this as a flag that input devices were detected, so that this
* program doesn't need to be called more than once per device */
udev_builtin_add_property(dev, test, "ID_INPUT", "1");
get_cap_mask(dev, pdev, "capabilities/ev", bitmask_ev, sizeof(bitmask_ev), test);
get_cap_mask(dev, pdev, "capabilities/abs", bitmask_abs, sizeof(bitmask_abs), test);
get_cap_mask(dev, pdev, "capabilities/rel", bitmask_rel, sizeof(bitmask_rel), test);
get_cap_mask(dev, pdev, "capabilities/key", bitmask_key, sizeof(bitmask_key), test);
get_cap_mask(dev, pdev, "properties", bitmask_props, sizeof(bitmask_props), test);
get_cap_mask(pdev, "capabilities/ev", bitmask_ev, sizeof(bitmask_ev), test);
get_cap_mask(pdev, "capabilities/abs", bitmask_abs, sizeof(bitmask_abs), test);
get_cap_mask(pdev, "capabilities/rel", bitmask_rel, sizeof(bitmask_rel), test);
get_cap_mask(pdev, "capabilities/key", bitmask_key, sizeof(bitmask_key), test);
get_cap_mask(pdev, "properties", bitmask_props, sizeof(bitmask_props), test);
is_pointer = test_pointers(dev, bitmask_ev, bitmask_abs,
bitmask_key, bitmask_rel,
bitmask_props, test);

View file

@ -33,11 +33,11 @@ static int install_force_release(sd_device *dev, const unsigned *release, unsign
r = sd_device_get_parent_with_subsystem_devtype(dev, "serio", NULL, &atkbd);
if (r < 0)
return r;
return log_device_error_errno(dev, r, "Failed to get serio parent: %m");
r = sd_device_get_sysattr_value(atkbd, "force_release", &cur);
if (r < 0)
return r;
return log_device_error_errno(atkbd, r, "Failed to get force-release attribute: %m");
s = codes;
l = sizeof(codes);
@ -49,15 +49,15 @@ static int install_force_release(sd_device *dev, const unsigned *release, unsign
for (i = 0; i < release_count; i++)
l = strpcpyf(&s, l, ",%u", release[i]);
log_debug("keyboard: updating force-release list with '%s'", codes);
log_device_debug(atkbd, "keyboard: updating force-release list with '%s'", codes);
r = sd_device_set_sysattr_value(atkbd, "force_release", codes);
if (r < 0)
return log_error_errno(r, "Error writing force-release attribute: %m");
return log_device_error_errno(atkbd, r, "Failed to set force-release attribute: %m");
return 0;
}
static void map_keycode(int fd, const char *devnode, int scancode, const char *keycode) {
static int map_keycode(sd_device *dev, int fd, int scancode, const char *keycode) {
struct {
unsigned scan;
unsigned key;
@ -73,20 +73,20 @@ static void map_keycode(int fd, const char *devnode, int scancode, const char *k
} else {
/* check if it's a numeric code already */
keycode_num = strtoul(keycode, &endptr, 0);
if (endptr[0] !='\0') {
log_error("Unknown key identifier '%s'", keycode);
return;
}
if (endptr[0] !='\0')
return log_device_error_errno(dev, EINVAL, "Failed to parse key identifier '%s'", keycode);
}
map.scan = scancode;
map.key = keycode_num;
log_debug("keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
map.scan, map.scan, map.key, map.key);
log_device_debug(dev, "keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
map.scan, map.scan, map.key, map.key);
if (ioctl(fd, EVIOCSKEYCODE, &map) < 0)
log_error_errno(errno, "Error calling EVIOCSKEYCODE on device node '%s' (scan code 0x%x, key code %d): %m", devnode, map.scan, map.key);
return log_device_error_errno(dev, errno, "Failed to call EVIOCSKEYCODE with scan code 0x%x, and key code %d: %m", map.scan, map.key);
return 0;
}
static inline char* parse_token(const char *current, int32_t *val_out) {
@ -109,80 +109,60 @@ static inline char* parse_token(const char *current, int32_t *val_out) {
return next;
}
static void override_abs(int fd, const char *devnode,
unsigned evcode, const char *value) {
static int override_abs(sd_device *dev, int fd, unsigned evcode, const char *value) {
struct input_absinfo absinfo;
int rc;
char *next;
int r;
rc = ioctl(fd, EVIOCGABS(evcode), &absinfo);
if (rc < 0) {
log_error_errno(errno, "Unable to EVIOCGABS device \"%s\"", devnode);
return;
}
r = ioctl(fd, EVIOCGABS(evcode), &absinfo);
if (r < 0)
return log_device_error_errno(dev, errno, "Failed to call EVIOCGABS");
next = parse_token(value, &absinfo.minimum);
next = parse_token(next, &absinfo.maximum);
next = parse_token(next, &absinfo.resolution);
next = parse_token(next, &absinfo.fuzz);
next = parse_token(next, &absinfo.flat);
if (!next) {
log_error("Unable to parse EV_ABS override '%s' for '%s'", value, devnode);
return;
}
if (!next)
return log_device_error(dev, "Failed to parse EV_ABS override '%s'", value);
log_debug("keyboard: %x overridden with %"PRIi32"/%"PRIi32"/%"PRIi32"/%"PRIi32"/%"PRIi32" for \"%s\"",
evcode,
absinfo.minimum, absinfo.maximum, absinfo.resolution, absinfo.fuzz, absinfo.flat,
devnode);
rc = ioctl(fd, EVIOCSABS(evcode), &absinfo);
if (rc < 0)
log_error_errno(errno, "Unable to EVIOCSABS device \"%s\"", devnode);
log_device_debug(dev, "keyboard: %x overridden with %"PRIi32"/%"PRIi32"/%"PRIi32"/%"PRIi32"/%"PRIi32,
evcode, absinfo.minimum, absinfo.maximum, absinfo.resolution, absinfo.fuzz, absinfo.flat);
r = ioctl(fd, EVIOCSABS(evcode), &absinfo);
if (r < 0)
return log_device_error_errno(dev, errno, "Failed to call EVIOCSABS");
return 0;
}
static int set_trackpoint_sensitivity(sd_device *dev, const char *value) {
sd_device *pdev;
char val_s[DECIMAL_STR_MAX(int)];
const char *devnode;
int r, val_i;
assert(dev);
assert(value);
r = sd_device_get_devname(dev, &devnode);
if (r < 0)
return log_error_errno(r, "Failed to get devname: %m");
/* The sensitivity sysfs attr belongs to the serio parent device */
r = sd_device_get_parent_with_subsystem_devtype(dev, "serio", NULL, &pdev);
if (r < 0)
return log_warning_errno(r, "Failed to get serio parent for '%s': %m", devnode);
return log_device_error_errno(dev, r, "Failed to get serio parent: %m");
r = safe_atoi(value, &val_i);
if (r < 0)
return log_error_errno(r, "Unable to parse POINTINGSTICK_SENSITIVITY '%s' for '%s': %m", value, devnode);
return log_device_error_errno(dev, r, "Failed to parse POINTINGSTICK_SENSITIVITY '%s': %m", value);
else if (val_i < 0 || val_i > 255)
return log_error_errno(ERANGE, "POINTINGSTICK_SENSITIVITY %d outside range [0..255] for '%s'", val_i, devnode);
return log_device_error_errno(dev, ERANGE, "POINTINGSTICK_SENSITIVITY %d outside range [0..255]", val_i);
xsprintf(val_s, "%d", val_i);
r = sd_device_set_sysattr_value(pdev, "sensitivity", val_s);
if (r < 0)
return log_error_errno(r, "Failed to write 'sensitivity' attribute for '%s': %m", devnode);
return log_device_error_errno(dev, r, "Failed to write 'sensitivity' attribute: %m");
return 0;
}
static int open_device(const char *devnode) {
int fd;
fd = open(devnode, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return log_error_errno(errno, "Error opening device \"%s\": %m", devnode);
return fd;
}
static int builtin_keyboard(sd_device *dev, int argc, char *argv[], bool test) {
unsigned release[1024];
unsigned release_count = 0;
@ -191,12 +171,8 @@ static int builtin_keyboard(sd_device *dev, int argc, char *argv[], bool test) {
int has_abs = -1, r;
r = sd_device_get_devname(dev, &node);
if (r < 0) {
const char *s = NULL;
(void) sd_device_get_syspath(dev, &s);
return log_error_errno(r, "No device node for \"%s\": %m", strnull(s));
}
if (r < 0)
return log_device_error_errno(dev, r, "Failed to get device name: %m");
FOREACH_DEVICE_PROPERTY(dev, key, value) {
char *endptr;
@ -208,7 +184,7 @@ static int builtin_keyboard(sd_device *dev, int argc, char *argv[], bool test) {
/* KEYBOARD_KEY_<hex scan code>=<key identifier string> */
scancode = strtoul(key + 13, &endptr, 16);
if (endptr[0] != '\0') {
log_warning("Unable to parse scan code from \"%s\"", key);
log_device_warning(dev, "Failed to parse scan code from \"%s\", ignoring", key);
continue;
}
@ -224,27 +200,27 @@ static int builtin_keyboard(sd_device *dev, int argc, char *argv[], bool test) {
continue;
}
if (fd == -1) {
fd = open_device(node);
if (fd < 0) {
fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return fd;
return log_device_error_errno(dev, errno, "Failed to open device '%s': %m", node);
}
map_keycode(fd, node, scancode, keycode);
(void) map_keycode(dev, fd, scancode, keycode);
} else if (startswith(key, "EVDEV_ABS_")) {
unsigned evcode;
/* EVDEV_ABS_<EV_ABS code>=<min>:<max>:<res>:<fuzz>:<flat> */
evcode = strtoul(key + 10, &endptr, 16);
if (endptr[0] != '\0') {
log_warning("Unable to parse EV_ABS code from \"%s\"", key);
log_device_warning(dev, "Failed to parse EV_ABS code from \"%s\", ignoring", key);
continue;
}
if (fd == -1) {
fd = open_device(node);
if (fd < 0) {
fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return fd;
return log_device_error_errno(dev, errno, "Failed to open device '%s': %m", node);
}
if (has_abs == -1) {
@ -253,24 +229,24 @@ static int builtin_keyboard(sd_device *dev, int argc, char *argv[], bool test) {
rc = ioctl(fd, EVIOCGBIT(0, sizeof(bits)), &bits);
if (rc < 0)
return log_error_errno(errno, "Unable to EVIOCGBIT device \"%s\"", node);
return log_device_error_errno(dev, errno, "Failed to set EVIOCGBIT");
has_abs = !!(bits & (1 << EV_ABS));
if (!has_abs)
log_warning("EVDEV_ABS override set but no EV_ABS present on device \"%s\"", node);
log_device_warning(dev, "EVDEV_ABS override set but no EV_ABS present on device");
}
if (!has_abs)
continue;
override_abs(fd, node, evcode, value);
(void) override_abs(dev, fd, evcode, value);
} else if (streq(key, "POINTINGSTICK_SENSITIVITY"))
set_trackpoint_sensitivity(dev, value);
(void) set_trackpoint_sensitivity(dev, value);
}
/* install list of force-release codes */
if (release_count > 0)
install_force_release(dev, release, release_count);
(void) install_force_release(dev, release, release_count);
return 0;
}

View file

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "device-util.h"
#include "alloc-util.h"
#include "link-config.h"
#include "log.h"
@ -14,10 +15,8 @@ static int builtin_net_setup_link(sd_device *dev, int argc, char **argv, bool te
link_config *link;
int r;
if (argc > 1) {
log_error("This program takes no arguments.");
return -EINVAL;
}
if (argc > 1)
return log_device_error_errno(dev, EINVAL, "This program takes no arguments.");
r = link_get_driver(ctx, dev, &driver);
if (r >= 0)
@ -26,18 +25,14 @@ static int builtin_net_setup_link(sd_device *dev, int argc, char **argv, bool te
r = link_config_get(ctx, dev, &link);
if (r < 0) {
if (r == -ENOENT)
return log_debug_errno(r, "No matching link configuration found.");
return log_device_debug_errno(dev, r, "No matching link configuration found.");
return log_error_errno(r, "Could not get link config: %m");
return log_device_error_errno(dev, r, "Failed to get link config: %m");
}
r = link_config_apply(ctx, link, dev, &name);
if (r < 0) {
const char *sysname = NULL;
(void) sd_device_get_sysname(dev, &sysname);
log_warning_errno(r, "Could not apply link config to %s, ignoring: %m", strnull(sysname));
}
if (r < 0)
log_device_warning_errno(dev, r, "Could not apply link config, ignoring: %m");
udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->filename);

View file

@ -10,16 +10,17 @@
#include "sd-login.h"
#include "device-util.h"
#include "login-util.h"
#include "logind-acl.h"
#include "log.h"
#include "udev-builtin.h"
static int builtin_uaccess(sd_device *dev, int argc, char *argv[], bool test) {
int r;
const char *path = NULL, *seat;
bool changed_acl = false;
uid_t uid;
int r;
umask(0022);
@ -29,6 +30,7 @@ static int builtin_uaccess(sd_device *dev, int argc, char *argv[], bool test) {
r = sd_device_get_devname(dev, &path);
if (r < 0)
log_device_error_errno(dev, r, "Failed to get device name: %m");
goto finish;
if (sd_device_get_property_value(dev, "ID_SEAT", &seat) < 0)
@ -40,14 +42,14 @@ static int builtin_uaccess(sd_device *dev, int argc, char *argv[], bool test) {
/* No active session on this seat */
r = 0;
else
log_error_errno(r, "Failed to determine active user on seat %s: %m", seat);
log_device_error_errno(dev, r, "Failed to determine active user on seat %s: %m", seat);
goto finish;
}
r = devnode_acl(path, true, false, 0, true, uid);
if (r < 0) {
log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to apply ACL on %s: %m", path);
log_device_full(dev, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to apply ACL: %m");
goto finish;
}
@ -61,7 +63,7 @@ finish:
/* Better be safe than sorry and reset ACL */
k = devnode_acl(path, true, false, 0, false, 0);
if (k < 0) {
log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, k, "Failed to apply ACL on %s: %m", path);
log_device_full(dev, errno == ENOENT ? LOG_DEBUG : LOG_ERR, k, "Failed to apply ACL: %m");
if (r >= 0)
r = k;
}

View file

@ -16,6 +16,7 @@
#include <unistd.h>
#include "alloc-util.h"
#include "device-util.h"
#include "fd-util.h"
#include "libudev-private.h"
#include "string-util.h"
@ -164,7 +165,7 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
fd = open(filename, O_RDONLY|O_CLOEXEC);
if (fd < 0)
return log_debug_errno(errno, "Error opening USB device 'descriptors' file: %m");
return log_device_debug_errno(dev, errno, "Failed to open USB device 'descriptors' file: %m");
size = read(fd, buf, sizeof(buf));
if (size < 18 || (size_t) size >= sizeof(buf))
@ -269,17 +270,17 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) {
/* usb interface directory */
r = sd_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface", &dev_interface);
if (r < 0)
return log_debug_errno(r, "Failed to access usb_interface device of '%s': %m", syspath);
return log_device_debug_errno(dev, r, "Failed to access usb_interface: %m");
r = sd_device_get_syspath(dev_interface, &interface_syspath);
if (r < 0)
return r;
return log_device_debug_errno(dev_interface, r, "Failed to get syspath: %m");
(void) sd_device_get_sysattr_value(dev_interface, "bInterfaceNumber", &ifnum);
(void) sd_device_get_sysattr_value(dev_interface, "driver", &driver);
r = sd_device_get_sysattr_value(dev_interface, "bInterfaceClass", &if_class);
if (r < 0)
return log_debug_errno(r, "Failed to get bInterfaceClass attribute of '%s': %m", sysname);
return log_device_debug_errno(dev_interface, r, "Failed to get bInterfaceClass attribute: %m");
if_class_num = strtoul(if_class, NULL, 16);
if (if_class_num == 8) {
@ -289,12 +290,12 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) {
} else
set_usb_iftype(type_str, if_class_num, sizeof(type_str)-1);
log_debug("%s: if_class %d protocol %d", interface_syspath, if_class_num, protocol);
log_device_debug(dev_interface, "if_class:%d protocol:%d", if_class_num, protocol);
/* usb device directory */
r = sd_device_get_parent_with_subsystem_devtype(dev_interface, "usb", "usb_device", &dev_usb);
if (r < 0)
return log_debug_errno(r, "Failed to find parent 'usb' device of '%s'", syspath);
return log_device_debug_errno(dev_interface, r, "Failed to find parent 'usb' device");
/* all interfaces of the device in a single string */
dev_if_packed_info(dev_usb, packed_if_str, sizeof(packed_if_str));
@ -308,20 +309,20 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) {
/* get scsi device */
r = sd_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device", &dev_scsi);
if (r < 0) {
log_debug_errno(r, "Unable to find parent 'scsi' device of '%s'", syspath);
log_device_debug_errno(dev, r, "Unable to find parent SCSI device");
goto fallback;
}
if (sd_device_get_sysname(dev_scsi, &scsi_sysname) < 0)
goto fallback;
if (sscanf(scsi_sysname, "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4) {
log_debug("invalid scsi device '%s'", scsi_sysname);
log_device_debug(dev_scsi, "Invalid SCSI device");
goto fallback;
}
/* Generic SPC-2 device */
r = sd_device_get_sysattr_value(dev_scsi, "vendor", &scsi_vendor);
if (r < 0) {
log_debug_errno(r, "%s: cannot get SCSI vendor attribute: %m", scsi_sysname);
log_device_debug_errno(dev_scsi, r, "Failed to get SCSI vendor attribute: %m");
goto fallback;
}
udev_util_encode_string(scsi_vendor, vendor_str_enc, sizeof(vendor_str_enc));
@ -330,7 +331,7 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) {
r = sd_device_get_sysattr_value(dev_scsi, "model", &scsi_model);
if (r < 0) {
log_debug_errno(r, "%s: cannot get SCSI model attribute: %m", scsi_sysname);
log_device_debug_errno(dev_scsi, r, "Failed to get SCSI model attribute: %m");
goto fallback;
}
udev_util_encode_string(scsi_model, model_str_enc, sizeof(model_str_enc));
@ -339,14 +340,14 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) {
r = sd_device_get_sysattr_value(dev_scsi, "type", &scsi_type);
if (r < 0) {
log_debug_errno(r, "%s: cannot get SCSI type attribute", scsi_sysname);
log_device_debug_errno(dev_scsi, r, "Failed to get SCSI type attribute: %m");
goto fallback;
}
set_scsi_type(type_str, scsi_type, sizeof(type_str)-1);
r = sd_device_get_sysattr_value(dev_scsi, "rev", &scsi_rev);
if (r < 0) {
log_debug_errno(r, "%s: cannot get SCSI revision attribute: %m", scsi_sysname);
log_device_debug_errno(dev_scsi, r, "Failed to get SCSI revision attribute: %m");
goto fallback;
}
util_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1);
@ -362,11 +363,11 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) {
fallback:
r = sd_device_get_sysattr_value(dev_usb, "idVendor", &vendor_id);
if (r < 0)
return r;
return log_device_debug_errno(dev_usb, r, "Failed to get idVendor attribute: %m");
r = sd_device_get_sysattr_value(dev_usb, "idProduct", &product_id);
if (r < 0)
return r;
return log_device_debug_errno(dev_usb, r, "Failed to get idProduct attribute: %m");
/* fallback to USB vendor & device */
if (vendor_str[0] == '\0') {
@ -405,7 +406,7 @@ fallback:
const unsigned char *p;
/* http://msdn.microsoft.com/en-us/library/windows/hardware/gg487321.aspx */
for (p = (unsigned char *)usb_serial; *p != '\0'; p++)
for (p = (unsigned char *) usb_serial; *p != '\0'; p++)
if (*p < 0x20 || *p > 0x7f || *p == ',') {
usb_serial = NULL;
break;