chiark / gitweb /
udev: add builtin 'keyboard' to manage key mappings
[elogind.git] / src / udev / udev.h
1 /*
2  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3  * Copyright (C) 2003-2010 Kay Sievers <kay@vrfy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #pragma once
20
21 #include <sys/types.h>
22 #include <sys/param.h>
23 #include <signal.h>
24
25 #include "macro.h"
26 #include "libudev.h"
27 #include "libudev-private.h"
28 #include "util.h"
29 #include "label.h"
30 #include "strv.h"
31
32 struct udev_event {
33         struct udev *udev;
34         struct udev_device *dev;
35         struct udev_device *dev_parent;
36         struct udev_device *dev_db;
37         char *name;
38         char *program_result;
39         mode_t mode;
40         uid_t uid;
41         gid_t gid;
42         struct udev_list run_list;
43         int exec_delay;
44         usec_t birth_usec;
45         usec_t timeout_usec;
46         int fd_signal;
47         unsigned int builtin_run;
48         unsigned int builtin_ret;
49         bool sigterm;
50         bool inotify_watch;
51         bool inotify_watch_final;
52         bool group_set;
53         bool group_final;
54         bool owner_set;
55         bool owner_final;
56         bool mode_set;
57         bool mode_final;
58         bool name_final;
59         bool devlink_final;
60         bool run_final;
61 };
62
63 struct udev_watch {
64         struct udev_list_node node;
65         int handle;
66         char *name;
67 };
68
69 /* udev-rules.c */
70 struct udev_rules;
71 struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
72 struct udev_rules *udev_rules_unref(struct udev_rules *rules);
73 bool udev_rules_check_timestamp(struct udev_rules *rules);
74 int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask);
75 void udev_rules_apply_static_dev_perms(struct udev_rules *rules);
76
77 /* udev-event.c */
78 struct udev_event *udev_event_new(struct udev_device *dev);
79 void udev_event_unref(struct udev_event *event);
80 size_t udev_event_apply_format(struct udev_event *event, const char *src, char *dest, size_t size);
81 int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string,
82                                    char *result, size_t maxsize, int read_value);
83 int udev_event_spawn(struct udev_event *event,
84                      const char *cmd, char **envp, const sigset_t *sigmask,
85                      char *result, size_t ressize);
86 int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigset);
87 void udev_event_execute_run(struct udev_event *event, const sigset_t *sigset);
88 int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]);
89
90 /* udev-watch.c */
91 int udev_watch_init(struct udev *udev);
92 void udev_watch_restore(struct udev *udev);
93 void udev_watch_begin(struct udev *udev, struct udev_device *dev);
94 void udev_watch_end(struct udev *udev, struct udev_device *dev);
95 struct udev_device *udev_watch_lookup(struct udev *udev, int wd);
96
97 /* udev-node.c */
98 void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid);
99 void udev_node_remove(struct udev_device *dev);
100 void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old);
101
102 /* udev-ctrl.c */
103 struct udev_ctrl;
104 struct udev_ctrl *udev_ctrl_new(struct udev *udev);
105 struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd);
106 int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl);
107 struct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl);
108 struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl);
109 int udev_ctrl_cleanup(struct udev_ctrl *uctrl);
110 struct udev *udev_ctrl_get_udev(struct udev_ctrl *uctrl);
111 int udev_ctrl_get_fd(struct udev_ctrl *uctrl);
112 int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout);
113 int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout);
114 int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout);
115 int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout);
116 int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout);
117 int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout);
118 int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout);
119 int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, int timeout);
120 struct udev_ctrl_connection;
121 struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl);
122 struct udev_ctrl_connection *udev_ctrl_connection_ref(struct udev_ctrl_connection *conn);
123 struct udev_ctrl_connection *udev_ctrl_connection_unref(struct udev_ctrl_connection *conn);
124 struct udev_ctrl_msg;
125 struct udev_ctrl_msg *udev_ctrl_receive_msg(struct udev_ctrl_connection *conn);
126 struct udev_ctrl_msg *udev_ctrl_msg_ref(struct udev_ctrl_msg *ctrl_msg);
127 struct udev_ctrl_msg *udev_ctrl_msg_unref(struct udev_ctrl_msg *ctrl_msg);
128 int udev_ctrl_get_set_log_level(struct udev_ctrl_msg *ctrl_msg);
129 int udev_ctrl_get_stop_exec_queue(struct udev_ctrl_msg *ctrl_msg);
130 int udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg);
131 int udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg);
132 int udev_ctrl_get_ping(struct udev_ctrl_msg *ctrl_msg);
133 int udev_ctrl_get_exit(struct udev_ctrl_msg *ctrl_msg);
134 const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg);
135 int udev_ctrl_get_set_children_max(struct udev_ctrl_msg *ctrl_msg);
136
137 /* built-in commands */
138 enum udev_builtin_cmd {
139 #ifdef HAVE_BLKID
140         UDEV_BUILTIN_BLKID,
141 #endif
142         UDEV_BUILTIN_BTRFS,
143 #ifdef HAVE_FIRMWARE
144         UDEV_BUILTIN_FIRMWARE,
145 #endif
146         UDEV_BUILTIN_HWDB,
147         UDEV_BUILTIN_INPUT_ID,
148         UDEV_BUILTIN_KEYBOARD,
149 #ifdef HAVE_KMOD
150         UDEV_BUILTIN_KMOD,
151 #endif
152         UDEV_BUILTIN_NET_ID,
153         UDEV_BUILTIN_PATH_ID,
154         UDEV_BUILTIN_USB_ID,
155 #ifdef HAVE_ACL
156         UDEV_BUILTIN_UACCESS,
157 #endif
158         UDEV_BUILTIN_MAX
159 };
160 struct udev_builtin {
161         const char *name;
162         int (*cmd)(struct udev_device *dev, int argc, char *argv[], bool test);
163         const char *help;
164         int (*init)(struct udev *udev);
165         void (*exit)(struct udev *udev);
166         bool (*validate)(struct udev *udev);
167         bool run_once;
168 };
169 #ifdef HAVE_BLKID
170 extern const struct udev_builtin udev_builtin_blkid;
171 #endif
172 extern const struct udev_builtin udev_builtin_btrfs;
173 #ifdef HAVE_FIRMWARE
174 extern const struct udev_builtin udev_builtin_firmware;
175 #endif
176 extern const struct udev_builtin udev_builtin_hwdb;
177 extern const struct udev_builtin udev_builtin_input_id;
178 extern const struct udev_builtin udev_builtin_keyboard;
179 #ifdef HAVE_KMOD
180 extern const struct udev_builtin udev_builtin_kmod;
181 #endif
182 extern const struct udev_builtin udev_builtin_net_id;
183 extern const struct udev_builtin udev_builtin_path_id;
184 extern const struct udev_builtin udev_builtin_usb_id;
185 extern const struct udev_builtin udev_builtin_uaccess;
186 void udev_builtin_init(struct udev *udev);
187 void udev_builtin_exit(struct udev *udev);
188 enum udev_builtin_cmd udev_builtin_lookup(const char *command);
189 const char *udev_builtin_name(enum udev_builtin_cmd cmd);
190 bool udev_builtin_run_once(enum udev_builtin_cmd cmd);
191 int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test);
192 void udev_builtin_list(struct udev *udev);
193 bool udev_builtin_validate(struct udev *udev);
194 int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val);
195 int udev_builtin_hwdb_lookup(struct udev_device *dev, const char *prefix, const char *modalias,
196                              const char *filter, bool test);
197
198 /* udev logging */
199 void udev_main_log(struct udev *udev, int priority,
200                    const char *file, int line, const char *fn,
201                    const char *format, va_list args) _printf_attr_(6, 0);
202
203 /* udevadm commands */
204 struct udevadm_cmd {
205         const char *name;
206         int (*cmd)(struct udev *udev, int argc, char *argv[]);
207         const char *help;
208         int debug;
209 };
210 extern const struct udevadm_cmd udevadm_info;
211 extern const struct udevadm_cmd udevadm_trigger;
212 extern const struct udevadm_cmd udevadm_settle;
213 extern const struct udevadm_cmd udevadm_control;
214 extern const struct udevadm_cmd udevadm_monitor;
215 extern const struct udevadm_cmd udevadm_hwdb;
216 extern const struct udevadm_cmd udevadm_test;
217 extern const struct udevadm_cmd udevadm_test_builtin;