mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-31 14:07:16 +00:00
Add support for /run/initctl
Newer versions of Debian use '/run/initctl' instead of '/dev/initctl'. This patch updates the code to search for the FIFO from a list of well-known locations.
This commit is contained in:
parent
966d07b935
commit
7e037f64c0
@ -46,12 +46,6 @@
|
|||||||
* Copyright (C) 1995-2004 Miquel van Smoorenburg
|
* Copyright (C) 1995-2004 Miquel van Smoorenburg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# if defined(__FreeBSD_kernel__)
|
|
||||||
# define VIR_INITCTL_FIFO "/etc/.initctl"
|
|
||||||
# else
|
|
||||||
# define VIR_INITCTL_FIFO "/dev/initctl"
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# define VIR_INITCTL_MAGIC 0x03091969
|
# define VIR_INITCTL_MAGIC 0x03091969
|
||||||
# define VIR_INITCTL_CMD_START 0
|
# define VIR_INITCTL_CMD_START 0
|
||||||
# define VIR_INITCTL_CMD_RUNLVL 1
|
# define VIR_INITCTL_CMD_RUNLVL 1
|
||||||
@ -124,6 +118,13 @@ virInitctlSetRunLevel(virInitctlRunLevel level)
|
|||||||
struct virInitctlRequest req;
|
struct virInitctlRequest req;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
const char *initctl_fifo = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
const char *initctl_fifos[] = {
|
||||||
|
"/run/initctl",
|
||||||
|
"/dev/initctl",
|
||||||
|
"/etc/.initctl",
|
||||||
|
};
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
|
|
||||||
@ -133,22 +134,31 @@ virInitctlSetRunLevel(virInitctlRunLevel level)
|
|||||||
/* Yes it is an 'int' field, but wants a numeric character. Go figure */
|
/* Yes it is an 'int' field, but wants a numeric character. Go figure */
|
||||||
req.runlevel = '0' + level;
|
req.runlevel = '0' + level;
|
||||||
|
|
||||||
if ((fd = open(VIR_INITCTL_FIFO,
|
for (i = 0; i < ARRAY_CARDINALITY(initctl_fifos); i++) {
|
||||||
O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY)) < 0) {
|
initctl_fifo = initctl_fifos[i];
|
||||||
if (errno == ENOENT) {
|
|
||||||
ret = 0;
|
if ((fd = open(initctl_fifo,
|
||||||
|
O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY)) >= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (errno != ENOENT) {
|
||||||
|
virReportSystemError(errno,
|
||||||
|
_("Cannot open init control %s"),
|
||||||
|
initctl_fifo);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
virReportSystemError(errno,
|
}
|
||||||
_("Cannot open init control %s"),
|
|
||||||
VIR_INITCTL_FIFO);
|
/* Ensure we found a valid initctl fifo */
|
||||||
|
if (fd < 0) {
|
||||||
|
ret = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safewrite(fd, &req, sizeof(req)) != sizeof(req)) {
|
if (safewrite(fd, &req, sizeof(req)) != sizeof(req)) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to send request to init control %s"),
|
_("Failed to send request to init control %s"),
|
||||||
VIR_INITCTL_FIFO);
|
initctl_fifo);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user