1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

sd-device: pass timestamp internally as usec_t not char*

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-12-14 11:33:17 +01:00
parent ebcc52fad6
commit dc5042c0a3
3 changed files with 29 additions and 28 deletions

View File

@ -5,6 +5,7 @@
#include "hashmap.h"
#include "set.h"
#include "time-util.h"
struct sd_device {
unsigned n_ref;
@ -106,7 +107,7 @@ int device_set_devtype(sd_device *device, const char *_devtype);
int device_set_devnum(sd_device *device, const char *major, const char *minor);
int device_set_subsystem(sd_device *device, const char *_subsystem);
int device_set_driver(sd_device *device, const char *_driver);
int device_set_usec_initialized(sd_device *device, const char *initialized);
int device_set_usec_initialized(sd_device *device, usec_t when);
DeviceAction device_action_from_string(const char *s) _pure_;
const char *device_action_to_string(DeviceAction a) _const_;

View File

@ -60,26 +60,16 @@ void device_set_is_initialized(sd_device *device) {
}
int device_ensure_usec_initialized(sd_device *device, sd_device *device_old) {
char num[DECIMAL_STR_MAX(usec_t)];
usec_t usec_initialized;
int r;
usec_t when;
assert(device);
if (device_old && device_old->usec_initialized > 0)
usec_initialized = device_old->usec_initialized;
when = device_old->usec_initialized;
else
usec_initialized = now(CLOCK_MONOTONIC);
when = now(CLOCK_MONOTONIC);
r = snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
if (r < 0)
return -errno;
r = device_set_usec_initialized(device, num);
if (r < 0)
return r;
return 0;
return device_set_usec_initialized(device, when);
}
uint64_t device_get_properties_generation(sd_device *device) {
@ -223,7 +213,13 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to set devname to '%s': %m", value);
} else if (streq(key, "USEC_INITIALIZED")) {
r = device_set_usec_initialized(device, value);
usec_t t;
r = safe_atou64(value, &t);
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to parse timestamp '%s': %m", value);
r = device_set_usec_initialized(device, t);
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to set usec-initialized to '%s': %m", value);
} else if (streq(key, "DRIVER")) {

View File

@ -22,6 +22,7 @@
#include "set.h"
#include "socket-util.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "strxcpyx.h"
@ -1149,23 +1150,19 @@ static int device_add_property_internal_from_string(sd_device *device, const cha
return device_add_property_internal(device, key, value);
}
int device_set_usec_initialized(sd_device *device, const char *initialized) {
uint64_t usec_initialized;
int device_set_usec_initialized(sd_device *device, usec_t when) {
char s[DECIMAL_STR_MAX(usec_t)];
int r;
assert(device);
assert(initialized);
r = safe_atou64(initialized, &usec_initialized);
xsprintf(s, USEC_FMT, when);
r = device_add_property_internal(device, "USEC_INITIALIZED", s);
if (r < 0)
return r;
r = device_add_property_internal(device, "USEC_INITIALIZED", initialized);
if (r < 0)
return r;
device->usec_initialized = usec_initialized;
device->usec_initialized = when;
return 0;
}
@ -1196,12 +1193,19 @@ static int handle_db_line(sd_device *device, char key, const char *value) {
return r;
break;
case 'I':
r = device_set_usec_initialized(device, value);
case 'I': {
usec_t t;
r = safe_atou64(value, &t);
if (r < 0)
return r;
r = device_set_usec_initialized(device, t);
if (r < 0)
return r;
break;
}
case 'L':
r = safe_atoi(value, &device->devlink_priority);
if (r < 0)