device-private.c revision 8b43440b7ef4b81c69c31de7ff820dc07a780254
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering This file is part of systemd.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering Copyright 2014 Tom Gundersen <teg@jklm.no>
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering systemd is free software; you can redistribute it and/or modify it
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering under the terms of the GNU Lesser General Public License as published by
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering (at your option) any later version.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering systemd is distributed in the hope that it will be useful, but
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering Lesser General Public License for more details.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering You should have received a copy of the GNU Lesser General Public License
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringint device_add_property(sd_device *device, const char *key, const char *value) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = device_add_property_aux(device, key, value, false);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = device_add_property_aux(device, key, value, true);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic int device_add_property_internal_from_string(sd_device *device, const char *str) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering return device_add_property_internal(device, key, value);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic int handle_db_line(sd_device *device, char key, const char *value) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = safe_atoi(value, &device->devlink_priority);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = device_add_property_internal_from_string(device, value);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = safe_atoi(value, &device->watch_handle);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = device_set_usec_initialized(device, value);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering log_debug("device db: unknown key '%c'", key);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringvoid device_set_devlink_priority(sd_device *device, int priority) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringvoid device_set_is_initialized(sd_device *device) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringint device_ensure_usec_initialized(sd_device *device, sd_device *device_old) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering if (device_old && device_old->usec_initialized > 0)
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering usec_initialized = device_old->usec_initialized;
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering r = device_set_usec_initialized(device, num);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic int device_read_db(sd_device *device) {
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering return log_debug_errno(r, "sd-device: failed to read db '%s': %m", path);
dea7b6b043f0cd9e34ee719b9b612c3a4776387eLennart Poettering /* devices with a database entry are initialized */
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering for (i = 0; i < db_len; i++) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering log_debug("sd-device: ignoring invalid db entry with key '%c'", key);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering log_debug_errno(r, "sd-device: failed to handle db entry '%c:%s': %m", key, value);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_not_reached("invalid state when parsing db");
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringuint64_t device_get_properties_generation(sd_device *device) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringuint64_t device_get_tags_generation(sd_device *device) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringuint64_t device_get_devlinks_generation(sd_device *device) {
char *path;
size_t l;
size_t l;
static int device_append(sd_device *device, char *key, const char **_major, const char **_minor, uint64_t *_seqnum,
char *value;
if (!value) {
return -EINVAL;
value++;
return -EINVAL;
else if (seqnum == 0)
return -EINVAL;
if (major != 0)
if (minor != 0)
if (seqnum > 0)
return -EINVAL;
char **key;
if (major) {
while (i < len) {
char *key;
const char *end;
if (!end) {
return -EINVAL;
if (major) {
if (!buf_nulstr)
return -ENOMEM;
++num;
if (!buf_strv)
return -ENOMEM;
char *new_syspath;
const char *interface;
if (!dirname)
return -ENOMEM;
/* like DEVPATH_OLD, INTERFACE_OLD is not saved to the db, but only stays around for the current event */
} else if (r != -ENOENT)
int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, const char *action) {
const char *id;
char *path;
if (add) {
return -errno;
const char *tag;
const char *id;
char *path;
bool has_info;
return -errno;
r = -errno;
goto fail;
r = -errno;
goto fail;
if (has_info) {
Iterator i;
const char *devlink;
r = fflush_and_check(f);
goto fail;
r = -errno;
goto fail;
fail:
return log_error_errno(r, "failed to create %s file '%s' for '%s'", has_info ? "db" : "empty", path, device->devpath);
const char *id;
char *path;
return -errno;