libudev.c revision ff944daa019c1101d6464412e6682732ec11143a
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * libudev - interface to udev device information
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This library is free software; you can redistribute it and/or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * modify it under the terms of the GNU Lesser General Public
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * License as published by the Free Software Foundation; either
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * version 2.1 of the License, or (at your option) any later version.
51323288fc628a5cac50914df915545d685b793eLennart Poettering * SECTION:libudev
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @short_description: libudev context
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering * The context contains the default values read from the udev config file,
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering * and is passed to all library operations.
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering * Opaque object representing the library context.
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering int priority, const char *file, int line, const char *fn,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int priority, const char *file, int line, const char *fn,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering const char *format, ...)
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering udev->log_fn(udev, priority, file, line, fn, format, args);
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering int priority, const char *file, int line, const char *fn,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * udev_get_userdata:
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering * @udev: udev library context
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * Retrieve stored data pointer from library context. This might be useful
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * to access from callbacks like a custom logging function.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Returns: stored userdata
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering_public_ void *udev_get_userdata(struct udev *udev)
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * udev_set_userdata:
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * @udev: udev library context
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering * @userdata: data pointer
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering * Store custom @userdata in the library context.
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering_public_ void udev_set_userdata(struct udev *udev, void *userdata)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering * Create udev library context. This reads the udev configuration
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering * file, and fills in the default values.
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering * The initial refcount is 1, and needs to be decremented to
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering * release the resources of the udev library context.
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * Returns: a new udev library context
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering udev_list_init(udev, &udev->properties_list, true);
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering /* find key */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* comment or empty line */
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering udev_err(udev, "missing <key>=<value> in /etc/udev/udev.conf[%i]; skip line\n", line_nr);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering /* find value */
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering /* terminate key */
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering /* terminate value */
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering udev_err(udev, "inconsistent quoting in /etc/udev/udev.conf[%i]; skip line\n", line_nr);
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering udev_set_log_priority(udev, util_log_priority(val));
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering /* environment overrides config */
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering udev_set_log_priority(udev, util_log_priority(env));
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering * @udev: udev library context
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Take a reference of the udev library context.
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt * Returns: the passed udev library context
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering_public_ struct udev *udev_ref(struct udev *udev)
51323288fc628a5cac50914df915545d685b793eLennart Poettering * @udev: udev library context
51323288fc628a5cac50914df915545d685b793eLennart Poettering * Drop a reference of the udev library context. If the refcount
51323288fc628a5cac50914df915545d685b793eLennart Poettering * reaches zero, the resources of the context will be released.
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
51323288fc628a5cac50914df915545d685b793eLennart Poettering_public_ struct udev *udev_unref(struct udev *udev)
51323288fc628a5cac50914df915545d685b793eLennart Poettering udev_list_cleanup(&udev->properties_list);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * udev_set_log_fn:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * @udev: udev library context
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering * @log_fn: function to be called for logging messages
51323288fc628a5cac50914df915545d685b793eLennart Poettering * The built-in logging writes to stderr. It can be
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * overridden by a custom function, to plug log messages
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * into the users' logging functionality.
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering_public_ void udev_set_log_fn(struct udev *udev,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering int priority, const char *file, int line, const char *fn,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering udev_dbg(udev, "custom logging function %p registered\n", log_fn);
51323288fc628a5cac50914df915545d685b793eLennart Poettering * udev_get_log_priority:
51323288fc628a5cac50914df915545d685b793eLennart Poettering * @udev: udev library context
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering * The initial logging priority is read from the udev config file
51323288fc628a5cac50914df915545d685b793eLennart Poettering * Returns: the current logging priority
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering_public_ int udev_get_log_priority(struct udev *udev)
966c66e34940001a40806142ecebaae61b478444Lennart Poettering * udev_set_log_priority:
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering * @udev: udev library context
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering * @priority: the new logging priority
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering * Set the current logging priority. The value controls which messages
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering_public_ void udev_set_log_priority(struct udev *udev, int priority)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering snprintf(num, sizeof(num), "%u", udev->log_priority);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering udev_add_property(udev, "UDEV_LOG", num);
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poetteringstruct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering list_entry = udev_get_properties_list_entry(udev);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering list_entry = udev_list_entry_get_by_name(list_entry, key);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return udev_list_entry_add(&udev->properties_list, key, value);
039a8725fdff1d71e9efd28f27741601c5b4235cLennart Poetteringstruct udev_list_entry *udev_get_properties_list_entry(struct udev *udev)