2017-11-18 17:14:42 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
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"
|
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
|
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;
|
2012-01-10 01:34:15 +01:00
|
|
|
bool inotify_watch;
|
|
|
|
bool inotify_watch_final;
|
2012-12-31 04:48:44 +01:00
|
|
|
bool group_set;
|
2012-01-10 01:34:15 +01:00
|
|
|
bool group_final;
|
2012-12-31 04:48:44 +01:00
|
|
|
bool owner_set;
|
2012-01-10 01:34:15 +01:00
|
|
|
bool owner_final;
|
|
|
|
bool mode_set;
|
|
|
|
bool mode_final;
|
|
|
|
bool name_final;
|
|
|
|
bool devlink_final;
|
|
|
|
bool run_final;
|
2018-12-14 10:27:24 +01:00
|
|
|
} UdevEvent;
|
2008-10-16 17:16:58 +02:00
|
|
|
|
2008-10-18 14:33:37 +02:00
|
|
|
/* udev-rules.c */
|
2018-12-14 10:24:40 +01:00
|
|
|
typedef struct UdevRules UdevRules;
|
2018-12-14 10:20:43 +01:00
|
|
|
|
2018-12-14 10:24:40 +01:00
|
|
|
int udev_rules_new(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing);
|
|
|
|
UdevRules *udev_rules_free(UdevRules *rules);
|
|
|
|
|
|
|
|
bool udev_rules_check_timestamp(UdevRules *rules);
|
2018-12-14 10:27:24 +01:00
|
|
|
int udev_rules_apply_to_event(UdevRules *rules, UdevEvent *event,
|
2018-11-13 10:37:05 +01:00
|
|
|
usec_t timeout_usec,
|
2018-10-16 23:47:16 +02:00
|
|
|
Hashmap *properties_list);
|
2018-12-14 10:24:40 +01:00
|
|
|
int udev_rules_apply_static_dev_perms(UdevRules *rules);
|
2008-10-18 19:19:56 +02:00
|
|
|
|
2018-11-13 10:37:05 +01:00
|
|
|
static inline usec_t udev_warn_timeout(usec_t timeout_usec) {
|
|
|
|
return DIV_ROUND_UP(timeout_usec, 3);
|
|
|
|
}
|
|
|
|
|
2008-10-18 19:19:56 +02:00
|
|
|
/* udev-event.c */
|
2018-12-14 10:27:24 +01:00
|
|
|
UdevEvent *udev_event_new(sd_device *dev, usec_t exec_delay_usec, sd_netlink *rtnl);
|
|
|
|
UdevEvent *udev_event_free(UdevEvent *event);
|
|
|
|
ssize_t udev_event_apply_format(UdevEvent *event,
|
2018-10-25 06:59:03 +02:00
|
|
|
const char *src, char *dest, size_t size,
|
|
|
|
bool replace_whitespace);
|
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,
|
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,
|
2018-10-25 04:14:11 +02:00
|
|
|
Hashmap *properties_list,
|
2018-12-14 10:24:40 +01:00
|
|
|
UdevRules *rules);
|
2018-12-14 10:27:24 +01:00
|
|
|
void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec);
|
2008-10-18 14:33:37 +02:00
|
|
|
|
2018-08-22 09:25:17 +02:00
|
|
|
/* Cleanup functions */
|
2018-12-14 10:27:24 +01:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_free);
|
2018-12-14 10:24:40 +01:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(UdevRules*, udev_rules_free);
|