libudev.c revision 25e773eeb4f853804e1bf0dbd9a184f23e9b2a97
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt This file is part of systemd.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Copyright 2008-2014 Kay Sievers <kay@vrfy.org>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is free software; you can redistribute it and/or modify it
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt under the terms of the GNU Lesser General Public License as published by
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt the Free Software Foundation; either version 2.1 of the License, or
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt (at your option) any later version.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is distributed in the hope that it will be useful, but
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt WITHOUT ANY WARRANTY; without even the implied warranty of
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Lesser General Public License for more details.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt You should have received a copy of the GNU Lesser General Public License
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt along with systemd; If not, see <http://www.gnu.org/licenses/>.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * SECTION:libudev
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @short_description: libudev context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * The context contains the default values read from the udev config file,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * and is passed to all library operations.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Opaque object representing the library context.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int priority, const char *file, int line, const char *fn,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_get_userdata:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Retrieve stored data pointer from library context. This might be useful
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * to access from callbacks.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Returns: stored userdata
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void *udev_get_userdata(struct udev *udev) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_set_userdata:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @userdata: data pointer
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Store custom @userdata in the library context.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void udev_set_userdata(struct udev *udev, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Create udev library context. This reads the udev configuration
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * file, and fills in the default values.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * The initial refcount is 1, and needs to be decremented to
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * release the resources of the udev library context.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Returns: a new udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt udev_list_init(udev, &udev->properties_list, true);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* find key */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* comment or empty line */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("/etc/udev/udev.conf:%u: missing assignment, skipping line.\n", line_nr);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* find value */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* terminate key */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* terminate value */
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt /* unquote */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("/etc/udev/udev.conf:%u: inconsistent quoting, skipping line.\n", line_nr);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_debug("/etc/udev/udev.conf:%u: invalid log level '%s', ignoring.\n", line_nr, val);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * @udev: udev library context
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Take a reference of the udev library context.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Returns: the passed udev library context
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt_public_ struct udev *udev_ref(struct udev *udev) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * udev_unref:
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * @udev: udev library context
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Drop a reference of the udev library context. If the refcount
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * reaches zero, the resources of the context will be released.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt_public_ struct udev *udev_unref(struct udev *udev) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_set_log_fn:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @log_fn: function to be called for log messages
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * This function is deprecated.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void udev_set_log_fn(struct udev *udev,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int priority, const char *file, int line, const char *fn,
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * udev_get_log_priority:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * This function is deprecated.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ int udev_get_log_priority(struct udev *udev) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_set_log_priority:
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @priority: the new log priority
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * This function is deprecated.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void udev_set_log_priority(struct udev *udev, int priority) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstruct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt list_entry = udev_get_properties_list_entry(udev);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt list_entry = udev_list_entry_get_by_name(list_entry, key);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return udev_list_entry_add(&udev->properties_list, key, value);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstruct udev_list_entry *udev_get_properties_list_entry(struct udev *udev) {