summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libudev/libudev-device-private.c2
-rw-r--r--src/libudev/libudev-device.c14
-rw-r--r--src/libudev/libudev-hwdb.c2
-rw-r--r--src/libudev/libudev-private.h9
-rw-r--r--src/libudev/libudev-util.c17
-rw-r--r--src/udev/udev-event.c12
-rw-r--r--src/udev/udev-rules.c6
-rw-r--r--src/udev/udev.h4
-rw-r--r--src/udev/udevadm-settle.c12
-rw-r--r--src/udev/udevd.c16
10 files changed, 38 insertions, 56 deletions
diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c
index 489bea8480..489afe2125 100644
--- a/src/libudev/libudev-device-private.c
+++ b/src/libudev/libudev-device-private.c
@@ -147,7 +147,7 @@ int udev_device_update_db(struct udev_device *udev_device)
}
if (udev_device_get_usec_initialized(udev_device) > 0)
- fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device));
+ fprintf(f, "I:%llu\n", (unsigned long long)udev_device_get_usec_initialized(udev_device));
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
if (!udev_list_entry_get_num(list_entry))
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index 08476e6596..181a9d8eeb 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -67,7 +67,7 @@ struct udev_device {
struct udev_list sysattr_list;
struct udev_list tags_list;
unsigned long long int seqnum;
- unsigned long long int usec_initialized;
+ usec_t usec_initialized;
int devlink_priority;
int refcount;
dev_t devnum;
@@ -246,7 +246,7 @@ static int udev_device_set_devtype(struct udev_device *udev_device, const char *
return 0;
}
-static int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
+int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
{
free(udev_device->subsystem);
udev_device->subsystem = strdup(subsystem);
@@ -1267,7 +1267,7 @@ _public_ const char *udev_device_get_action(struct udev_device *udev_device)
**/
_public_ unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
{
- unsigned long long now_ts;
+ usec_t now_ts;
if (udev_device == NULL)
return 0;
@@ -1275,23 +1275,23 @@ _public_ unsigned long long int udev_device_get_usec_since_initialized(struct ud
udev_device_read_db(udev_device, NULL);
if (udev_device->usec_initialized == 0)
return 0;
- now_ts = now_usec();
+ now_ts = now(CLOCK_MONOTONIC);
if (now_ts == 0)
return 0;
return now_ts - udev_device->usec_initialized;
}
-unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device)
+usec_t udev_device_get_usec_initialized(struct udev_device *udev_device)
{
return udev_device->usec_initialized;
}
-void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
+void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized)
{
char num[32];
udev_device->usec_initialized = usec_initialized;
- snprintf(num, sizeof(num), "%llu", usec_initialized);
+ snprintf(num, sizeof(num), "%llu", (unsigned long long)usec_initialized);
udev_device_add_property(udev_device, "USEC_INITIALIZED", num);
}
diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c
index 8fe24a4320..e72123a3af 100644
--- a/src/libudev/libudev-hwdb.c
+++ b/src/libudev/libudev-hwdb.c
@@ -356,7 +356,7 @@ bool udev_hwdb_validate(struct udev_hwdb *hwdb) {
return false;
if (fstat(fileno(hwdb->f), &st) < 0)
return true;
- if (ts_usec(&hwdb->st.st_mtim) != ts_usec(&st.st_mtim))
+ if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim))
return true;
return false;
}
diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h
index d233565fb8..e3fc9a76f4 100644
--- a/src/libudev/libudev-private.h
+++ b/src/libudev/libudev-private.h
@@ -41,13 +41,14 @@ void udev_log(struct udev *udev,
int priority, const char *file, int line, const char *fn,
const char *format, ...)
__attribute__((format(printf, 6, 7)));
-int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *ts_usec[]);
+int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]);
struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value);
struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);
/* libudev-device.c */
struct udev_device *udev_device_new(struct udev *udev);
mode_t udev_device_get_devnode_mode(struct udev_device *udev_device);
+int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);
int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode);
int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink);
@@ -65,8 +66,8 @@ const char *udev_device_get_id_filename(struct udev_device *udev_device);
void udev_device_set_is_initialized(struct udev_device *udev_device);
int udev_device_add_tag(struct udev_device *udev_device, const char *tag);
void udev_device_cleanup_tags_list(struct udev_device *udev_device);
-unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device);
-void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized);
+usec_t udev_device_get_usec_initialized(struct udev_device *udev_device);
+void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized);
int udev_device_get_devlink_priority(struct udev_device *udev_device);
int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio);
int udev_device_get_watch_handle(struct udev_device *udev_device);
@@ -167,7 +168,5 @@ int util_delete_path(struct udev *udev, const char *path);
uid_t util_lookup_user(struct udev *udev, const char *user);
gid_t util_lookup_group(struct udev *udev, const char *group);
int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value);
-unsigned long long ts_usec(const struct timespec *ts);
-unsigned long long now_usec(void);
ssize_t print_kmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
#endif
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index b1c113046e..b609857eaf 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -691,23 +691,6 @@ uint64_t util_string_bloom64(const char *str)
return bits;
}
-#define USEC_PER_SEC 1000000ULL
-#define NSEC_PER_USEC 1000ULL
-unsigned long long ts_usec(const struct timespec *ts)
-{
- return (unsigned long long) ts->tv_sec * USEC_PER_SEC +
- (unsigned long long) ts->tv_nsec / NSEC_PER_USEC;
-}
-
-unsigned long long now_usec(void)
-{
- struct timespec ts;
-
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
- return 0;
- return ts_usec(&ts);
-}
-
ssize_t print_kmsg(const char *fmt, ...)
{
int fd;
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 2b9fdf6748..11540f7bc1 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -48,7 +48,7 @@ struct udev_event *udev_event_new(struct udev_device *dev)
event->udev = udev;
udev_list_init(udev, &event->run_list, false);
event->fd_signal = -1;
- event->birth_usec = now_usec();
+ event->birth_usec = now(CLOCK_MONOTONIC);
event->timeout_usec = 30 * 1000 * 1000;
return event;
}
@@ -466,9 +466,9 @@ static void spawn_read(struct udev_event *event,
int i;
if (event->timeout_usec > 0) {
- unsigned long long age_usec;
+ usec_t age_usec;
- age_usec = now_usec() - event->birth_usec;
+ age_usec = now(CLOCK_MONOTONIC) - event->birth_usec;
if (age_usec >= event->timeout_usec) {
log_error("timeout '%s'\n", cmd);
goto out;
@@ -554,9 +554,9 @@ static int spawn_wait(struct udev_event *event, const char *cmd, pid_t pid)
int fdcount;
if (event->timeout_usec > 0) {
- unsigned long long age_usec;
+ usec_t age_usec;
- age_usec = now_usec() - event->birth_usec;
+ age_usec = now(CLOCK_MONOTONIC) - event->birth_usec;
if (age_usec >= event->timeout_usec)
timeout = 1000;
else
@@ -860,7 +860,7 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
if (event->dev_db != NULL && udev_device_get_usec_initialized(event->dev_db) > 0)
udev_device_set_usec_initialized(event->dev, udev_device_get_usec_initialized(event->dev_db));
else if (udev_device_get_usec_initialized(event->dev) == 0)
- udev_device_set_usec_initialized(event->dev, now_usec());
+ udev_device_set_usec_initialized(event->dev, now(CLOCK_MONOTONIC));
/* (re)write database file */
udev_device_update_db(dev);
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 6f64bf6055..494ca7b689 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -47,7 +47,7 @@ struct uid_gid {
struct udev_rules {
struct udev *udev;
char **dirs;
- unsigned long long *dirs_ts_usec;
+ usec_t *dirs_ts_usec;
int resolve_names;
/* every key in the rules file becomes a token */
@@ -1691,7 +1691,7 @@ bool udev_rules_check_timestamp(struct udev_rules *rules)
if (stat(rules->dirs[i], &stats) < 0)
continue;
- if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim))
+ if (rules->dirs_ts_usec[i] == timespec_load(&stats.st_mtim))
continue;
/* first check */
@@ -1701,7 +1701,7 @@ bool udev_rules_check_timestamp(struct udev_rules *rules)
}
/* update timestamp */
- rules->dirs_ts_usec[i] = ts_usec(&stats.st_mtim);
+ rules->dirs_ts_usec[i] = timespec_load(&stats.st_mtim);
}
out:
return changed;
diff --git a/src/udev/udev.h b/src/udev/udev.h
index b0bd4d1961..a1dc3ee617 100644
--- a/src/udev/udev.h
+++ b/src/udev/udev.h
@@ -41,8 +41,8 @@ struct udev_event {
gid_t gid;
struct udev_list run_list;
int exec_delay;
- unsigned long long birth_usec;
- unsigned long long timeout_usec;
+ usec_t birth_usec;
+ usec_t timeout_usec;
int fd_signal;
unsigned int builtin_run;
unsigned int builtin_ret;
diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c
index e70b351eb9..c4fc4ee4e5 100644
--- a/src/udev/udevadm-settle.c
+++ b/src/udev/udevadm-settle.c
@@ -47,9 +47,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
{ "help", no_argument, NULL, 'h' },
{}
};
- unsigned long long start_usec = now_usec();
- unsigned long long start = 0;
- unsigned long long end = 0;
+ usec_t start_usec = now(CLOCK_MONOTONIC);
+ usec_t start = 0;
+ usec_t end = 0;
int quiet = 0;
const char *exists = NULL;
unsigned int timeout = 120;
@@ -123,7 +123,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
start = 0;
end = 0;
}
- log_debug("start=%llu end=%llu current=%llu\n", start, end, kernel_seq);
+ log_debug("start=%llu end=%llu current=%llu\n", (unsigned long long)start, (unsigned long long)end, kernel_seq);
} else {
if (end > 0) {
log_error("seq-end needs seq-start parameter, ignoring\n");
@@ -199,9 +199,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
}
if (timeout > 0) {
- unsigned long long age_usec;
+ usec_t age_usec;
- age_usec = now_usec() - start_usec;
+ age_usec = now(CLOCK_MONOTONIC) - start_usec;
if (age_usec / (1000 * 1000) >= timeout) {
struct udev_list_entry *list_entry;
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 9bbc8ec8ad..b69f3f87de 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -122,7 +122,7 @@ struct worker {
struct udev_monitor *monitor;
enum worker_state state;
struct event *event;
- unsigned long long event_start_usec;
+ usec_t event_start_usec;
};
/* passed from worker to main process */
@@ -378,7 +378,7 @@ out:
worker->monitor = worker_monitor;
worker->pid = pid;
worker->state = WORKER_RUNNING;
- worker->event_start_usec = now_usec();
+ worker->event_start_usec = now(CLOCK_MONOTONIC);
worker->event = event;
event->state = EVENT_RUNNING;
udev_list_node_append(&worker->node, &worker_list);
@@ -409,7 +409,7 @@ static void event_run(struct event *event)
worker_ref(worker);
worker->event = event;
worker->state = WORKER_RUNNING;
- worker->event_start_usec = now_usec();
+ worker->event_start_usec = now(CLOCK_MONOTONIC);
event->state = EVENT_RUNNING;
return;
}
@@ -1374,7 +1374,7 @@ int main(int argc, char *argv[])
udev_list_node_init(&worker_list);
for (;;) {
- static unsigned long long last_usec;
+ static usec_t last_usec;
struct epoll_event ev[8];
int fdcount;
int timeout;
@@ -1445,7 +1445,7 @@ int main(int argc, char *argv[])
if (worker->state != WORKER_RUNNING)
continue;
- if ((now_usec() - worker->event_start_usec) > 30 * 1000 * 1000) {
+ if ((now(CLOCK_MONOTONIC) - worker->event_start_usec) > 30 * 1000 * 1000) {
log_error("worker [%u] %s timeout; kill it\n", worker->pid,
worker->event ? worker->event->devpath : "<idle>");
kill(worker->pid, SIGKILL);
@@ -1479,13 +1479,13 @@ int main(int argc, char *argv[])
}
/* check for changed config, every 3 seconds at most */
- if ((now_usec() - last_usec) > 3 * 1000 * 1000) {
+ if ((now(CLOCK_MONOTONIC) - last_usec) > 3 * 1000 * 1000) {
if (udev_rules_check_timestamp(rules))
reload = true;
if (udev_builtin_validate(udev))
reload = true;
- last_usec = now_usec();
+ last_usec = now(CLOCK_MONOTONIC);
}
/* reload requested, HUP signal received, rules changed, builtin changed */
@@ -1505,7 +1505,7 @@ int main(int argc, char *argv[])
dev = udev_monitor_receive_device(monitor);
if (dev != NULL) {
- udev_device_set_usec_initialized(dev, now_usec());
+ udev_device_set_usec_initialized(dev, now(CLOCK_MONOTONIC));
if (event_queue_insert(dev) < 0)
udev_device_unref(dev);
}