]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemctl/sysv-compat.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "parse-util.h"
12 #include "sysv-compat.h"
15 int talk_initctl(char rl
) {
16 struct init_request request
;
17 _cleanup_close_
int fd
= -1;
21 /* Try to switch to the specified SysV runlevel. Returns == 0 if the operation does not apply on this
22 * system, and > 0 on success. */
27 FOREACH_STRING(p
, "/run/initctl", "/dev/initctl") {
28 fd
= open(p
, O_WRONLY
|O_NONBLOCK
|O_CLOEXEC
|O_NOCTTY
);
29 if (fd
>= 0 || errno
!= ENOENT
)
36 return log_error_errno(errno
, "Failed to open initctl fifo: %m");
39 request
= (struct init_request
) {
42 .cmd
= INIT_CMD_RUNLVL
,
46 r
= loop_write(fd
, &request
, sizeof(request
), false);
48 return log_error_errno(r
, "Failed to write to %s: %m", p
);
54 int parse_shutdown_time_spec(const char *t
, usec_t
*ret
) {
60 else if (!strchr(t
, ':')) {
63 if (safe_atou64(t
, &u
) < 0)
66 *ret
= now(CLOCK_REALTIME
) + USEC_PER_MINUTE
* u
;
75 hour
= strtol(t
, &e
, 10);
76 if (errno
> 0 || *e
!= ':' || hour
< 0 || hour
> 23)
79 minute
= strtol(e
+1, &e
, 10);
80 if (errno
> 0 || *e
!= 0 || minute
< 0 || minute
> 59)
83 n
= now(CLOCK_REALTIME
);
84 s
= (time_t) (n
/ USEC_PER_SEC
);
86 assert_se(localtime_r(&s
, &tm
));
88 tm
.tm_hour
= (int) hour
;
89 tm
.tm_min
= (int) minute
;
95 *ret
= (usec_t
) s
* USEC_PER_SEC
;