diff options
Diffstat (limited to 'src/udev')
46 files changed, 483 insertions, 753 deletions
diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index 7e3654c30f..e077a699a4 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -2,22 +2,8 @@ /* * ata_id - reads product/serial number from ATA drives * - * Copyright (C) 2005-2008 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2009 Lennart Poettering <lennart@poettering.net> - * Copyright (C) 2009-2010 David Zeuthen <zeuthen@gmail.com> + * Copyright © 2009-2010 David Zeuthen <zeuthen@gmail.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> @@ -318,7 +304,7 @@ static void disk_identify_fixup_uint16 (uint8_t identify[512], unsigned int offs * device represented by @fd. If successful, then the result will be * copied into @out_identify and @out_is_packet_device. * - * This routine is based on code from libatasmart, Copyright 2008 + * This routine is based on code from libatasmart, Copyright © 2008 * Lennart Poettering, LGPL v2.1. * * Returns: 0 if the data was successfully obtained, otherwise @@ -405,9 +391,8 @@ out: return ret; } -int main(int argc, char *argv[]) -{ - _cleanup_udev_unref_ struct udev *udev = NULL; +int main(int argc, char *argv[]) { + _cleanup_(udev_unrefp) struct udev *udev = NULL; struct hd_driveid id; union { uint8_t byte[512]; diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 5e7bebeb16..1aaa263f76 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -2,20 +2,7 @@ /* * cdrom_id - optical drive and media information prober * - * Copyright (C) 2008-2010 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 2821640e93..a88dedd002 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -11,7 +11,7 @@ * number of missing IDs otherwise. * A negative number is returned on error. * - * Copyright(C) 2007, Hannes Reinecke <hare@suse.de> + * Copyright © 2007, Hannes Reinecke <hare@suse.de> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -58,7 +58,7 @@ static inline struct _mate *node_to_mate(struct udev_list_node *node) return container_of(node, struct _mate, node); } -noreturn static void sig_alrm(int signo) +_noreturn_ static void sig_alrm(int signo) { exit(4); } diff --git a/src/udev/meson.build b/src/udev/meson.build index de2fd2d9c4..3bcd2bd3d7 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -1,19 +1,4 @@ # SPDX-License-Identifier: LGPL-2.1+ -# -# Copyright 2017 Zbigniew Jędrzejewski-Szmek -# -# 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 -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. -# -# systemd is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with systemd; If not, see <http://www.gnu.org/licenses/>. udevadm_sources = files(''' udevadm.c @@ -63,7 +48,7 @@ endif if conf.get('HAVE_ACL') == 1 libudev_core_sources += ['udev-builtin-uaccess.c', - logind_acl_c, + logind_acl_c, sd_login_c] endif @@ -124,12 +109,29 @@ libudev_basic = static_library( c_args : ['-fvisibility=default']) libudev_static = static_library( - 'udev', + 'udev_static', 'udev.h', include_directories : includes, link_with : udev_link_with, link_whole : libudev_basic) +static_libudev = get_option('static-libudev') +static_libudev_pic = static_libudev == 'true' or static_libudev == 'pic' +install_libudev_static = static_library( + 'udev', + basic_sources, + shared_sources, + libsystemd_sources, + libudev_sources, + include_directories : includes, + build_by_default : static_libudev != 'false', + install : static_libudev != 'false', + install_dir : rootlibdir, + link_depends : libudev_sym, + dependencies : libshared_deps + [libmount], + c_args : static_libudev_pic ? [] : ['-fno-PIC'], + pic : static_libudev_pic) + libudev = shared_library( 'udev', 'udev.h', # pick a header file at random to work around old meson bug diff --git a/src/udev/mtd_probe/mtd_probe.c b/src/udev/mtd_probe/mtd_probe.c index 1d692f1187..f47b13378c 100644 --- a/src/udev/mtd_probe/mtd_probe.c +++ b/src/udev/mtd_probe/mtd_probe.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2010 - Maxim Levitsky + * Copyright © 2010 - Maxim Levitsky * * mtd_probe is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ * Boston, MA 02110-1301 USA */ +#include <errno.h> #include <fcntl.h> #include <mtd/mtd-user.h> #include <stdio.h> @@ -27,31 +28,32 @@ #include <sys/types.h> #include <unistd.h> +#include "alloc-util.h" +#include "fd-util.h" #include "mtd_probe.h" -int main(int argc, char** argv) -{ - int mtd_fd; - int error; +int main(int argc, char** argv) { + _cleanup_close_ int mtd_fd = -1; mtd_info_t mtd_info; if (argc != 2) { printf("usage: mtd_probe /dev/mtd[n]\n"); - return 1; + return EXIT_FAILURE; } mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC); - if (mtd_fd == -1) { - perror("open"); - exit(-1); + if (mtd_fd < 0) { + log_error_errno(errno, "Failed to open: %m"); + return EXIT_FAILURE; } - error = ioctl(mtd_fd, MEMGETINFO, &mtd_info); - if (error == -1) { - perror("ioctl"); - exit(-1); + if (ioctl(mtd_fd, MEMGETINFO, &mtd_info) < 0) { + log_error_errno(errno, "Failed to issue MEMGETINFO ioctl: %m"); + return EXIT_FAILURE; } - probe_smart_media(mtd_fd, &mtd_info); - return -1; + if (probe_smart_media(mtd_fd, &mtd_info) < 0) + return EXIT_FAILURE; + + return EXIT_SUCCESS; } diff --git a/src/udev/mtd_probe/mtd_probe.h b/src/udev/mtd_probe/mtd_probe.h index 39841f9b7d..1d8c93b7fd 100644 --- a/src/udev/mtd_probe/mtd_probe.h +++ b/src/udev/mtd_probe/mtd_probe.h @@ -2,7 +2,7 @@ #pragma once /* - * Copyright (C) 2010 - Maxim Levitsky + * Copyright © 2010 - Maxim Levitsky * * mtd_probe is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,4 +49,4 @@ struct sm_oob { #define SM_SMALL_PAGE 256 #define SM_SMALL_OOB_SIZE 8 -void probe_smart_media(int mtd_fd, mtd_info_t *info); +int probe_smart_media(int mtd_fd, mtd_info_t *info); diff --git a/src/udev/mtd_probe/probe_smartmedia.c b/src/udev/mtd_probe/probe_smartmedia.c index 5d58de6a87..099809da1b 100644 --- a/src/udev/mtd_probe/probe_smartmedia.c +++ b/src/udev/mtd_probe/probe_smartmedia.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2010 - Maxim Levitsky + * Copyright © 2010 - Maxim Levitsky * * mtd_probe is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ * Boston, MA 02110-1301 USA */ +#include <errno.h> #include <fcntl.h> #include <mtd/mtd-user.h> #include <stdint.h> @@ -35,8 +36,7 @@ static const uint8_t cis_signature[] = { 0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, 0xDF, 0x01, 0x20 }; - -void probe_smart_media(int mtd_fd, mtd_info_t* info) { +int probe_smart_media(int mtd_fd, mtd_info_t* info) { int sector_size; int block_size; int size_in_megs; @@ -47,17 +47,21 @@ void probe_smart_media(int mtd_fd, mtd_info_t* info) { cis_buffer = malloc(SM_SECTOR_SIZE); if (!cis_buffer) - return; + return log_oom(); - if (info->type != MTD_NANDFLASH) - goto exit; + if (info->type != MTD_NANDFLASH) { + log_debug("Not marked MTD_NANDFLASH."); + return -EINVAL; + } sector_size = info->writesize; block_size = info->erasesize; size_in_megs = info->size / (1024 * 1024); - if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE)) - goto exit; + if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE)) { + log_debug("Unexpected sector size: %i", sector_size); + return -EINVAL; + } switch(size_in_megs) { case 1: @@ -72,26 +76,26 @@ void probe_smart_media(int mtd_fd, mtd_info_t* info) { break; } - for (offset = 0 ; offset < block_size * spare_count ; - offset += sector_size) { - lseek(mtd_fd, SEEK_SET, offset); + for (offset = 0; offset < block_size * spare_count; offset += sector_size) { + (void) lseek(mtd_fd, SEEK_SET, offset); + if (read(mtd_fd, cis_buffer, SM_SECTOR_SIZE) == SM_SECTOR_SIZE) { cis_found = 1; break; } } - if (!cis_found) - goto exit; + if (!cis_found) { + log_debug("CIS not found"); + return -EINVAL; + } if (memcmp(cis_buffer, cis_signature, sizeof(cis_signature)) != 0 && - (memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, - sizeof(cis_signature)) != 0)) - goto exit; + memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, sizeof(cis_signature)) != 0) { + log_debug("CIS signature didn't match"); + return -EINVAL; + } printf("MTD_FTL=smartmedia\n"); - exit(EXIT_SUCCESS); - -exit: - return; + return 0; } diff --git a/src/udev/net/ethtool-util.c b/src/udev/net/ethtool-util.c index 9bdaef8d90..4bb4216ac8 100644 --- a/src/udev/net/ethtool-util.c +++ b/src/udev/net/ethtool-util.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright (C) 2013 Tom Gundersen <teg@jklm.no> - - 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <net/if.h> #include <sys/ioctl.h> @@ -72,7 +54,6 @@ static const char* const netdev_feature_table[_NET_DEV_FEAT_MAX] = { [NET_DEV_FEAT_LRO] = "rx-lro", [NET_DEV_FEAT_TSO] = "tx-tcp-segmentation", [NET_DEV_FEAT_TSO6] = "tx-tcp6-segmentation", - [NET_DEV_FEAT_UFO] = "tx-udp-fragmentation", }; int ethtool_connect(int *ret) { @@ -305,8 +286,7 @@ static int get_stringset(int fd, struct ifreq *ifr, int stringset_id, struct eth if (r < 0) return -errno; - *gstrings = strings; - strings = NULL; + *gstrings = TAKE_PTR(strings); return 0; } @@ -418,7 +398,7 @@ static int get_glinksettings(int fd, struct ifreq *ifr, struct ethtool_link_uset if (!u) return -ENOMEM; - ecmd.req = u->base; + u->base = ecmd.req; offset = 0; memcpy(u->link_modes.supported, &ecmd.link_mode_data[offset], 4 * ecmd.req.link_mode_masks_nwords); @@ -583,3 +563,105 @@ int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *l return r; } + +int config_parse_channel(const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + link_config *config = data; + uint32_t k; + int r; + + assert(filename); + assert(section); + assert(lvalue); + assert(rvalue); + assert(data); + + r = safe_atou32(rvalue, &k); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse channel value, ignoring: %s", rvalue); + return 0; + } + + if (k < 1) { + log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Invalid %s value, ignoring: %s", lvalue, rvalue); + return 0; + } + + if (streq(lvalue, "RxChannels")) { + config->channels.rx_count = k; + config->channels.rx_count_set = true; + } else if (streq(lvalue, "TxChannels")) { + config->channels.tx_count = k; + config->channels.tx_count_set = true; + } else if (streq(lvalue, "OtherChannels")) { + config->channels.other_count = k; + config->channels.other_count_set = true; + } else if (streq(lvalue, "CombinedChannels")) { + config->channels.combined_count = k; + config->channels.combined_count_set = true; + } + + return 0; +} + +int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels) { + struct ethtool_channels ecmd = { + .cmd = ETHTOOL_GCHANNELS + }; + struct ifreq ifr = { + .ifr_data = (void*) &ecmd + }; + + bool need_update = false; + int r; + + if (*fd < 0) { + r = ethtool_connect(fd); + if (r < 0) + return log_warning_errno(r, "link_config: could not connect to ethtool: %m"); + } + + strscpy(ifr.ifr_name, IFNAMSIZ, ifname); + + r = ioctl(*fd, SIOCETHTOOL, &ifr); + if (r < 0) + return -errno; + + if (channels->rx_count_set && ecmd.rx_count != channels->rx_count) { + ecmd.rx_count = channels->rx_count; + need_update = true; + } + + if (channels->tx_count_set && ecmd.tx_count != channels->tx_count) { + ecmd.tx_count = channels->tx_count; + need_update = true; + } + + if (channels->other_count_set && ecmd.other_count != channels->other_count) { + ecmd.other_count = channels->other_count; + need_update = true; + } + + if (channels->combined_count_set && ecmd.combined_count != channels->combined_count) { + ecmd.combined_count = channels->combined_count; + need_update = true; + } + + if (need_update) { + ecmd.cmd = ETHTOOL_SCHANNELS; + + r = ioctl(*fd, SIOCETHTOOL, &ifr); + if (r < 0) + return -errno; + } + + return 0; +} diff --git a/src/udev/net/ethtool-util.h b/src/udev/net/ethtool-util.h index 5681472a9a..064bf4d2bd 100644 --- a/src/udev/net/ethtool-util.h +++ b/src/udev/net/ethtool-util.h @@ -1,24 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -/*** - This file is part of systemd. - - Copyright (C) 2013 Tom Gundersen <teg@jklm.no> - - 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <macro.h> #include <linux/ethtool.h> @@ -55,7 +37,6 @@ typedef enum NetDevFeature { NET_DEV_FEAT_LRO, NET_DEV_FEAT_TSO, NET_DEV_FEAT_TSO6, - NET_DEV_FEAT_UFO, _NET_DEV_FEAT_MAX, _NET_DEV_FEAT_INVALID = -1 } NetDevFeature; @@ -86,6 +67,18 @@ struct ethtool_link_usettings { } link_modes; }; +typedef struct netdev_channels { + uint32_t rx_count; + uint32_t tx_count; + uint32_t other_count; + uint32_t combined_count; + + bool rx_count_set; + bool tx_count_set; + bool other_count_set; + bool combined_count_set; +} netdev_channels; + int ethtool_connect(int *ret); int ethtool_get_driver(int *fd, const char *ifname, char **ret); @@ -93,6 +86,7 @@ int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex du int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol); int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features); int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *link); +int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels); const char *duplex_to_string(Duplex d) _const_; Duplex duplex_from_string(const char *d) _pure_; @@ -106,3 +100,4 @@ NetDevPort port_from_string(const char *port) _pure_; int config_parse_duplex(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_wol(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_port(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_channel(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); diff --git a/src/udev/net/link-config-gperf.gperf b/src/udev/net/link-config-gperf.gperf index 5cb126d870..5640fa0513 100644 --- a/src/udev/net/link-config-gperf.gperf +++ b/src/udev/net/link-config-gperf.gperf @@ -4,9 +4,9 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") #endif #include <stddef.h> #include "conf-parser.h" -#include "network-internal.h" -#include "link-config.h" #include "ethtool-util.h" +#include "link-config.h" +#include "network-internal.h" %} struct ConfigPerfItem; %null_strings @@ -19,7 +19,7 @@ struct ConfigPerfItem; %struct-type %includes %% -Match.MACAddress, config_parse_hwaddr, 0, offsetof(link_config, match_mac) +Match.MACAddress, config_parse_hwaddrs, 0, offsetof(link_config, match_mac) Match.OriginalName, config_parse_ifnames, 0, offsetof(link_config, match_name) Match.Path, config_parse_strv, 0, offsetof(link_config, match_path) Match.Driver, config_parse_strv, 0, offsetof(link_config, match_driver) @@ -35,7 +35,7 @@ Link.MACAddress, config_parse_hwaddr, 0, Link.NamePolicy, config_parse_name_policy, 0, offsetof(link_config, name_policy) Link.Name, config_parse_ifname, 0, offsetof(link_config, name) Link.Alias, config_parse_ifalias, 0, offsetof(link_config, alias) -Link.MTUBytes, config_parse_iec_size, 0, offsetof(link_config, mtu) +Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(link_config, mtu) Link.BitsPerSecond, config_parse_si_size, 0, offsetof(link_config, speed) Link.Duplex, config_parse_duplex, 0, offsetof(link_config, duplex) Link.AutoNegotiation, config_parse_tristate, 0, offsetof(link_config, autonegotiation) @@ -44,6 +44,10 @@ Link.Port, config_parse_port, 0, Link.GenericSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GSO]) Link.TCPSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO]) Link.TCP6SegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO6]) -Link.UDPSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_UFO]) +Link.UDPSegmentationOffload, config_parse_warn_compat, DISABLED_LEGACY, 0 Link.GenericReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GRO]) Link.LargeReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_LRO]) +Link.RxChannels, config_parse_channel, 0, 0 +Link.TxChannels, config_parse_channel, 0, 0 +Link.OtherChannels, config_parse_channel, 0, 0 +Link.CombinedChannels, config_parse_channel, 0, 0 diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index a4368f088d..cec4f4f779 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright (C) 2013 Tom Gundersen <teg@jklm.no> - - 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <netinet/ether.h> @@ -70,7 +52,7 @@ static void link_config_free(link_config *link) { free(link->filename); - free(link->match_mac); + set_free_free(link->match_mac); strv_free(link->match_path); strv_free(link->match_driver); strv_free(link->match_type); @@ -135,8 +117,7 @@ int link_config_ctx_new(link_config_ctx **ret) { ctx->enable_name_policy = true; - *ret = ctx; - ctx = NULL; + *ret = TAKE_PTR(ctx); return 0; } @@ -183,7 +164,7 @@ static int load_link(link_config_ctx *ctx, const char *filename) { else log_debug("Parsed configuration file %s", filename); - if (link->mtu > UINT_MAX || link->speed > UINT_MAX) + if (link->speed > UINT_MAX) return -ERANGE; link->filename = strdup(filename); @@ -407,6 +388,12 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, if (r < 0) log_warning_errno(r, "Could not set offload features of %s: %m", old_name); + if (config->channels.rx_count_set || config->channels.tx_count_set || config->channels.other_count_set || config->channels.combined_count_set) { + r = ethtool_set_channels(&ctx->ethtool_fd, old_name, &config->channels); + if (r < 0) + log_warning_errno(r, "Could not set channels of %s: %m", old_name); + } + ifindex = udev_device_get_ifindex(device); if (ifindex <= 0) { log_warning("Could not find ifindex"); @@ -480,7 +467,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac, config->mtu); if (r < 0) - return log_warning_errno(r, "Could not set Alias, MACAddress or MTU on %s: %m", old_name); + return log_warning_errno(r, "Could not set Alias=, MACAddress= or MTU= on %s: %m", old_name); *name = new_name; diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h index dabc3eff8f..4798bb101c 100644 --- a/src/udev/net/link-config.h +++ b/src/udev/net/link-config.h @@ -1,30 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -/*** - This file is part of systemd. - - Copyright (C) 2013 Tom Gundersen <teg@jklm.no> - - 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include "libudev.h" #include "condition.h" #include "ethtool-util.h" #include "list.h" +#include "set.h" typedef struct link_config_ctx link_config_ctx; typedef struct link_config link_config; @@ -51,7 +34,7 @@ typedef enum NamePolicy { struct link_config { char *filename; - struct ether_addr *match_mac; + Set *match_mac; char **match_path; char **match_driver; char **match_type; @@ -68,13 +51,14 @@ struct link_config { NamePolicy *name_policy; char *name; char *alias; - size_t mtu; + uint32_t mtu; size_t speed; Duplex duplex; int autonegotiation; WakeOnLan wol; NetDevPort port; NetDevFeature features[_NET_DEV_FEAT_MAX]; + netdev_channels channels; LIST_FIELDS(link_config, links); }; diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index 32c1a8def4..5caab7774f 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -1,20 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) IBM Corp. 2003 - * Copyright (C) SUSE Linux Products GmbH, 2006 + * Copyright © IBM Corp. 2003 + * Copyright © SUSE Linux Products GmbH, 2006 * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> @@ -164,7 +152,7 @@ static int get_file_options(struct udev *udev, const char *vendor, const char *model, int *argc, char ***newargv) { - char *buffer; + _cleanup_free_ char *buffer = NULL; _cleanup_fclose_ FILE *f; char *buf; char *str1; @@ -259,9 +247,8 @@ static int get_file_options(struct udev *udev, if (vendor_in == NULL) break; } else if (vendor_in && - strneq(vendor, vendor_in, strlen(vendor_in)) && - (!model_in || - (strneq(model, model_in, strlen(model_in))))) { + startswith(vendor, vendor_in) && + (!model_in || startswith(model, model_in))) { /* * Matched vendor and optionally model. * @@ -296,14 +283,13 @@ static int get_file_options(struct udev *udev, (*newargv)[c] = buffer; for (c = 1; c < *argc; c++) (*newargv)[c] = strsep(&buffer, " \t"); + buffer = NULL; } } else { /* No matches */ retval = 1; } } - if (retval != 0) - free(buffer); return retval; } @@ -570,9 +556,8 @@ out: return retval; } -int main(int argc, char **argv) -{ - _cleanup_udev_unref_ struct udev *udev; +int main(int argc, char **argv) { + _cleanup_(udev_unrefp) struct udev *udev; int retval = 0; char maj_min_dev[MAX_PATH_LEN]; int newargc; diff --git a/src/udev/scsi_id/scsi_id.h b/src/udev/scsi_id/scsi_id.h index 9a33f6a158..1222f250ec 100644 --- a/src/udev/scsi_id/scsi_id.h +++ b/src/udev/scsi_id/scsi_id.h @@ -2,20 +2,8 @@ #pragma once /* - * Copyright (C) IBM Corp. 2003 + * Copyright © IBM Corp. 2003 * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define MAX_PATH_LEN 512 diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index bf6b28e8e5..fd91657a32 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -1,21 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) IBM Corp. 2003 + * Copyright © IBM Corp. 2003 * * Author: Patrick Mansfield<patmans@us.ibm.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -590,7 +578,7 @@ static int check_fill_0x83_prespc3(struct udev *udev, { int i, j; - serial[0] = hex_str[id_search->id_type]; + serial[0] = hex_str[SCSI_ID_NAA]; /* serial has been memset to zero before */ j = strlen(serial); /* j = 1; */ @@ -603,7 +591,6 @@ static int check_fill_0x83_prespc3(struct udev *udev, return 0; } - /* Get device identification VPD page */ static int do_scsi_page83_inquiry(struct udev *udev, struct scsi_id_device *dev_scsi, int fd, @@ -739,7 +726,7 @@ static int do_scsi_page83_prespc3_inquiry(struct udev *udev, if (page_83[6] == 0) return 2; - serial[0] = hex_str[id_search_list[0].id_type]; + serial[0] = hex_str[SCSI_ID_NAA]; /* * The first four bytes contain data, not a descriptor. */ diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index eeed803f57..477b7ef61f 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -2,21 +2,8 @@ /* * probe disks for filesystems and partitions * - * Copyright (C) 2011 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2011 Karel Zak <kzak@redhat.com> + * Copyright © 2011 Karel Zak <kzak@redhat.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <blkid.h> @@ -228,7 +215,7 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t int64_t offset = 0; bool noraid = false; _cleanup_close_ int fd = -1; - _cleanup_blkid_free_probe_ blkid_probe pr = NULL; + _cleanup_(blkid_free_probep) blkid_probe pr = NULL; const char *data; const char *name; int nvals; diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index 9e0f1e0aac..2e8535598d 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2012 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <fcntl.h> #include <stdlib.h> diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c index dbfe024298..396384f6c8 100644 --- a/src/udev/udev-builtin-hwdb.c +++ b/src/udev/udev-builtin-hwdb.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2012 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <fnmatch.h> #include <getopt.h> @@ -73,9 +55,9 @@ static const char *modalias_usb(struct udev_device *dev, char *s, size_t size) { if (!p) return NULL; if (safe_atoux16(v, &vn) < 0) - return NULL; + return NULL; if (safe_atoux16(p, &pn) < 0) - return NULL; + return NULL; snprintf(s, size, "usb:v%04Xp%04X*", vn, pn); return s; } @@ -139,7 +121,7 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te const char *device = NULL; const char *subsystem = NULL; const char *prefix = NULL; - _cleanup_udev_device_unref_ struct udev_device *srcdev = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *srcdev = NULL; if (!hwdb) return EXIT_FAILURE; diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 02b86cce23..680170028b 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -2,24 +2,10 @@ /* * expose input properties via udev * - * Copyright (C) 2009 Martin Pitt <martin.pitt@ubuntu.com> - * Portions Copyright (C) 2004 David Zeuthen, <david@fubar.dk> - * Copyright (C) 2011 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2014 Carlos Garnacho <carlosg@gnome.org> - * Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com> + * Copyright © 2009 Martin Pitt <martin.pitt@ubuntu.com> + * Portions Copyright © 2004 David Zeuthen, <david@fubar.dk> + * Copyright © 2014 Carlos Garnacho <carlosg@gnome.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -195,15 +181,23 @@ static bool test_pointers(struct udev_device *dev, has_mt_coordinates = false; is_direct = test_bit(INPUT_PROP_DIRECT, bitmask_props); has_touch = test_bit(BTN_TOUCH, bitmask_key); + /* joysticks don't necessarily have buttons; e. g. * rudders/pedals are joystick-like, but buttonless; they have - * other fancy axes. Others have buttons only but no axes. */ - for (button = BTN_JOYSTICK; button < BTN_DIGI && !has_joystick_axes_or_buttons; button++) - has_joystick_axes_or_buttons = test_bit(button, bitmask_key); - for (button = BTN_TRIGGER_HAPPY1; button <= BTN_TRIGGER_HAPPY40 && !has_joystick_axes_or_buttons; button++) - has_joystick_axes_or_buttons = test_bit(button, bitmask_key); - for (button = BTN_DPAD_UP; button <= BTN_DPAD_RIGHT && !has_joystick_axes_or_buttons; button++) - has_joystick_axes_or_buttons = test_bit(button, bitmask_key); + * other fancy axes. Others have buttons only but no axes. + * + * The BTN_JOYSTICK range starts after the mouse range, so a mouse + * with more than 16 buttons runs into the joystick range (e.g. Mad + * Catz Mad Catz M.M.O.TE). Skip those. + */ + if (!test_bit(BTN_JOYSTICK - 1, bitmask_key)) { + for (button = BTN_JOYSTICK; button < BTN_DIGI && !has_joystick_axes_or_buttons; button++) + has_joystick_axes_or_buttons = test_bit(button, bitmask_key); + for (button = BTN_TRIGGER_HAPPY1; button <= BTN_TRIGGER_HAPPY40 && !has_joystick_axes_or_buttons; button++) + has_joystick_axes_or_buttons = test_bit(button, bitmask_key); + for (button = BTN_DPAD_UP; button <= BTN_DPAD_RIGHT && !has_joystick_axes_or_buttons; button++) + has_joystick_axes_or_buttons = test_bit(button, bitmask_key); + } for (axis = ABS_RX; axis < ABS_PRESSURE && !has_joystick_axes_or_buttons; axis++) has_joystick_axes_or_buttons = test_bit(axis, bitmask_abs); @@ -299,7 +293,7 @@ static bool test_key(struct udev_device *dev, /* the first 32 bits are ESC, numbers, and Q to D; if we have all of * those, consider it a full keyboard; do not test KEY_RESERVED, though */ mask = 0xFFFFFFFE; - if ((bitmask_key[0] & mask) == mask) { + if (FLAGS_SET(bitmask_key[0], mask)) { udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD", "1"); ret = true; } diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index 0044280399..9160a5b5d5 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2013 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <stdio.h> #include <stdlib.h> diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index 2530fdfd23..e24e8e55e2 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -2,21 +2,8 @@ /* * load kernel modules * - * Copyright (C) 2011-2012 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2011 ProFUSION embedded systems + * Copyright © 2011 ProFUSION embedded systems * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 36994360c7..147e04ab8c 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2012 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ /* * Predictable network interface device names based on: @@ -112,6 +94,8 @@ #include "dirent-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" +#include "parse-util.h" #include "stdio-util.h" #include "string-util.h" #include "udev.h" @@ -149,6 +133,11 @@ struct netnames { char platform_path[IFNAMSIZ]; }; +struct virtfn_info { + struct udev_device *physfn_pcidev; + char suffix[IFNAMSIZ]; +}; + /* skip intermediate virtio devices */ static struct udev_device *skip_virtio(struct udev_device *dev) { struct udev_device *parent = dev; @@ -161,6 +150,67 @@ static struct udev_device *skip_virtio(struct udev_device *dev) { return parent; } +static int get_virtfn_info(struct udev_device *dev, struct netnames *names, struct virtfn_info *vf_info) { + struct udev *udev; + const char *physfn_link_file; + _cleanup_free_ char *physfn_pci_syspath = NULL; + _cleanup_free_ char *virtfn_pci_syspath = NULL; + struct dirent *dent; + _cleanup_closedir_ DIR *dir = NULL; + struct virtfn_info vf_info_local = {}; + int r; + + udev = udev_device_get_udev(names->pcidev); + if (!udev) + return -ENOENT; + /* Check if this is a virtual function. */ + physfn_link_file = strjoina(udev_device_get_syspath(names->pcidev), "/physfn"); + r = chase_symlinks(physfn_link_file, NULL, 0, &physfn_pci_syspath); + if (r < 0) + return r; + + /* Get physical function's pci device. */ + vf_info_local.physfn_pcidev = udev_device_new_from_syspath(udev, physfn_pci_syspath); + if (!vf_info_local.physfn_pcidev) + return -ENOENT; + + /* Find the virtual function number by finding the right virtfn link. */ + dir = opendir(physfn_pci_syspath); + if (!dir) { + r = -errno; + goto out_unref; + } + FOREACH_DIRENT_ALL(dent, dir, break) { + _cleanup_free_ char *virtfn_link_file = NULL; + if (!startswith(dent->d_name, "virtfn")) + continue; + virtfn_link_file = strjoin(physfn_pci_syspath, "/", dent->d_name); + if (!virtfn_link_file) { + r = -ENOMEM; + goto out_unref; + } + if (chase_symlinks(virtfn_link_file, NULL, 0, &virtfn_pci_syspath) < 0) + continue; + if (streq(udev_device_get_syspath(names->pcidev), virtfn_pci_syspath)) { + if (!snprintf_ok(vf_info_local.suffix, sizeof(vf_info_local.suffix), "v%s", &dent->d_name[6])) { + r = -ENOENT; + goto out_unref; + } + break; + } + } + if (isempty(vf_info_local.suffix)) { + r = -ENOENT; + goto out_unref; + } + *vf_info = vf_info_local; + return 0; + +out_unref: + udev_device_unref(vf_info_local.physfn_pcidev); + return r; +} + /* retrieve on-board index number and label from firmware */ static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) { unsigned dev_port = 0; @@ -231,20 +281,29 @@ static bool is_pci_multifunction(struct udev_device *dev) { return false; } +static bool is_pci_ari_enabled(struct udev_device *dev) { + return streq_ptr(udev_device_get_sysattr_value(dev, "ari_enabled"), "1"); +} + static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { struct udev *udev = udev_device_get_udev(names->pcidev); - unsigned domain, bus, slot, func, dev_port = 0; + unsigned domain, bus, slot, func, dev_port = 0, hotplug_slot = 0; size_t l; char *s; const char *attr, *port_name; - _cleanup_udev_device_unref_ struct udev_device *pci = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *pci = NULL; + struct udev_device *hotplug_slot_dev; char slots[PATH_MAX]; _cleanup_closedir_ DIR *dir = NULL; struct dirent *dent; - int hotplug_slot = 0; if (sscanf(udev_device_get_sysname(names->pcidev), "%x:%x:%x.%u", &domain, &bus, &slot, &func) != 4) return -ENOENT; + if (is_pci_ari_enabled(names->pcidev)) + /* ARI devices support up to 256 functions on a single device ("slot"), and interpret the + * traditional 5-bit slot and 3-bit function number as a single 8-bit function number, + * where the slot makes up the upper 5 bits. */ + func += slot * 8; /* kernel provided port index for multiple ports on a single PCI function */ attr = udev_device_get_sysattr_value(dev, "dev_port"); @@ -281,27 +340,33 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) { if (!dir) return -errno; - FOREACH_DIRENT_ALL(dent, dir, break) { - int i; - char *rest, str[PATH_MAX]; - _cleanup_free_ char *address = NULL; - - if (dent->d_name[0] == '.') - continue; - i = strtol(dent->d_name, &rest, 10); - if (rest[0] != '\0') - continue; - if (i < 1) - continue; - - if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, dent->d_name) && - read_one_line_file(str, &address) >= 0) - /* match slot address with device by stripping the function */ - if (streq(address, udev_device_get_sysname(names->pcidev))) - hotplug_slot = i; - + hotplug_slot_dev = names->pcidev; + while (hotplug_slot_dev) { + FOREACH_DIRENT_ALL(dent, dir, break) { + unsigned i; + int r; + char str[PATH_MAX]; + _cleanup_free_ char *address = NULL; + + if (dent->d_name[0] == '.') + continue; + r = safe_atou_full(dent->d_name, 10, &i); + if (i < 1 || r < 0) + continue; + + if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, dent->d_name) && + read_one_line_file(str, &address) >= 0) + /* match slot address with device by stripping the function */ + if (startswith(udev_device_get_sysname(hotplug_slot_dev), address)) + hotplug_slot = i; + + if (hotplug_slot > 0) + break; + } if (hotplug_slot > 0) break; + rewinddir(dir); + hotplug_slot_dev = udev_device_get_parent_with_subsystem_devtype(hotplug_slot_dev, "pci", NULL); } if (hotplug_slot > 0) { @@ -406,6 +471,8 @@ static int names_platform(struct udev_device *dev, struct netnames *names, bool static int names_pci(struct udev_device *dev, struct netnames *names) { struct udev_device *parent; + struct netnames vf_names = {}; + struct virtfn_info vf_info = {}; assert(dev); assert(names); @@ -426,8 +493,29 @@ static int names_pci(struct udev_device *dev, struct netnames *names) { if (!names->pcidev) return -ENOENT; } - dev_pci_onboard(dev, names); - dev_pci_slot(dev, names); + + if (get_virtfn_info(dev, names, &vf_info) >= 0) { + /* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */ + vf_names.pcidev = vf_info.physfn_pcidev; + dev_pci_onboard(dev, &vf_names); + dev_pci_slot(dev, &vf_names); + if (vf_names.pci_onboard[0]) + if (strlen(vf_names.pci_onboard) + strlen(vf_info.suffix) < sizeof(names->pci_onboard)) + strscpyl(names->pci_onboard, sizeof(names->pci_onboard), + vf_names.pci_onboard, vf_info.suffix, NULL); + if (vf_names.pci_slot[0]) + if (strlen(vf_names.pci_slot) + strlen(vf_info.suffix) < sizeof(names->pci_slot)) + strscpyl(names->pci_slot, sizeof(names->pci_slot), + vf_names.pci_slot, vf_info.suffix, NULL); + if (vf_names.pci_path[0]) + if (strlen(vf_names.pci_path) + strlen(vf_info.suffix) < sizeof(names->pci_path)) + strscpyl(names->pci_path, sizeof(names->pci_path), + vf_names.pci_path, vf_info.suffix, NULL); + udev_device_unref(vf_info.physfn_pcidev); + } else { + dev_pci_onboard(dev, names); + dev_pci_slot(dev, names); + } return 0; } diff --git a/src/udev/udev-builtin-net_setup_link.c b/src/udev/udev-builtin-net_setup_link.c index 40158e0afc..8bed6399af 100644 --- a/src/udev/udev-builtin-net_setup_link.c +++ b/src/udev/udev-builtin-net_setup_link.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2013 Tom Gundersen - - 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include "alloc-util.h" #include "link-config.h" diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 9ce2079a67..36f1949c7b 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -2,22 +2,9 @@ /* * compose persistent device path * - * Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org> * * Logic based on Hannes Reinecke's shell script. * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> @@ -62,10 +49,8 @@ static void path_prepend(char **path, const char *fmt, ...) { } free_and_replace(*path, new); - } else { - *path = pre; - pre = NULL; - } + } else + *path = TAKE_PTR(pre); } /* @@ -106,7 +91,7 @@ static struct udev_device *skip_subsystem(struct udev_device *dev, const char *s static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent, char **path) { struct udev *udev; struct udev_device *targetdev; - _cleanup_udev_device_unref_ struct udev_device *fcdev = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *fcdev = NULL; const char *port; _cleanup_free_ char *lun = NULL; @@ -135,7 +120,7 @@ static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent, static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent, char **path) { struct udev *udev; struct udev_device *targetdev, *target_parent; - _cleanup_udev_device_unref_ struct udev_device *sasdev = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *sasdev = NULL; const char *sas_address; _cleanup_free_ char *lun = NULL; @@ -170,7 +155,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa { struct udev *udev; struct udev_device *targetdev, *target_parent, *port, *expander; - _cleanup_udev_device_unref_ struct udev_device + _cleanup_(udev_device_unrefp) struct udev_device *target_sasdev = NULL, *expander_sasdev = NULL, *port_sasdev = NULL; const char *sas_address = NULL; const char *phy_id; @@ -246,7 +231,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path) { struct udev *udev; struct udev_device *transportdev; - _cleanup_udev_device_unref_ struct udev_device + _cleanup_(udev_device_unrefp) struct udev_device *sessiondev = NULL, *conndev = NULL; const char *target, *connname, *addr, *port; _cleanup_free_ char *lun = NULL; @@ -293,7 +278,7 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char ** static struct udev_device *handle_scsi_ata(struct udev_device *parent, char **path) { struct udev *udev; struct udev_device *targetdev, *target_parent; - _cleanup_udev_device_unref_ struct udev_device *atadev = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *atadev = NULL; const char *port_no; assert(parent); @@ -397,16 +382,17 @@ static struct udev_device *handle_scsi_default(struct udev_device *parent, char return hostdev; } -static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path) { +static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path, size_t guid_str_len) { struct udev_device *hostdev; struct udev_device *vmbusdev; const char *guid_str; _cleanup_free_ char *lun = NULL; - char guid[38]; + char guid[39]; size_t i, k; assert(parent); assert(path); + assert(guid_str_len < sizeof(guid)); hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host"); if (!hostdev) @@ -420,10 +406,10 @@ static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char * if (!guid_str) return NULL; - if (strlen(guid_str) < 37 || guid_str[0] != '{' || guid_str[36] != '}') + if (strlen(guid_str) < guid_str_len || guid_str[0] != '{' || guid_str[guid_str_len-1] != '}') return NULL; - for (i = 1, k = 0; i < 36; i++) { + for (i = 1, k = 0; i < guid_str_len-1; i++) { if (guid_str[i] == '-') continue; guid[k++] = guid_str[i]; @@ -472,7 +458,9 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path, return handle_scsi_ata(parent, path); if (strstr(name, "/vmbus_")) - return handle_scsi_hyperv(parent, path); + return handle_scsi_hyperv(parent, path, 37); + else if (strstr(name, "/VMBUS")) + return handle_scsi_hyperv(parent, path, 38); return handle_scsi_default(parent, path); } diff --git a/src/udev/udev-builtin-uaccess.c b/src/udev/udev-builtin-uaccess.c index edea242e65..b1191ae7ff 100644 --- a/src/udev/udev-builtin-uaccess.c +++ b/src/udev/udev-builtin-uaccess.c @@ -2,21 +2,7 @@ /* * manage device node user ACL * - * Copyright 2010-2012 Kay Sievers <kay@vrfy.org> - * Copyright 2010 Lennart Poettering * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index 6d22dfe82c..dcf21a2f44 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -5,20 +5,7 @@ * Copyright (c) 2005 SUSE Linux Products GmbH, Germany * Author: Hannes Reinecke <hare@suse.de> * - * Copyright (C) 2005-2011 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> @@ -176,7 +163,7 @@ static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len return log_debug_errno(errno, "Error opening USB device 'descriptors' file: %m"); size = read(fd, buf, sizeof(buf)); - if (size < 18 || size == sizeof(buf)) + if (size < 18 || (size_t) size >= sizeof(buf)) return -EIO; ifs_str[0] = '\0'; diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index db2b6874f8..576d83d378 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2007-2012 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <getopt.h> #include <stdio.h> diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 7b8110582d..efe7297f04 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -2,7 +2,6 @@ * * libudev - interface to udev device information * - * Copyright (C) 2008 Kay Sievers <kay@vrfy.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index d0befba29c..fd8406d959 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 6a3ee93ca2..333dcae6b9 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -79,7 +66,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s buf[len] = '\0'; if (streq(target, buf)) { log_debug("preserve already existing symlink '%s' to '%s'", slink, target); - label_fix(slink, true, false); + (void) label_fix(slink, LABEL_IGNORE_ENOENT); utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW); goto exit; } @@ -324,7 +311,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, /* set the defaults */ if (!selinux) - mac_selinux_fix(devnode, true, false); + (void) mac_selinux_fix(devnode, LABEL_IGNORE_ENOENT); if (!smack) mac_smack_apply(devnode, SMACK_ATTR_ACCESS, NULL); } diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 635811c59f..f029395884 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2003-2012 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 61179ce03d..7864f57aa5 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -1,21 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2009 Canonical Ltd. - * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com> + * Copyright © 2009 Canonical Ltd. + * Copyright © 2009 Scott James Remnant <scott@netsplit.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/udev.h b/src/udev/udev.h index ea11c2d29e..4596d0ea01 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -2,21 +2,8 @@ #pragma once /* - * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> - * Copyright (C) 2003-2010 Kay Sievers <kay@vrfy.org> + * Copyright © 2003 Greg Kroah-Hartman <greg@kroah.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/param.h> diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index 9546a6ebaf..a84cc156cb 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2005-2011 Kay Sievers <kay@vrfy.org> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,7 +43,7 @@ static void print_help(void) { } static int adm_control(struct udev *udev, int argc, char *argv[]) { - _cleanup_udev_ctrl_unref_ struct udev_ctrl *uctrl = NULL; + _cleanup_(udev_ctrl_unrefp) struct udev_ctrl *uctrl = NULL; int timeout = 60; int rc = 1, c; @@ -137,18 +136,17 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) { break; } case 't': { + int r, seconds; usec_t s; - int seconds; - int r; r = parse_sec(optarg, &s); if (r < 0) return log_error_errno(r, "Failed to parse timeout value '%s'.", optarg); - if (((s + USEC_PER_SEC - 1) / USEC_PER_SEC) > INT_MAX) + if (DIV_ROUND_UP(s, USEC_PER_SEC) > INT_MAX) log_error("Timeout value is out of range."); else { - seconds = s != USEC_INFINITY ? (int) ((s + USEC_PER_SEC - 1) / USEC_PER_SEC) : INT_MAX; + seconds = s != USEC_INFINITY ? (int) DIV_ROUND_UP(s, USEC_PER_SEC) : INT_MAX; timeout = seconds; rc = 0; } diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index dc3ae7484d..02408a4285 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -1,22 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - This file is part of systemd. - - Copyright 2012 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 - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see <http://www.gnu.org/licenses/>. -***/ #include <ctype.h> #include <getopt.h> @@ -114,7 +96,9 @@ static struct trie_node *node_lookup(const struct trie_node *node, uint8_t c) { struct trie_child_entry search; search.c = c; - child = bsearch(&search, node->children, node->children_count, sizeof(struct trie_child_entry), trie_children_cmp); + child = bsearch_safe(&search, + node->children, node->children_count, sizeof(struct trie_child_entry), + trie_children_cmp); if (child) return child->child; return NULL; @@ -461,6 +445,7 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam FILE *f; char line[LINE_MAX]; struct udev_list match_list; + int r = 0, err; udev_list_init(udev, &match_list, false); @@ -494,6 +479,7 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam if (line[0] == ' ') { log_error("Error, MATCH expected but got '%s' in '%s':", line, filename); + r = -EINVAL; break; } @@ -505,6 +491,7 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam case HW_MATCH: if (len == 0) { log_error("Error, DATA expected but got empty line in '%s':", filename); + r = -EINVAL; state = HW_NONE; udev_list_cleanup(&match_list); break; @@ -518,7 +505,9 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam /* first data */ state = HW_DATA; - insert_data(trie, &match_list, line, filename); + err = insert_data(trie, &match_list, line, filename); + if (err < 0) + r = err; break; case HW_DATA: @@ -531,19 +520,22 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam if (line[0] != ' ') { log_error("Error, DATA expected but got '%s' in '%s':", line, filename); + r = -EINVAL; state = HW_NONE; udev_list_cleanup(&match_list); break; } - insert_data(trie, &match_list, line, filename); + err = insert_data(trie, &match_list, line, filename); + if (err < 0) + r = err; break; }; } fclose(f); udev_list_cleanup(&match_list); - return 0; + return r; } static void help(void) { @@ -551,6 +543,7 @@ static void help(void) { " -h --help Print this message\n" " -V --version Print version of the program\n" " -u --update Update the hardware database\n" + " -s --strict When updating, return non-zero exit value on any parsing error\n" " --usr Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n" " -t --test=MODALIAS Query database and print result\n" " -r --root=PATH Alternative root path in the filesystem\n\n" @@ -568,6 +561,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { static const struct option options[] = { { "update", no_argument, NULL, 'u' }, { "usr", no_argument, NULL, ARG_USR }, + { "strict", no_argument, NULL, 's' }, { "test", required_argument, NULL, 't' }, { "root", required_argument, NULL, 'r' }, { "version", no_argument, NULL, 'V' }, @@ -581,8 +575,9 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { struct trie *trie = NULL; int err, c; int rc = EXIT_SUCCESS; + bool strict = false; - while ((c = getopt_long(argc, argv, "ut:r:Vh", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "ust:r:Vh", options, NULL)) >= 0) switch(c) { case 'u': update = true; @@ -590,6 +585,9 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { case ARG_USR: hwdb_bin_dir = UDEVLIBEXECDIR; break; + case 's': + strict = true; + break; case 't': test = optarg; break; @@ -646,7 +644,8 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { } STRV_FOREACH(f, files) { log_debug("reading file '%s'", *f); - import_file(udev, trie, *f); + if (import_file(udev, trie, *f) < 0 && strict) + rc = EXIT_FAILURE; } strv_free(files); @@ -680,7 +679,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { rc = EXIT_FAILURE; } - label_fix(hwdb_bin, false, false); + (void) label_fix(hwdb_bin, 0); } if (test) { @@ -699,7 +698,8 @@ out: if (trie) { if (trie->root) trie_node_cleanup(trie->root); - strbuf_cleanup(trie->strings); + if (trie->strings) + strbuf_cleanup(trie->strings); free(trie); } return rc; diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 580e95095b..ff41290478 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2004-2009 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> @@ -173,7 +160,7 @@ static int stat_device(const char *name, bool export, const char *prefix) { } static int export_devices(struct udev *udev) { - _cleanup_udev_enumerate_unref_ struct udev_enumerate *udev_enumerate; + _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *udev_enumerate; struct udev_list_entry *list_entry; udev_enumerate = udev_enumerate_new(udev); @@ -182,7 +169,7 @@ static int export_devices(struct udev *udev) { udev_enumerate_scan_devices(udev_enumerate); udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) { - _cleanup_udev_device_unref_ struct udev_device *device; + _cleanup_(udev_device_unrefp) struct udev_device *device; device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); if (device != NULL) @@ -272,7 +259,7 @@ static void help(void) { } static int uinfo(struct udev *udev, int argc, char *argv[]) { - _cleanup_udev_device_unref_ struct udev_device *device = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *device = NULL; bool root = 0; bool export = 0; const char *export_prefix = NULL; diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index 028ef92bc2..b1e13553dc 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2004-2010 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -79,10 +66,10 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) { bool prop = false; bool print_kernel = false; bool print_udev = false; - _cleanup_udev_list_cleanup_ struct udev_list subsystem_match_list; - _cleanup_udev_list_cleanup_ struct udev_list tag_match_list; - _cleanup_udev_monitor_unref_ struct udev_monitor *udev_monitor = NULL; - _cleanup_udev_monitor_unref_ struct udev_monitor *kernel_monitor = NULL; + _cleanup_(udev_list_cleanup) struct udev_list subsystem_match_list; + _cleanup_(udev_list_cleanup) struct udev_list tag_match_list; + _cleanup_(udev_monitor_unrefp) struct udev_monitor *udev_monitor = NULL; + _cleanup_(udev_monitor_unrefp) struct udev_monitor *kernel_monitor = NULL; _cleanup_close_ int fd_ep = -1; int fd_kernel = -1, fd_udev = -1; struct epoll_event ep_kernel, ep_udev; diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 0af3e6412b..b8d428bcb4 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -1,21 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2006-2009 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2009 Canonical Ltd. - * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com> + * Copyright © 2009 Canonical Ltd. + * Copyright © 2009 Scott James Remnant <scott@netsplit.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index f5a39a11c1..0d6cd46bd7 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2011 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index ef1f2f0269..e3d85597a8 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -1,20 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com> - * Copyright (C) 2004-2008 Kay Sievers <kay@vrfy.org> + * Copyright © 2003-2004 Greg Kroah-Hartman <greg@kroah.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -48,9 +35,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) { const char *action = "add"; const char *syspath = NULL; struct udev_list_entry *entry; - _cleanup_udev_rules_unref_ struct udev_rules *rules = NULL; - _cleanup_udev_device_unref_ struct udev_device *dev = NULL; - _cleanup_udev_event_unref_ struct udev_event *event = NULL; + _cleanup_(udev_rules_unrefp) struct udev_rules *rules = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *dev = NULL; + _cleanup_(udev_event_unrefp) struct udev_event *event = NULL; sigset_t mask, sigmask_orig; int rc = 0, c; diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index d979c1bc24..9c07a51869 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2008-2009 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -134,8 +121,8 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) { TYPE_SUBSYSTEMS, } device_type = TYPE_DEVICES; const char *action = "change"; - _cleanup_udev_enumerate_unref_ struct udev_enumerate *udev_enumerate = NULL; - _cleanup_udev_monitor_unref_ struct udev_monitor *udev_monitor = NULL; + _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *udev_enumerate = NULL; + _cleanup_(udev_monitor_unrefp) struct udev_monitor *udev_monitor = NULL; _cleanup_close_ int fd_ep = -1; int fd_udev = -1; struct epoll_event ep_udev; @@ -230,7 +217,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) { } break; case 'b': { - _cleanup_udev_device_unref_ struct udev_device *dev; + _cleanup_(udev_device_unrefp) struct udev_device *dev; dev = find_device(udev, optarg, "/sys"); if (!dev) { @@ -250,7 +237,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) { break; case ARG_NAME: { - _cleanup_udev_device_unref_ struct udev_device *dev; + _cleanup_(udev_device_unrefp) struct udev_device *dev; dev = find_device(udev, optarg, "/dev/"); if (!dev) { @@ -280,7 +267,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) { } for (; optind < argc; optind++) { - _cleanup_udev_device_unref_ struct udev_device *dev; + _cleanup_(udev_device_unrefp) struct udev_device *dev; dev = find_device(udev, argv[optind], NULL); if (!dev) { @@ -355,7 +342,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) { for (i = 0; i < fdcount; i++) { if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) { - _cleanup_udev_device_unref_ struct udev_device *device; + _cleanup_(udev_device_unrefp) struct udev_device *device; const char *syspath = NULL; device = udev_monitor_receive_device(udev_monitor); diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index b71b9ebd99..c570b72b8e 100644 --- a/src/udev/udevadm-util.c +++ b/src/udev/udevadm-util.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2008-2009 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "path-util.h" diff --git a/src/udev/udevadm-util.h b/src/udev/udevadm-util.h index 8262a8343f..0b426e09f6 100644 --- a/src/udev/udevadm-util.h +++ b/src/udev/udevadm-util.h @@ -2,20 +2,6 @@ #pragma once /* - * Copyright (C) 2014 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "udev.h" diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index 06be1e8af5..0b79d2f91d 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -1,19 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2007-2012 Kay Sievers <kay@vrfy.org> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 615c4ed3e2..34f6a95503 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1,22 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org> - * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca> - * Copyright (C) 2009 Canonical Ltd. - * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com> + * Copyright © 2004 Chris Friesen <chris_friesen@sympatico.ca> + * Copyright © 2009 Canonical Ltd. + * Copyright © 2009 Scott James Remnant <scott@netsplit.com> * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> @@ -233,8 +220,7 @@ static int worker_new(struct worker **ret, Manager *manager, struct udev_monitor if (r < 0) return r; - *ret = worker; - worker = NULL; + *ret = TAKE_PTR(worker); return 0; } @@ -325,9 +311,21 @@ static int worker_send_message(int fd) { return loop_write(fd, &message, sizeof(message), false); } +static bool shall_lock_device(struct udev_device *dev) { + const char *sysname; + + if (!streq_ptr("block", udev_device_get_subsystem(dev))) + return false; + + sysname = udev_device_get_sysname(dev); + return !startswith(sysname, "dm-") && + !startswith(sysname, "md") && + !startswith(sysname, "drbd"); +} + static void worker_spawn(Manager *manager, struct event *event) { struct udev *udev = event->udev; - _cleanup_udev_monitor_unref_ struct udev_monitor *worker_monitor = NULL; + _cleanup_(udev_monitor_unrefp) struct udev_monitor *worker_monitor = NULL; pid_t pid; int r = 0; @@ -353,8 +351,7 @@ static void worker_spawn(Manager *manager, struct event *event) { sigset_t mask; /* take initial device from queue */ - dev = event->dev; - event->dev = NULL; + dev = TAKE_PTR(event->dev); unsetenv("NOTIFY_SOCKET"); @@ -427,9 +424,7 @@ static void worker_spawn(Manager *manager, struct event *event) { * udev has finished its event handling. */ if (!streq_ptr(udev_device_get_action(dev), "remove") && - streq_ptr("block", udev_device_get_subsystem(dev)) && - !startswith(udev_device_get_sysname(dev), "dm-") && - !startswith(udev_device_get_sysname(dev), "md")) { + shall_lock_device(dev)) { struct udev_device *d = dev; if (streq_ptr("partition", udev_device_get_devtype(d))) @@ -923,8 +918,8 @@ static int on_uevent(sd_event_source *s, int fd, uint32_t revents, void *userdat /* receive the udevd message from userspace */ static int on_ctrl_msg(sd_event_source *s, int fd, uint32_t revents, void *userdata) { Manager *manager = userdata; - _cleanup_udev_ctrl_connection_unref_ struct udev_ctrl_connection *ctrl_conn = NULL; - _cleanup_udev_ctrl_msg_unref_ struct udev_ctrl_msg *ctrl_msg = NULL; + _cleanup_(udev_ctrl_connection_unrefp) struct udev_ctrl_connection *ctrl_conn = NULL; + _cleanup_(udev_ctrl_msg_unrefp) struct udev_ctrl_msg *ctrl_msg = NULL; const char *str; int i; @@ -1021,7 +1016,7 @@ static int synthesize_change(struct udev_device *dev) { bool has_partitions = false; int fd; struct udev *udev = udev_device_get_udev(dev); - _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL; + _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; struct udev_list_entry *item; /* @@ -1059,7 +1054,7 @@ static int synthesize_change(struct udev_device *dev) { return r; udev_list_entry_foreach(item, udev_enumerate_get_list_entry(e)) { - _cleanup_udev_device_unref_ struct udev_device *d = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item)); if (!d) @@ -1089,7 +1084,7 @@ static int synthesize_change(struct udev_device *dev) { write_string_file(filename, "change", WRITE_STRING_FILE_CREATE); udev_list_entry_foreach(item, udev_enumerate_get_list_entry(e)) { - _cleanup_udev_device_unref_ struct udev_device *d = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item)); if (!d) @@ -1131,7 +1126,7 @@ static int on_inotify(sd_event_source *s, int fd, uint32_t revents, void *userda } FOREACH_INOTIFY_EVENT(e, buffer, l) { - _cleanup_udev_device_unref_ struct udev_device *dev = NULL; + _cleanup_(udev_device_unrefp) struct udev_device *dev = NULL; dev = udev_watch_lookup(manager->udev, e->wd); if (!dev) @@ -1258,7 +1253,7 @@ static int on_post(sd_event_source *s, void *userdata) { } static int listen_fds(int *rctrl, int *rnetlink) { - _cleanup_udev_unref_ struct udev *udev = NULL; + _cleanup_(udev_unrefp) struct udev *udev = NULL; int ctrl_fd = -1, netlink_fd = -1; int fd, n, r; @@ -1288,7 +1283,7 @@ static int listen_fds(int *rctrl, int *rnetlink) { } if (ctrl_fd < 0) { - _cleanup_udev_ctrl_unref_ struct udev_ctrl *ctrl = NULL; + _cleanup_(udev_ctrl_unrefp) struct udev_ctrl *ctrl = NULL; udev = udev_new(); if (!udev) @@ -1312,7 +1307,7 @@ static int listen_fds(int *rctrl, int *rnetlink) { } if (netlink_fd < 0) { - _cleanup_udev_monitor_unref_ struct udev_monitor *monitor = NULL; + _cleanup_(udev_monitor_unrefp) struct udev_monitor *monitor = NULL; if (!udev) { udev = udev_new(); @@ -1606,8 +1601,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg if (r < 0) return log_error_errno(r, "error creating post event source: %m"); - *ret = manager; - manager = NULL; + *ret = TAKE_PTR(manager); return 0; } @@ -1676,12 +1670,16 @@ int main(int argc, char *argv[]) { if (arg_children_max == 0) { cpu_set_t cpu_set; + unsigned long mem_limit; arg_children_max = 8; if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) == 0) arg_children_max += CPU_COUNT(&cpu_set) * 2; + mem_limit = physical_memory() / (128LU*1024*1024); + arg_children_max = MAX(10U, MIN(arg_children_max, mem_limit)); + log_debug("set children_max to %u", arg_children_max); } @@ -1739,8 +1737,6 @@ int main(int argc, char *argv[]) { log_warning_errno(r, "Failed to redirect standard streams to /dev/null: %m"); } - - pid = fork(); switch (pid) { case 0: diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c index 05f31d479e..4d482891a1 100644 --- a/src/udev/v4l_id/v4l_id.c +++ b/src/udev/v4l_id/v4l_id.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* - * Copyright (C) 2009 Kay Sievers <kay@vrfy.org> * Copyright (c) 2009 Filippo Argiolas <filippo.argiolas@gmail.com> * * This program is free software; you can redistribute it and/or @@ -68,9 +67,11 @@ int main(int argc, char *argv[]) { printf("ID_V4L_VERSION=2\n"); printf("ID_V4L_PRODUCT=%s\n", v2cap.card); printf("ID_V4L_CAPABILITIES=:"); - if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0) + if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0 || + (v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) > 0) printf("capture:"); - if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0) + if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0 || + (v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) > 0) printf("video_output:"); if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0) printf("video_overlay:"); |