2020-11-09 05:25:50 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2016-02-16 20:05:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
2005-04-27 05:59:47 +02:00
|
|
|
/*
|
2018-06-12 17:15:23 +02:00
|
|
|
* Copyright © 2003 Greg Kroah-Hartman <greg@kroah.com>
|
2005-04-27 05:59:47 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-14 21:13:29 +02:00
|
|
|
#include "sd-device.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "sd-netlink.h"
|
|
|
|
|
2018-10-16 22:37:34 +02:00
|
|
|
#include "hashmap.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "macro.h"
|
2019-04-25 01:21:11 +02:00
|
|
|
#include "udev-rules.h"
|
2018-11-13 13:42:42 +01:00
|
|
|
#include "udev-util.h"
|
2018-11-16 03:28:07 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#define READ_END 0
|
|
|
|
#define WRITE_END 1
|
2020-12-14 08:26:13 +01:00
|
|
|
#define UDEV_ALLOWED_CHARS_INPUT "/ $%?,"
|
2005-04-27 05:59:47 +02:00
|
|
|
|
2018-12-14 10:27:24 +01:00
|
|
|
typedef struct UdevEvent {
|
2018-10-29 08:27:13 +01:00
|
|
|
sd_device *dev;
|
2018-10-29 07:16:00 +01:00
|
|
|
sd_device *dev_parent;
|
2018-10-29 07:01:39 +01:00
|
|
|
sd_device *dev_db_clone;
|
2012-01-10 01:34:15 +01:00
|
|
|
char *name;
|
|
|
|
char *program_result;
|
|
|
|
mode_t mode;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2019-03-04 20:01:34 +01:00
|
|
|
OrderedHashmap *seclabel_list;
|
|
|
|
OrderedHashmap *run_list;
|
2018-10-25 07:56:12 +02:00
|
|
|
usec_t exec_delay_usec;
|
2012-11-11 20:45:05 +01:00
|
|
|
usec_t birth_usec;
|
2015-06-12 16:31:33 +02:00
|
|
|
sd_netlink *rtnl;
|
2018-10-19 20:00:46 +02:00
|
|
|
unsigned builtin_run;
|
|
|
|
unsigned builtin_ret;
|
2019-04-25 01:21:11 +02:00
|
|
|
UdevRuleEscapeType esc:8;
|
2020-12-08 13:49:34 +01:00
|
|
|
bool inotify_watch;
|
|
|
|
bool inotify_watch_final;
|
|
|
|
bool group_final;
|
|
|
|
bool owner_final;
|
|
|
|
bool mode_final;
|
|
|
|
bool name_final;
|
|
|
|
bool devlink_final;
|
|
|
|
bool run_final;
|
2020-12-08 14:37:12 +01:00
|
|
|
bool log_level_was_debug;
|
|
|
|
int default_log_level;
|
2018-12-14 10:27:24 +01:00
|
|
|
} UdevEvent;
|
2008-10-16 17:16:58 +02:00
|
|
|
|
2020-12-08 14:37:12 +01:00
|
|
|
UdevEvent *udev_event_new(sd_device *dev, usec_t exec_delay_usec, sd_netlink *rtnl, int log_level);
|
2018-12-14 10:27:24 +01:00
|
|
|
UdevEvent *udev_event_free(UdevEvent *event);
|
2019-04-25 01:21:11 +02:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_free);
|
|
|
|
|
2020-06-18 06:48:45 +02:00
|
|
|
size_t udev_event_apply_format(UdevEvent *event,
|
|
|
|
const char *src, char *dest, size_t size,
|
|
|
|
bool replace_whitespace);
|
udev-rules: add precise information to rule failure logs
It is pretty hard to figure out what the problem actually is, esp. when the rule
is long.
On my machine:
systemd[1]: Starting udev Kernel Device Manager...
systemd-udevd[217399]: /usr/lib/udev/rules.d/11-dm-lvm.rules:40 Invalid value for OPTIONS key, ignoring: 'event_timeout=180'
systemd-udevd[217399]: /usr/lib/udev/rules.d/11-dm-lvm.rules:40 The line takes no effect, ignoring.
systemd-udevd[217399]: /etc/udev/rules.d/60-ipath.rules:4 Invalid value "kcopy/%02n" for NAME (char 7: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/65-md-incremental.rules:28 Invalid value "/sbin/mdadm -I $env{DEVNAME} --export $devnode --offroot ${DEVLINKS}" for IMPORT (char 58: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /etc/udev/rules.d/73-special-net-names.rules:14 Invalid value "/bin/sh -ec 'D=${DEVPATH#*/vio/}; D=${D%%%%/*}; D=${D#????}; D=${D#0}; D=${D#0}; D=${D#0}; D=${D#0}; echo ${D:-0}'" for PROGRAM (char 16: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/84-nm-drivers.rules:10 Invalid value "/bin/sh -c 'ethtool -i $1 | sed -n s/^driver:\ //p' -- $env{INTERFACE}" for PROGRAM (char 24: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/90-libgpod.rules:19 IMPORT key takes '==' or '!=' operator, assuming '==', but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/90-libgpod.rules:23 IMPORT key takes '==' or '!=' operator, assuming '==', but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/99-vmware-scsi-udev.rules:5 Invalid value "/bin/sh -c 'echo 180 >/sys$DEVPATH/device/timeout'" for RUN (char 27: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/99-vmware-scsi-udev.rules:6 Invalid value "/bin/sh -c 'echo 180 >/sys$DEVPATH/device/timeout'" for RUN (char 27: invalid substitution type), ignoring, but please fix it.
systemd[1]: Started udev Kernel Device Manager.
2019-06-27 10:47:56 +02:00
|
|
|
int udev_check_format(const char *value, size_t *offset, const char **hint);
|
2018-12-14 10:27:24 +01:00
|
|
|
int udev_event_spawn(UdevEvent *event,
|
2014-07-29 15:18:27 +02:00
|
|
|
usec_t timeout_usec,
|
2020-04-09 11:14:25 +02:00
|
|
|
int timeout_signal,
|
2015-06-10 15:20:02 +02:00
|
|
|
bool accept_failure,
|
2015-06-28 23:42:52 +02:00
|
|
|
const char *cmd, char *result, size_t ressize);
|
2018-12-14 10:27:24 +01:00
|
|
|
int udev_event_execute_rules(UdevEvent *event,
|
2018-11-13 10:37:05 +01:00
|
|
|
usec_t timeout_usec,
|
2020-04-09 11:14:25 +02:00
|
|
|
int timeout_signal,
|
2018-10-25 04:14:11 +02:00
|
|
|
Hashmap *properties_list,
|
2018-12-14 10:24:40 +01:00
|
|
|
UdevRules *rules);
|
2020-04-09 11:14:25 +02:00
|
|
|
void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_signal);
|
2008-10-18 14:33:37 +02:00
|
|
|
|
2019-04-25 01:21:11 +02:00
|
|
|
static inline usec_t udev_warn_timeout(usec_t timeout_usec) {
|
|
|
|
return DIV_ROUND_UP(timeout_usec, 3);
|
|
|
|
}
|