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/sysmacros.h> 22 #include <sys/types.h> 23 #include <sys/param.h> 24 #include <signal.h> 25 26 #include "macro.h" 27 #include "libudev.h" 28 #include "libudev-private.h" 29 #include "util.h" 30 #include "label.h" 31 #include "strv.h" 32 33 struct udev_event { 34 struct udev *udev; 35 struct udev_device *dev; 36 struct udev_device *dev_parent; 37 struct udev_device *dev_db; 38 char *name; 39 char *program_result; 40 mode_t mode; 41 uid_t uid; 42 gid_t gid; 43 struct udev_list seclabel_list; 44 struct udev_list run_list; 45 int exec_delay; 46 usec_t birth_usec; 47 int fd_signal; 48 unsigned int builtin_run; 49 unsigned int builtin_ret; 50 bool sigterm; 51 bool inotify_watch; 52 bool inotify_watch_final; 53 bool group_set; 54 bool group_final; 55 bool owner_set; 56 bool owner_final; 57 bool mode_set; 58 bool mode_final; 59 bool name_final; 60 bool devlink_final; 61 bool run_final; 62 }; 63 64 struct udev_watch { 65 struct udev_list_node node; 66 int handle; 67 char *name; 68 }; 69 70 /* udev-rules.c */ 71 struct udev_rules; 72 struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names); 73 struct udev_rules *udev_rules_unref(struct udev_rules *rules); 74 bool udev_rules_check_timestamp(struct udev_rules *rules); 75 int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, 76 usec_t timeout_usec, usec_t timeout_warn_usec, 77 struct udev_list *properties_list, 78 const sigset_t *sigmask); 79 int udev_rules_apply_static_dev_perms(struct udev_rules *rules); 80 81 /* udev-event.c */ 82 struct udev_event *udev_event_new(struct udev_device *dev); 83 void udev_event_unref(struct udev_event *event); 84 size_t udev_event_apply_format(struct udev_event *event, 85 const char *src, char *dest, size_t size, 86 bool replace_whitespace); 87 int udev_event_apply_subsys_kernel(struct udev_event *event, const char *string, 88 char *result, size_t maxsize, int read_value); 89 int udev_event_spawn(struct udev_event *event, 90 usec_t timeout_usec, 91 usec_t timeout_warn_usec, 92 const char *cmd, char **envp, const sigset_t *sigmask, 93 char *result, size_t ressize); 94 void udev_event_execute_rules(struct udev_event *event, 95 usec_t timeout_usec, usec_t timeout_warn_usec, 96 struct udev_list *properties_list, 97 struct udev_rules *rules, 98 const sigset_t *sigset); 99 void udev_event_execute_run(struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec, const sigset_t *sigset); 100 int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]); 101 102 /* udev-watch.c */ 103 int udev_watch_init(struct udev *udev); 104 void udev_watch_restore(struct udev *udev); 105 void udev_watch_begin(struct udev *udev, struct udev_device *dev); 106 void udev_watch_end(struct udev *udev, struct udev_device *dev); 107 struct udev_device *udev_watch_lookup(struct udev *udev, int wd); 108 109 /* udev-node.c */ 110 void udev_node_add(struct udev_device *dev, bool apply, 111 mode_t mode, uid_t uid, gid_t gid, 112 struct udev_list *seclabel_list); 113 void udev_node_remove(struct udev_device *dev); 114 void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old); 115 116 /* udev-ctrl.c */ 117 struct udev_ctrl; 118 struct udev_ctrl *udev_ctrl_new(struct udev *udev); 119 struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd); 120 int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl); 121 struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl); 122 int udev_ctrl_cleanup(struct udev_ctrl *uctrl); 123 struct udev *udev_ctrl_get_udev(struct udev_ctrl *uctrl); 124 int udev_ctrl_get_fd(struct udev_ctrl *uctrl); 125 int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout); 126 int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout); 127 int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout); 128 int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout); 129 int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout); 130 int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout); 131 int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout); 132 int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, int timeout); 133 struct udev_ctrl_connection; 134 struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl); 135 struct udev_ctrl_connection *udev_ctrl_connection_ref(struct udev_ctrl_connection *conn); 136 struct udev_ctrl_connection *udev_ctrl_connection_unref(struct udev_ctrl_connection *conn); 137 struct udev_ctrl_msg; 138 struct udev_ctrl_msg *udev_ctrl_receive_msg(struct udev_ctrl_connection *conn); 139 struct udev_ctrl_msg *udev_ctrl_msg_unref(struct udev_ctrl_msg *ctrl_msg); 140 int udev_ctrl_get_set_log_level(struct udev_ctrl_msg *ctrl_msg); 141 int udev_ctrl_get_stop_exec_queue(struct udev_ctrl_msg *ctrl_msg); 142 int udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg); 143 int udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg); 144 int udev_ctrl_get_ping(struct udev_ctrl_msg *ctrl_msg); 145 int udev_ctrl_get_exit(struct udev_ctrl_msg *ctrl_msg); 146 const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg); 147 int udev_ctrl_get_set_children_max(struct udev_ctrl_msg *ctrl_msg); 148 149 /* built-in commands */ 150 enum udev_builtin_cmd { 151 #ifdef HAVE_BLKID 152 UDEV_BUILTIN_BLKID, 153 #endif 154 UDEV_BUILTIN_BTRFS, 155 UDEV_BUILTIN_HWDB, 156 UDEV_BUILTIN_INPUT_ID, 157 UDEV_BUILTIN_KEYBOARD, 158 #ifdef HAVE_KMOD 159 UDEV_BUILTIN_KMOD, 160 #endif 161 UDEV_BUILTIN_NET_ID, 162 UDEV_BUILTIN_PATH_ID, 163 UDEV_BUILTIN_USB_ID, 164 UDEV_BUILTIN_MAX 165 }; 166 struct udev_builtin { 167 const char *name; 168 int (*cmd)(struct udev_device *dev, int argc, char *argv[], bool test); 169 const char *help; 170 int (*init)(struct udev *udev); 171 void (*exit)(struct udev *udev); 172 bool (*validate)(struct udev *udev); 173 bool run_once; 174 }; 175 #ifdef HAVE_BLKID 176 extern const struct udev_builtin udev_builtin_blkid; 177 #endif 178 extern const struct udev_builtin udev_builtin_btrfs; 179 extern const struct udev_builtin udev_builtin_hwdb; 180 extern const struct udev_builtin udev_builtin_input_id; 181 extern const struct udev_builtin udev_builtin_keyboard; 182 #ifdef HAVE_KMOD 183 extern const struct udev_builtin udev_builtin_kmod; 184 #endif 185 extern const struct udev_builtin udev_builtin_net_id; 186 extern const struct udev_builtin udev_builtin_path_id; 187 extern const struct udev_builtin udev_builtin_usb_id; 188 void udev_builtin_init(struct udev *udev); 189 void udev_builtin_exit(struct udev *udev); 190 enum udev_builtin_cmd udev_builtin_lookup(const char *command); 191 const char *udev_builtin_name(enum udev_builtin_cmd cmd); 192 bool udev_builtin_run_once(enum udev_builtin_cmd cmd); 193 int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test); 194 void udev_builtin_list(struct udev *udev); 195 bool udev_builtin_validate(struct udev *udev); 196 int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val); 197 int udev_builtin_hwdb_lookup(struct udev_device *dev, const char *prefix, const char *modalias, 198 const char *filter, bool test); 199 200 /* udevadm commands */ 201 struct udevadm_cmd { 202 const char *name; 203 int (*cmd)(struct udev *udev, int argc, char *argv[]); 204 const char *help; 205 int debug; 206 }; 207 extern const struct udevadm_cmd udevadm_info; 208 extern const struct udevadm_cmd udevadm_trigger; 209 extern const struct udevadm_cmd udevadm_settle; 210 extern const struct udevadm_cmd udevadm_control; 211 extern const struct udevadm_cmd udevadm_monitor; 212 extern const struct udevadm_cmd udevadm_hwdb; 213 extern const struct udevadm_cmd udevadm_test; 214 extern const struct udevadm_cmd udevadm_test_builtin; 215