mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 01:55:22 +03:00
udevadm: use parse_sec instead of atoi for timeout option (#4331)
log_error method is used instead of fprintf
This commit is contained in:
parent
ec72b96366
commit
1f1a5e8b40
@ -20,6 +20,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "time-util.h"
|
||||||
#include "udev-util.h"
|
#include "udev-util.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (getuid() != 0) {
|
if (getuid() != 0) {
|
||||||
fprintf(stderr, "root privileges required\n");
|
log_error("root privileges required");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
|||||||
|
|
||||||
i = util_log_priority(optarg);
|
i = util_log_priority(optarg);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
fprintf(stderr, "invalid number '%s'\n", optarg);
|
log_error("invalid number '%s'", optarg);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
if (udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg), timeout) < 0)
|
if (udev_ctrl_send_set_log_level(uctrl, util_log_priority(optarg), timeout) < 0)
|
||||||
@ -110,7 +111,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (strchr(optarg, '=') == NULL) {
|
if (strchr(optarg, '=') == NULL) {
|
||||||
fprintf(stderr, "expect <KEY>=<value> instead of '%s'\n", optarg);
|
log_error("expect <KEY>=<value> instead of '%s'", optarg);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
if (udev_ctrl_send_set_env(uctrl, optarg, timeout) < 0)
|
if (udev_ctrl_send_set_env(uctrl, optarg, timeout) < 0)
|
||||||
@ -124,7 +125,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
|||||||
|
|
||||||
i = strtoul(optarg, &endp, 0);
|
i = strtoul(optarg, &endp, 0);
|
||||||
if (endp[0] != '\0' || i < 1) {
|
if (endp[0] != '\0' || i < 1) {
|
||||||
fprintf(stderr, "invalid number '%s'\n", optarg);
|
log_error("invalid number '%s'", optarg);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
if (udev_ctrl_send_set_children_max(uctrl, i, timeout) < 0)
|
if (udev_ctrl_send_set_children_max(uctrl, i, timeout) < 0)
|
||||||
@ -134,13 +135,21 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 't': {
|
case 't': {
|
||||||
|
usec_t s;
|
||||||
int seconds;
|
int seconds;
|
||||||
|
int r;
|
||||||
|
|
||||||
seconds = atoi(optarg);
|
r = parse_sec(optarg, &s);
|
||||||
if (seconds >= 0)
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to parse timeout value '%s'.", optarg);
|
||||||
|
|
||||||
|
if (((s + USEC_PER_SEC - 1) / USEC_PER_SEC) > INT_MAX)
|
||||||
|
log_error("Timeout value is out of range.");
|
||||||
|
else {
|
||||||
|
seconds = s != USEC_INFINITY ? (int) ((s + USEC_PER_SEC - 1) / USEC_PER_SEC) : INT_MAX;
|
||||||
timeout = seconds;
|
timeout = seconds;
|
||||||
else
|
rc = 0;
|
||||||
fprintf(stderr, "invalid timeout value\n");
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -150,9 +159,9 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
fprintf(stderr, "Extraneous argument: %s\n", argv[optind]);
|
log_error("Extraneous argument: %s", argv[optind]);
|
||||||
else if (optind == 1)
|
else if (optind == 1)
|
||||||
fprintf(stderr, "Option missing\n");
|
log_error("Option missing");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user