1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #pragma once
3 
4 /*
5  * Copyright © 2003 Greg Kroah-Hartman <greg@kroah.com>
6  */
7 
8 #include "sd-device.h"
9 #include "sd-netlink.h"
10 
11 #include "hashmap.h"
12 #include "macro.h"
13 #include "udev-rules.h"
14 #include "udev-util.h"
15 #include "util.h"
16 
17 #define READ_END  0
18 #define WRITE_END 1
19 #define UDEV_ALLOWED_CHARS_INPUT        "/ $%?,"
20 
21 typedef struct UdevEvent {
22         sd_device *dev;
23         sd_device *dev_parent;
24         sd_device *dev_db_clone;
25         char *name;
26         char *program_result;
27         mode_t mode;
28         uid_t uid;
29         gid_t gid;
30         OrderedHashmap *seclabel_list;
31         OrderedHashmap *run_list;
32         usec_t exec_delay_usec;
33         usec_t birth_usec;
34         sd_netlink *rtnl;
35         unsigned builtin_run;
36         unsigned builtin_ret;
37         UdevRuleEscapeType esc:8;
38         bool inotify_watch;
39         bool inotify_watch_final;
40         bool group_final;
41         bool owner_final;
42         bool mode_final;
43         bool name_final;
44         bool devlink_final;
45         bool run_final;
46         bool log_level_was_debug;
47         int default_log_level;
48 } UdevEvent;
49 
50 UdevEvent *udev_event_new(sd_device *dev, usec_t exec_delay_usec, sd_netlink *rtnl, int log_level);
51 UdevEvent *udev_event_free(UdevEvent *event);
52 DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_free);
53 
54 size_t udev_event_apply_format(
55                 UdevEvent *event,
56                 const char *src,
57                 char *dest,
58                 size_t size,
59                 bool replace_whitespace,
60                 bool *ret_truncated);
61 int udev_check_format(const char *value, size_t *offset, const char **hint);
62 int udev_event_spawn(
63                 UdevEvent *event,
64                 usec_t timeout_usec,
65                 int timeout_signal,
66                 bool accept_failure,
67                 const char *cmd,
68                 char *result,
69                 size_t ressize,
70                 bool *ret_truncated);
71 int udev_event_execute_rules(
72                 UdevEvent *event,
73                 int inotify_fd,
74                 usec_t timeout_usec,
75                 int timeout_signal,
76                 Hashmap *properties_list,
77                 UdevRules *rules);
78 void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_signal);
79 int udev_event_process_inotify_watch(UdevEvent *event, int inotify_fd);
80 
udev_warn_timeout(usec_t timeout_usec)81 static inline usec_t udev_warn_timeout(usec_t timeout_usec) {
82         return DIV_ROUND_UP(timeout_usec, 3);
83 }
84