libudev.c revision 25e773eeb4f853804e1bf0dbd9a184f23e9b2a97
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/***
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt This file is part of systemd.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Copyright 2008-2014 Kay Sievers <kay@vrfy.org>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
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
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
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***/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <stdio.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <stdlib.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <stddef.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <stdarg.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <unistd.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <errno.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <string.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <ctype.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include <time.h>
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include "libudev.h"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include "libudev-private.h"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include "missing.h"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/**
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * SECTION:libudev
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @short_description: libudev context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
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 */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/**
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Opaque object representing the library context.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstruct udev {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int refcount;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt void (*log_fn)(struct udev *udev,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int priority, const char *file, int line, const char *fn,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt const char *format, va_list args);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt void *userdata;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt struct udev_list properties_list;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt};
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/**
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_get_userdata:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Retrieve stored data pointer from library context. This might be useful
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * to access from callbacks.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Returns: stored userdata
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt **/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void *udev_get_userdata(struct udev *udev) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (udev == NULL)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return udev->userdata;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/**
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_set_userdata:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @userdata: data pointer
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Store custom @userdata in the library context.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt **/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void udev_set_userdata(struct udev *udev, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (udev == NULL)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt udev->userdata = userdata;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/**
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_new:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Create udev library context. This reads the udev configuration
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * file, and fills in the default values.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
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 *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * Returns: a new udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt **/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ struct udev *udev_new(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt struct udev *udev;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_fclose_ FILE *f = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt udev = new0(struct udev, 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (udev == NULL)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt udev->refcount = 1;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt udev_list_init(udev, &udev->properties_list, true);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt f = fopen("/etc/udev/udev.conf", "re");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (f != NULL) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char line[UTIL_LINE_SIZE];
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt unsigned line_nr = 0;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while (fgets(line, sizeof(line), f)) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt size_t len;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *key;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt line_nr++;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* find key */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key = line;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while (isspace(key[0]))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key++;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* comment or empty line */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (key[0] == '#' || key[0] == '\0')
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt continue;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* split key/value */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val = strchr(key, '=');
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (val == NULL) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("/etc/udev/udev.conf:%u: missing assignment, skipping line.\n", line_nr);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt continue;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val[0] = '\0';
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val++;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* find value */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while (isspace(val[0]))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val++;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* terminate key */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt len = strlen(key);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (len == 0)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt continue;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while (isspace(key[len-1]))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt len--;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key[len] = '\0';
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* terminate value */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt len = strlen(val);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (len == 0)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt continue;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while (isspace(val[len-1]))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt len--;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val[len] = '\0';
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (len == 0)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt continue;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt /* unquote */
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (val[0] == '"' || val[0] == '\'') {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (val[len-1] != val[0]) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("/etc/udev/udev.conf:%u: inconsistent quoting, skipping line.\n", line_nr);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt continue;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val[len-1] = '\0';
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val++;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (streq(key, "udev_log")) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt int prio;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt prio = util_log_priority(val);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (prio < 0)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_debug("/etc/udev/udev.conf:%u: invalid log level '%s', ignoring.\n", line_nr, val);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt else
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_set_max_level(prio);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt continue;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return udev;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt/**
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * udev_ref:
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * @udev: udev library context
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt *
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Take a reference of the udev library context.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt *
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Returns: the passed udev library context
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt **/
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt_public_ struct udev *udev_ref(struct udev *udev) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (udev == NULL)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt udev->refcount++;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return udev;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt/**
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * udev_unref:
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * @udev: udev library context
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt *
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 *
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt **/
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt_public_ struct udev *udev_unref(struct udev *udev) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (udev == NULL)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt udev->refcount--;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (udev->refcount > 0)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return udev;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt udev_list_cleanup(&udev->properties_list);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(udev);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/**
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 *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * This function is deprecated.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt **/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void udev_set_log_fn(struct udev *udev,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt void (*log_fn)(struct udev *udev,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int priority, const char *file, int line, const char *fn,
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt const char *format, va_list args)) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt/**
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * udev_get_log_priority:
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * This function is deprecated.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt **/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ int udev_get_log_priority(struct udev *udev) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt return log_get_max_level();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt/**
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * udev_set_log_priority:
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * @udev: udev library context
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * @priority: the new log priority
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt *
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * This function is deprecated.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt *
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt **/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt_public_ void udev_set_log_priority(struct udev *udev, int priority) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_set_max_level(priority);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstruct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (value == NULL) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt struct udev_list_entry *list_entry;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
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 if (list_entry != NULL)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt udev_list_entry_delete(list_entry);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return udev_list_entry_add(&udev->properties_list, key, value);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstruct udev_list_entry *udev_get_properties_list_entry(struct udev *udev) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt return udev_list_get_entry(&udev->properties_list);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt