diff options
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/.gitignore | 1 | ||||
-rw-r--r-- | src/udev/ata_id/ata_id.c | 8 | ||||
-rw-r--r-- | src/udev/cdrom_id/cdrom_id.c | 5 | ||||
-rw-r--r-- | src/udev/collect/collect.c | 2 | ||||
-rw-r--r-- | src/udev/net/ethtool-util.c | 3 | ||||
-rw-r--r-- | src/udev/net/link-config.c | 4 | ||||
-rw-r--r-- | src/udev/net/link-config.h | 1 | ||||
-rw-r--r-- | src/udev/scsi_id/scsi_id.c | 15 | ||||
-rw-r--r-- | src/udev/scsi_id/scsi_serial.c | 9 | ||||
-rw-r--r-- | src/udev/udev-builtin-keyboard.c | 3 | ||||
-rw-r--r-- | src/udev/udev-builtin-path_id.c | 46 | ||||
-rw-r--r-- | src/udev/udev-builtin-uaccess.c | 2 | ||||
-rw-r--r-- | src/udev/udev-ctrl.c | 14 | ||||
-rw-r--r-- | src/udev/udev-event.c | 26 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 25 | ||||
-rw-r--r-- | src/udev/udev-watch.c | 5 | ||||
-rw-r--r-- | src/udev/udevadm-settle.c | 7 | ||||
-rw-r--r-- | src/udev/udevd.c | 46 |
18 files changed, 108 insertions, 114 deletions
diff --git a/src/udev/.gitignore b/src/udev/.gitignore index ba112ce218..f5d8be3dc1 100644 --- a/src/udev/.gitignore +++ b/src/udev/.gitignore @@ -1,5 +1,4 @@ /udev.pc /keyboard-keys-from-name.gperf /keyboard-keys-from-name.h -/keyboard-keys-to-name.h /keyboard-keys-list.txt diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index c6a2c56e77..1d1798dd10 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -432,7 +432,7 @@ int main(int argc, char *argv[]) if (udev == NULL) return 0; - while (1) { + for (;;) { int option; option = getopt_long(argc, argv, "xh", options, NULL); @@ -473,7 +473,7 @@ int main(int argc, char *argv[]) disk_identify_fixup_string(identify.byte, 27, 40); /* model */ disk_identify_fixup_uint16(identify.byte, 0); /* configuration */ disk_identify_fixup_uint16(identify.byte, 75); /* queue depth */ - disk_identify_fixup_uint16(identify.byte, 75); /* SATA capabilities */ + disk_identify_fixup_uint16(identify.byte, 76); /* SATA capabilities */ disk_identify_fixup_uint16(identify.byte, 82); /* command set supported */ disk_identify_fixup_uint16(identify.byte, 83); /* command set supported */ disk_identify_fixup_uint16(identify.byte, 84); /* command set supported */ @@ -484,6 +484,10 @@ int main(int argc, char *argv[]) disk_identify_fixup_uint16(identify.byte, 90); /* time required for enhanced SECURITY ERASE UNIT */ disk_identify_fixup_uint16(identify.byte, 91); /* current APM values */ disk_identify_fixup_uint16(identify.byte, 94); /* current AAM value */ + disk_identify_fixup_uint16(identify.byte, 108); /* WWN */ + disk_identify_fixup_uint16(identify.byte, 109); /* WWN */ + disk_identify_fixup_uint16(identify.byte, 110); /* WWN */ + disk_identify_fixup_uint16(identify.byte, 111); /* WWN */ disk_identify_fixup_uint16(identify.byte, 128); /* device lock function */ disk_identify_fixup_uint16(identify.byte, 217); /* nominal media rotation rate */ memcpy(&id, identify.byte, sizeof id); diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 775da0355d..001bae7a24 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -565,9 +565,8 @@ static int cd_profiles(struct udev *udev, int fd) if (len > sizeof(features)) { log_debug("can not get features in a single query, truncating"); len = sizeof(features); - } else if (len <= 8) { + } else if (len <= 8) len = sizeof(features); - } /* Now get the full feature buffer */ scsi_cmd_init(udev, &sc); @@ -869,7 +868,7 @@ int main(int argc, char *argv[]) if (udev == NULL) goto exit; - while (1) { + for (;;) { int option; option = getopt_long(argc, argv, "deluh", options, NULL); diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 6cf41c67bb..b3a1f0bca1 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -364,7 +364,7 @@ int main(int argc, char **argv) goto exit; } - while (1) { + for (;;) { int option; option = getopt_long(argc, argv, "ardh", options, NULL); diff --git a/src/udev/net/ethtool-util.c b/src/udev/net/ethtool-util.c index 927b8abc64..a4b05d1bec 100644 --- a/src/udev/net/ethtool-util.c +++ b/src/udev/net/ethtool-util.c @@ -54,9 +54,8 @@ int ethtool_connect(int *ret) { assert_return(ret, -EINVAL); fd = socket(PF_INET, SOCK_DGRAM, 0); - if (fd < 0) { + if (fd < 0) return -errno; - } *ret = fd; diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 63e54db56e..4b8c5053a4 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -460,6 +460,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, mac = &generated_mac; } break; + case MACPOLICY_NONE: default: mac = config->mac; } @@ -492,7 +493,8 @@ int link_get_driver(link_config_ctx *ctx, struct udev_device *device, char **ret static const char* const mac_policy_table[_MACPOLICY_MAX] = { [MACPOLICY_PERSISTENT] = "persistent", - [MACPOLICY_RANDOM] = "random" + [MACPOLICY_RANDOM] = "random", + [MACPOLICY_NONE] = "none" }; DEFINE_STRING_TABLE_LOOKUP(mac_policy, MACPolicy); diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h index 9875057e84..c52db2ce55 100644 --- a/src/udev/net/link-config.h +++ b/src/udev/net/link-config.h @@ -32,6 +32,7 @@ typedef struct link_config link_config; typedef enum MACPolicy { MACPOLICY_PERSISTENT, MACPOLICY_RANDOM, + MACPOLICY_NONE, _MACPOLICY_MAX, _MACPOLICY_INVALID = -1 } MACPolicy; diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index a1b8e75fac..adb91869df 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -190,7 +190,7 @@ static int get_file_options(struct udev *udev, *newargv = NULL; lineno = 0; - while (1) { + for (;;) { vendor_in = model_in = options_in = NULL; buf = fgets(buffer, MAX_BUFFER_LEN, f); @@ -279,9 +279,9 @@ static int get_file_options(struct udev *udev, strcpy(buffer, options_in); c = argc_count(buffer) + 2; *newargv = calloc(c, sizeof(**newargv)); - if (!*newargv) { + if (!*newargv) retval = log_oom(); - } else { + else { *argc = c; c = 0; /* @@ -537,16 +537,13 @@ static int scsi_id(struct udev *udev, char *maj_min_dev) if (dev_scsi.wwn_vendor_extension[0] != '\0') { printf("ID_WWN_VENDOR_EXTENSION=0x%s\n", dev_scsi.wwn_vendor_extension); printf("ID_WWN_WITH_EXTENSION=0x%s%s\n", dev_scsi.wwn, dev_scsi.wwn_vendor_extension); - } else { + } else printf("ID_WWN_WITH_EXTENSION=0x%s\n", dev_scsi.wwn); - } } - if (dev_scsi.tgpt_group[0] != '\0') { + if (dev_scsi.tgpt_group[0] != '\0') printf("ID_TARGET_PORT=%s\n", dev_scsi.tgpt_group); - } - if (dev_scsi.unit_serial_number[0] != '\0') { + if (dev_scsi.unit_serial_number[0] != '\0') printf("ID_SCSI_SERIAL=%s\n", dev_scsi.unit_serial_number); - } goto out; } diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index 3691a69d48..de3b4f7581 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -135,9 +135,8 @@ static int sg_err_category_new(struct udev *udev, return SG_ERR_CAT_MEDIA_CHANGED; if (0x29 == asc) return SG_ERR_CAT_RESET; - } else if (sense_key == ILLEGAL_REQUEST) { + } else if (sense_key == ILLEGAL_REQUEST) return SG_ERR_CAT_NOTSUPPORTED; - } } return SG_ERR_CAT_SENSE; } @@ -490,9 +489,8 @@ static int check_fill_0x83_id(struct udev *udev, if ((page_83[1] & 0x30) == 0x10) { if (id_search->id_type != SCSI_ID_TGTGROUP) return 1; - } else if ((page_83[1] & 0x30) != 0) { + } else if ((page_83[1] & 0x30) != 0) return 1; - } if ((page_83[1] & 0x0f) != id_search->id_type) return 1; @@ -577,9 +575,8 @@ static int check_fill_0x83_id(struct udev *udev, if (id_search->id_type == SCSI_ID_NAA && wwn != NULL) { strncpy(wwn, &serial[s], 16); - if (wwn_vendor_extension != NULL) { + if (wwn_vendor_extension != NULL) strncpy(wwn_vendor_extension, &serial[s + 16], 16); - } } return 0; diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index 01f3879f37..d63a8e2760 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -255,9 +255,8 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo } override_abs(fd, node, evcode, udev_list_entry_get_value(entry)); - } else if (streq(key, "POINTINGSTICK_SENSITIVITY")) { + } else if (streq(key, "POINTINGSTICK_SENSITIVITY")) set_trackpoint_sensitivity(dev, udev_list_entry_get_value(entry)); - } } /* install list of force-release codes */ diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index f529ffcf25..01e2c659ae 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -317,6 +317,39 @@ out: return parent; } +static struct udev_device *handle_scsi_ata(struct udev_device *parent, char **path) { + struct udev *udev = udev_device_get_udev(parent); + struct udev_device *targetdev; + struct udev_device *target_parent; + struct udev_device *atadev; + const char *port_no; + + assert(parent); + assert(path); + + targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host"); + if (!targetdev) + return NULL; + + target_parent = udev_device_get_parent(targetdev); + if (!target_parent) + return NULL; + + atadev = udev_device_new_from_subsystem_sysname(udev, "ata_port", udev_device_get_sysname(target_parent)); + if (!atadev) + return NULL; + + port_no = udev_device_get_sysattr_value(atadev, "port_no"); + if (!port_no) { + parent = NULL; + goto out; + } + path_prepend(path, "ata-%s", port_no); +out: + udev_device_unref(atadev); + return parent; +} + static struct udev_device *handle_scsi_default(struct udev_device *parent, char **path) { struct udev_device *hostdev; int host, bus, target, lun; @@ -482,19 +515,8 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path, goto out; } - /* - * We do not support the ATA transport class, it uses global counters - * to name the ata devices which numbers spread across multiple - * controllers. - * - * The real link numbers are not exported. Also, possible chains of ports - * behind port multipliers cannot be composed that way. - * - * Until all that is solved at the kernel level, there are no by-path/ - * links for ATA devices. - */ if (strstr(name, "/ata") != NULL) { - parent = NULL; + parent = handle_scsi_ata(parent, path); goto out; } diff --git a/src/udev/udev-builtin-uaccess.c b/src/udev/udev-builtin-uaccess.c index 43bab8af63..7bf4e7f24d 100644 --- a/src/udev/udev-builtin-uaccess.c +++ b/src/udev/udev-builtin-uaccess.c @@ -45,7 +45,7 @@ static int builtin_uaccess(struct udev_device *dev, int argc, char *argv[], bool seat = "seat0"; r = sd_seat_get_active(seat, NULL, &uid); - if (r == -ENOENT) { + if (r == -ENXIO || r == -ENODATA) { /* No active session on this seat */ r = 0; goto finish; diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index ead7c92b27..56277f551f 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -121,18 +121,12 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) { err = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen); } - if (err < 0) { - err = -errno; - log_error_errno(errno, "bind failed: %m"); - return err; - } + if (err < 0) + return log_error_errno(errno, "bind failed: %m"); err = listen(uctrl->sock, 0); - if (err < 0) { - err = -errno; - log_error_errno(errno, "listen failed: %m"); - return err; - } + if (err < 0) + return log_error_errno(errno, "listen failed: %m"); uctrl->bound = true; uctrl->cleanup_socket = true; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 4761222786..1e34cbc2f5 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -731,15 +731,13 @@ int udev_event_spawn(struct udev_event *event, /* pipes from child to parent */ if (result != NULL || log_get_max_level() >= LOG_INFO) { if (pipe2(outpipe, O_NONBLOCK) != 0) { - err = -errno; - log_error_errno(errno, "pipe failed: %m"); + err = log_error_errno(errno, "pipe failed: %m"); goto out; } } if (log_get_max_level() >= LOG_INFO) { if (pipe2(errpipe, O_NONBLOCK) != 0) { - err = -errno; - log_error_errno(errno, "pipe failed: %m"); + err = log_error_errno(errno, "pipe failed: %m"); goto out; } } @@ -753,14 +751,8 @@ int udev_event_spawn(struct udev_event *event, char program[UTIL_PATH_SIZE]; /* child closes parent's ends of pipes */ - if (outpipe[READ_END] >= 0) { - close(outpipe[READ_END]); - outpipe[READ_END] = -1; - } - if (errpipe[READ_END] >= 0) { - close(errpipe[READ_END]); - errpipe[READ_END] = -1; - } + outpipe[READ_END] = safe_close(outpipe[READ_END]); + errpipe[READ_END] = safe_close(errpipe[READ_END]); strscpy(arg, sizeof(arg), cmd); udev_build_argv(event->udev, arg, NULL, argv); @@ -784,14 +776,8 @@ int udev_event_spawn(struct udev_event *event, goto out; default: /* parent closed child's ends of pipes */ - if (outpipe[WRITE_END] >= 0) { - close(outpipe[WRITE_END]); - outpipe[WRITE_END] = -1; - } - if (errpipe[WRITE_END] >= 0) { - close(errpipe[WRITE_END]); - errpipe[WRITE_END] = -1; - } + outpipe[WRITE_END] = safe_close(outpipe[WRITE_END]); + errpipe[WRITE_END] = safe_close(errpipe[WRITE_END]); spawn_read(event, timeout_usec, diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 43255fb9d4..10bf3880b0 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -672,9 +672,8 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi const char *key = udev_list_entry_get_name(list_entry); const char *val = udev_list_entry_get_value(list_entry); - if (fnmatch(filter, key, 0) == 0) { + if (fnmatch(filter, key, 0) == 0) udev_device_add_property(dev, key, val); - } } return 0; } @@ -1429,9 +1428,9 @@ static int add_rule(struct udev_rules *rules, char *line, } else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) { uid = add_uid(rules, value); rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid); - } else if (rules->resolve_names >= 0) { + } else if (rules->resolve_names >= 0) rule_add_key(&rule_tmp, TK_A_OWNER, op, value, NULL); - } + rule_tmp.rule.rule.can_set_name = true; continue; } @@ -1451,9 +1450,9 @@ static int add_rule(struct udev_rules *rules, char *line, } else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) { gid = add_gid(rules, value); rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid); - } else if (rules->resolve_names >= 0) { + } else if (rules->resolve_names >= 0) rule_add_key(&rule_tmp, TK_A_GROUP, op, value, NULL); - } + rule_tmp.rule.rule.can_set_name = true; continue; } @@ -1686,12 +1685,10 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) { strbuf_complete(rules->strbuf); /* cleanup uid/gid cache */ - free(rules->uids); - rules->uids = NULL; + rules->uids = mfree(rules->uids); rules->uids_cur = 0; rules->uids_max = 0; - free(rules->gids); - rules->gids = NULL; + rules->gids = mfree(rules->gids); rules->gids_cur = 0; rules->gids_max = 0; @@ -1940,7 +1937,8 @@ int udev_rules_apply_to_event(struct udev_rules *rules, break; } } - if (!match && (cur->key.op != OP_NOMATCH)) + if ((!match && (cur->key.op != OP_NOMATCH)) || + (match && (cur->key.op == OP_NOMATCH))) goto nomatch; break; } @@ -2064,8 +2062,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, char program[UTIL_PATH_SIZE]; char result[UTIL_LINE_SIZE]; - free(event->program_result); - event->program_result = NULL; + event->program_result = mfree(event->program_result); udev_event_apply_format(event, rules_str(rules, cur->key.value_off), program, sizeof(program)); log_debug("PROGRAM '%s' %s:%u", program, @@ -2518,7 +2515,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, rules_str(rules, rule->rule.filename_off), rule->rule.filename_line); r = sysctl_write(filename, value); if (r < 0) - log_error("error writing SYSCTL{%s}='%s': %s", filename, value, strerror(-r)); + log_error_errno(r, "error writing SYSCTL{%s}='%s': %m", filename, value); break; } case TK_A_RUN_BUILTIN: diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 15b76dd6ab..9aa5ab185d 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -83,9 +83,8 @@ unlink: closedir(dir); rmdir("/run/udev/watch.old"); - } else if (errno != ENOENT) { + } else if (errno != ENOENT) log_error_errno(errno, "unable to move watches dir /run/udev/watch; old watches will not be restored: %m"); - } } void udev_watch_begin(struct udev *udev, struct udev_device *dev) { @@ -100,7 +99,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) { wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE); if (wd < 0) { log_error_errno(errno, "inotify_add_watch(%d, %s, %o) failed: %m", - inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE); + inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE); return; } diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 79f45610db..3d6ca7a985 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -65,10 +65,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) { r = safe_atou(optarg, &timeout); if (r < 0) { - fprintf(stderr, "Invalid timeout value '%s': %s\n", - optarg, strerror(-r)); - exit(EXIT_FAILURE); - }; + log_error_errno(r, "Invalid timeout value '%s': %m", optarg); + return EXIT_FAILURE; + } break; } diff --git a/src/udev/udevd.c b/src/udev/udevd.c index f354ced2e2..e4d2f47745 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -18,44 +18,45 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <stddef.h> -#include <signal.h> -#include <unistd.h> #include <errno.h> +#include <fcntl.h> +#include <getopt.h> +#include <signal.h> +#include <stdbool.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> #include <string.h> -#include <fcntl.h> -#include <getopt.h> +#include <sys/epoll.h> #include <sys/file.h> -#include <sys/time.h> +#include <sys/inotify.h> +#include <sys/ioctl.h> +#include <sys/mount.h> #include <sys/prctl.h> -#include <sys/socket.h> #include <sys/signalfd.h> -#include <sys/epoll.h> -#include <sys/mount.h> -#include <sys/wait.h> +#include <sys/socket.h> #include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/inotify.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <unistd.h> #include "sd-daemon.h" #include "sd-event.h" -#include "terminal-util.h" -#include "signal-util.h" -#include "event-util.h" -#include "netlink-util.h" #include "cgroup-util.h" -#include "process-util.h" +#include "cpu-set-util.h" #include "dev-setup.h" +#include "event-util.h" #include "fileio.h" -#include "selinux-util.h" -#include "udev.h" -#include "udev-util.h" #include "formats-util.h" #include "hashmap.h" +#include "netlink-util.h" +#include "process-util.h" +#include "selinux-util.h" +#include "signal-util.h" +#include "terminal-util.h" +#include "udev-util.h" +#include "udev.h" static bool arg_debug = false; static int arg_daemonize = false; @@ -1670,9 +1671,8 @@ int main(int argc, char *argv[]) { arg_children_max = 8; - if (sched_getaffinity(0, sizeof (cpu_set), &cpu_set) == 0) { + if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) == 0) arg_children_max += CPU_COUNT(&cpu_set) * 2; - } log_debug("set children_max to %u", arg_children_max); } |