device-private.c revision ccc1002a1c510b7d4631833eaf60225f028f2280
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier This file is part of systemd.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier Copyright 2014 Tom Gundersen <teg@jklm.no>
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier systemd is free software; you can redistribute it and/or modify it
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier under the terms of the GNU Lesser General Public License as published by
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier the Free Software Foundation; either version 2.1 of the License, or
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier (at your option) any later version.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier systemd is distributed in the hope that it will be useful, but
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier WITHOUT ANY WARRANTY; without even the implied warranty of
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier Lesser General Public License for more details.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier You should have received a copy of the GNU Lesser General Public License
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalierint device_add_property(sd_device *device, const char *key, const char *value) {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier r = device_add_property_aux(device, key, value, false);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier r = device_add_property_aux(device, key, value, true);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalierstatic int device_add_property_internal_from_string(sd_device *device, const char *str) {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier return device_add_property_internal(device, key, value);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalierstatic int handle_db_line(sd_device *device, char key, const char *value) {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier r = safe_atoi(value, &device->devlink_priority);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier r = device_add_property_internal_from_string(device, value);
2de61bbebfe6a1a97709b3277b150cacc30a79cdRonny Chevalier r = safe_atoi(value, &device->watch_handle);
2de61bbebfe6a1a97709b3277b150cacc30a79cdRonny Chevalier r = device_set_usec_initialized(device, value);
2de61bbebfe6a1a97709b3277b150cacc30a79cdRonny Chevalier log_debug("device db: unknown key '%c'", key);
d7aeffea144c2c6bfee4e63131bb2b6c460de678Ronny Chevaliervoid device_set_devlink_priority(sd_device *device, int priority) {
d7aeffea144c2c6bfee4e63131bb2b6c460de678Ronny Chevaliervoid device_set_is_initialized(sd_device *device) {
d7aeffea144c2c6bfee4e63131bb2b6c460de678Ronny Chevalierint device_ensure_usec_initialized(sd_device *device, sd_device *device_old) {
d7aeffea144c2c6bfee4e63131bb2b6c460de678Ronny Chevalier if (device_old && device_old->usec_initialized > 0)
d7aeffea144c2c6bfee4e63131bb2b6c460de678Ronny Chevalier usec_initialized = device_old->usec_initialized;
0805e9a9c87845be9f801efacc0a358da6991190Ronny Chevalier r = snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
0805e9a9c87845be9f801efacc0a358da6991190Ronny Chevalier r = device_set_usec_initialized(device, num);
0805e9a9c87845be9f801efacc0a358da6991190Ronny Chevalierstatic int device_read_db(sd_device *device) {
0805e9a9c87845be9f801efacc0a358da6991190Ronny Chevalier log_debug("sd-device: failed to read db '%s': %s", path, strerror(-r));
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier /* devices with a database entry are initialized */
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier for (i = 0; i < db_len; i++) {
case KEY:
case PRE_VALUE:
case INVALID_LINE:
case VALUE:
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:
const char *id;
char *path;
return -errno;