/*
- * Copyright (C) 2004-2012 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
* Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
* Copyright (C) 2009 Canonical Ltd.
* Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
#include "sd-daemon.h"
#include "cgroup-util.h"
#include "dev-setup.h"
+#include "fileio.h"
static bool debug;
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 */
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);
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;
}
return true;
/* check our old name */
- if (event->devpath_old != NULL && strcmp(loop_event->devpath, event->devpath_old) == 0) {
+ if (event->devpath_old != NULL && streq(loop_event->devpath, event->devpath_old)) {
event->delaying_seqnum = loop_event->seqnum;
return true;
}
int fd;
log_debug("device %s closed, synthesising 'change'\n", udev_device_get_devnode(dev));
- util_strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL);
+ strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL);
fd = open(filename, O_WRONLY);
if (fd >= 0) {
if (write(fd, "change", 6) < 0)
FILE *f;
uname(&kernel);
- util_strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL);
+ strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL);
f = fopen(modules, "re");
if (f == NULL)
return;
else
continue;
- util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL);
+ strscpyl(filename, sizeof(filename), "/dev/", devname, NULL);
mkdir_parents_label(filename, 0755);
label_context_set(filename, mode);
log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min);
mkdir_p("/run/udev/data", 0755);
/* old database */
- util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL);
+ strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL);
if (access(filename, F_OK) < 0)
return 0;
/* find database in old location */
id = udev_device_get_id_filename(device);
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL);
+ strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);
}
/* find old database with $subsys:$sysname name */
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/",
+ strscpyl(from, sizeof(from), "/dev/.udev/db/",
udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
/* find old database with the encoded devpath name */
util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath));
- util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL);
+ strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL);
if (lstat(from, &stats) == 0) {
if (!have_db) {
udev_device_read_db(device, from);
for (;;) {
int option;
- option = getopt_long(argc, argv, "c:deDtN:hV", options, NULL);
+ option = getopt_long(argc, argv, "c:de:DtN:hV", options, NULL);
if (option == -1)
break;
udev_set_log_priority(udev, LOG_DEBUG);
break;
case 'N':
- if (strcmp (optarg, "early") == 0) {
+ if (streq(optarg, "early")) {
resolve_names = 1;
- } else if (strcmp (optarg, "late") == 0) {
+ } else if (streq(optarg, "late")) {
resolve_names = 0;
- } else if (strcmp (optarg, "never") == 0) {
+ } else if (streq(optarg, "never")) {
resolve_names = -1;
} else {
fprintf(stderr, "resolve-names must be early, late or never\n");
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;
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);
}
/* 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 */
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);
}