mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
udev: use usec_t for timeout in udev_ctrl_send_*()
This commit is contained in:
parent
b1d1cb5b47
commit
3797776e11
@ -213,7 +213,7 @@ static struct udev_ctrl_connection *udev_ctrl_connection_free(struct udev_ctrl_c
|
|||||||
|
|
||||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(struct udev_ctrl_connection, udev_ctrl_connection, udev_ctrl_connection_free);
|
DEFINE_TRIVIAL_REF_UNREF_FUNC(struct udev_ctrl_connection, udev_ctrl_connection, udev_ctrl_connection_free);
|
||||||
|
|
||||||
static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, int timeout) {
|
static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, usec_t timeout) {
|
||||||
struct udev_ctrl_msg_wire ctrl_msg_wire = {
|
struct udev_ctrl_msg_wire ctrl_msg_wire = {
|
||||||
.version = "udev-" STRINGIFY(PROJECT_VERSION),
|
.version = "udev-" STRINGIFY(PROJECT_VERSION),
|
||||||
.magic = UDEV_CTRL_MAGIC,
|
.magic = UDEV_CTRL_MAGIC,
|
||||||
@ -241,7 +241,7 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int
|
|||||||
};
|
};
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = poll(&pfd, 1, timeout * MSEC_PER_SEC);
|
r = poll(&pfd, 1, DIV_ROUND_UP(timeout, USEC_PER_MSEC));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
@ -255,35 +255,35 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout) {
|
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, priority, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, priority, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout) {
|
int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, 0, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, 0, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout) {
|
int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout) {
|
int udev_ctrl_send_reload(struct udev_ctrl *uctrl, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout) {
|
int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_SET_ENV, 0, key, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_SET_ENV, 0, key, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, int timeout) {
|
int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, count, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, count, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout) {
|
int udev_ctrl_send_ping(struct udev_ctrl *uctrl, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_PING, 0, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_PING, 0, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout) {
|
int udev_ctrl_send_exit(struct udev_ctrl *uctrl, usec_t timeout) {
|
||||||
return ctrl_send(uctrl, UDEV_CTRL_EXIT, 0, NULL, timeout);
|
return ctrl_send(uctrl, UDEV_CTRL_EXIT, 0, NULL, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
#include "time-util.h"
|
||||||
|
|
||||||
struct udev_ctrl;
|
struct udev_ctrl;
|
||||||
struct udev_ctrl *udev_ctrl_new(void);
|
struct udev_ctrl *udev_ctrl_new(void);
|
||||||
@ -10,14 +11,14 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl);
|
|||||||
struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl);
|
struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl);
|
||||||
int udev_ctrl_cleanup(struct udev_ctrl *uctrl);
|
int udev_ctrl_cleanup(struct udev_ctrl *uctrl);
|
||||||
int udev_ctrl_get_fd(struct udev_ctrl *uctrl);
|
int udev_ctrl_get_fd(struct udev_ctrl *uctrl);
|
||||||
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout);
|
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, usec_t timeout);
|
||||||
int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout);
|
int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, usec_t timeout);
|
||||||
int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout);
|
int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, usec_t timeout);
|
||||||
int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout);
|
int udev_ctrl_send_reload(struct udev_ctrl *uctrl, usec_t timeout);
|
||||||
int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout);
|
int udev_ctrl_send_ping(struct udev_ctrl *uctrl, usec_t timeout);
|
||||||
int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout);
|
int udev_ctrl_send_exit(struct udev_ctrl *uctrl, usec_t timeout);
|
||||||
int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout);
|
int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, usec_t timeout);
|
||||||
int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, int timeout);
|
int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, usec_t timeout);
|
||||||
|
|
||||||
struct udev_ctrl_connection;
|
struct udev_ctrl_connection;
|
||||||
struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl);
|
struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl);
|
||||||
|
@ -48,7 +48,7 @@ static int help(void) {
|
|||||||
|
|
||||||
int control_main(int argc, char *argv[], void *userdata) {
|
int control_main(int argc, char *argv[], void *userdata) {
|
||||||
_cleanup_(udev_ctrl_unrefp) struct udev_ctrl *uctrl = NULL;
|
_cleanup_(udev_ctrl_unrefp) struct udev_ctrl *uctrl = NULL;
|
||||||
int timeout = 60;
|
usec_t timeout = 60 * USEC_PER_SEC;
|
||||||
int c, r;
|
int c, r;
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
@ -135,19 +135,11 @@ int control_main(int argc, char *argv[], void *userdata) {
|
|||||||
return r;
|
return r;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 't': {
|
case 't':
|
||||||
usec_t s;
|
r = parse_sec(optarg, &timeout);
|
||||||
|
|
||||||
r = parse_sec(optarg, &s);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to parse timeout value '%s'.", optarg);
|
return log_error_errno(r, "Failed to parse timeout value '%s': %m", optarg);
|
||||||
|
|
||||||
if (DIV_ROUND_UP(s, USEC_PER_SEC) > INT_MAX)
|
|
||||||
log_error("Timeout value is out of range, ignoring.");
|
|
||||||
else
|
|
||||||
timeout = s != USEC_INFINITY ? (int) DIV_ROUND_UP(s, USEC_PER_SEC) : INT_MAX;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case 'V':
|
case 'V':
|
||||||
return print_version();
|
return print_version();
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -102,9 +102,9 @@ int settle_main(int argc, char *argv[], void *userdata) {
|
|||||||
|
|
||||||
uctrl = udev_ctrl_new();
|
uctrl = udev_ctrl_new();
|
||||||
if (uctrl) {
|
if (uctrl) {
|
||||||
r = udev_ctrl_send_ping(uctrl, MAX(5U, arg_timeout / USEC_PER_SEC));
|
r = udev_ctrl_send_ping(uctrl, MAX(5 * USEC_PER_SEC, arg_timeout));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_debug_errno(r, "Failed to connect to udev daemon.");
|
log_debug_errno(r, "Failed to connect to udev daemon: %m");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user