mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-29 17:33:09 +00:00
Avoid initializing driver if pidfie is claimed. Always claim pidfile as root
This commit is contained in:
parent
1290f50284
commit
8049357ded
@ -1,3 +1,10 @@
|
|||||||
|
Tue May 20 12:15:29 EST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* qemud/qemud.c: Re-factor daemon startup code to avoid
|
||||||
|
initializing the drivers if the pidfile is already claimed
|
||||||
|
by another daemon instance. Always claim pidfile when running
|
||||||
|
as root, even in non-daemon mode
|
||||||
|
|
||||||
Tue May 20 17:53:29 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
Tue May 20 17:53:29 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* docs/remote.html docs/remote.html.in: patch from Kenneth Nagin
|
* docs/remote.html docs/remote.html.in: patch from Kenneth Nagin
|
||||||
|
@ -2143,38 +2143,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pipe(sigpipe) < 0 ||
|
|
||||||
qemudSetNonBlock(sigpipe[0]) < 0 ||
|
|
||||||
qemudSetNonBlock(sigpipe[1]) < 0 ||
|
|
||||||
qemudSetCloseExec(sigpipe[0]) < 0 ||
|
|
||||||
qemudSetCloseExec(sigpipe[1]) < 0) {
|
|
||||||
qemudLog(QEMUD_ERR, _("Failed to create pipe: %s"),
|
|
||||||
strerror(errno));
|
|
||||||
goto error1;
|
|
||||||
}
|
|
||||||
sigwrite = sigpipe[1];
|
|
||||||
|
|
||||||
if (!(server = qemudInitialize(sigpipe[0]))) {
|
|
||||||
ret = 2;
|
|
||||||
goto error1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the config file (if it exists). */
|
|
||||||
if (remoteReadConfigFile (server, remote_config_file) < 0)
|
|
||||||
goto error1;
|
|
||||||
|
|
||||||
/* Change the group ownership of /var/run/libvirt to unix_sock_gid */
|
|
||||||
if (getuid() != 0) {
|
|
||||||
qemudLog (QEMUD_WARN,
|
|
||||||
"%s", _("Cannot set group ownership when not running as root"));
|
|
||||||
} else {
|
|
||||||
const char *sockdirname = LOCAL_STATE_DIR "/run/libvirt";
|
|
||||||
|
|
||||||
if (chown(sockdirname, -1, unix_sock_gid) < 0)
|
|
||||||
qemudLog(QEMUD_ERR, _("Failed to change group ownership of %s"),
|
|
||||||
sockdirname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (godaemon) {
|
if (godaemon) {
|
||||||
openlog("libvirtd", 0, 0);
|
openlog("libvirtd", 0, 0);
|
||||||
if (qemudGoDaemon() < 0) {
|
if (qemudGoDaemon() < 0) {
|
||||||
@ -2182,17 +2150,30 @@ int main(int argc, char **argv) {
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto error1;
|
goto error1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Choose the name of the PID file. */
|
|
||||||
if (!pid_file) {
|
|
||||||
if (REMOTE_PID_FILE[0] != '\0')
|
|
||||||
pid_file = REMOTE_PID_FILE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid_file && qemudWritePidFile (pid_file) < 0)
|
|
||||||
goto error1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If running as root and no PID file is set, use the default */
|
||||||
|
if (pid_file == NULL &&
|
||||||
|
getuid() == 0 &&
|
||||||
|
REMOTE_PID_FILE[0] != '\0')
|
||||||
|
pid_file = REMOTE_PID_FILE;
|
||||||
|
|
||||||
|
/* If we have a pidfile set, claim it now, exiting if already taken */
|
||||||
|
if (pid_file != NULL &&
|
||||||
|
qemudWritePidFile (pid_file) < 0)
|
||||||
|
goto error1;
|
||||||
|
|
||||||
|
if (pipe(sigpipe) < 0 ||
|
||||||
|
qemudSetNonBlock(sigpipe[0]) < 0 ||
|
||||||
|
qemudSetNonBlock(sigpipe[1]) < 0 ||
|
||||||
|
qemudSetCloseExec(sigpipe[0]) < 0 ||
|
||||||
|
qemudSetCloseExec(sigpipe[1]) < 0) {
|
||||||
|
qemudLog(QEMUD_ERR, _("Failed to create pipe: %s"),
|
||||||
|
strerror(errno));
|
||||||
|
goto error2;
|
||||||
|
}
|
||||||
|
sigwrite = sigpipe[1];
|
||||||
|
|
||||||
sig_action.sa_sigaction = sig_handler;
|
sig_action.sa_sigaction = sig_handler;
|
||||||
sig_action.sa_flags = SA_SIGINFO;
|
sig_action.sa_flags = SA_SIGINFO;
|
||||||
sigemptyset(&sig_action.sa_mask);
|
sigemptyset(&sig_action.sa_mask);
|
||||||
@ -2206,6 +2187,24 @@ int main(int argc, char **argv) {
|
|||||||
sig_action.sa_handler = SIG_IGN;
|
sig_action.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGPIPE, &sig_action, NULL);
|
sigaction(SIGPIPE, &sig_action, NULL);
|
||||||
|
|
||||||
|
if (!(server = qemudInitialize(sigpipe[0]))) {
|
||||||
|
ret = 2;
|
||||||
|
goto error2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the config file (if it exists). */
|
||||||
|
if (remoteReadConfigFile (server, remote_config_file) < 0)
|
||||||
|
goto error2;
|
||||||
|
|
||||||
|
/* Change the group ownership of /var/run/libvirt to unix_sock_gid */
|
||||||
|
if (getuid() == 0) {
|
||||||
|
const char *sockdirname = LOCAL_STATE_DIR "/run/libvirt";
|
||||||
|
|
||||||
|
if (chown(sockdirname, -1, unix_sock_gid) < 0)
|
||||||
|
qemudLog(QEMUD_ERR, _("Failed to change group ownership of %s"),
|
||||||
|
sockdirname);
|
||||||
|
}
|
||||||
|
|
||||||
if (virEventAddHandleImpl(sigpipe[0],
|
if (virEventAddHandleImpl(sigpipe[0],
|
||||||
POLLIN,
|
POLLIN,
|
||||||
qemudDispatchSignalEvent,
|
qemudDispatchSignalEvent,
|
||||||
@ -2223,19 +2222,17 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
qemudRunLoop(server);
|
qemudRunLoop(server);
|
||||||
|
|
||||||
close(sigwrite);
|
|
||||||
|
|
||||||
if (godaemon)
|
|
||||||
closelog();
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
error2:
|
error2:
|
||||||
if (godaemon && pid_file)
|
|
||||||
unlink (pid_file);
|
|
||||||
|
|
||||||
error1:
|
|
||||||
if (server)
|
if (server)
|
||||||
qemudCleanup(server);
|
qemudCleanup(server);
|
||||||
|
if (pid_file)
|
||||||
|
unlink (pid_file);
|
||||||
|
close(sigwrite);
|
||||||
|
|
||||||
|
error1:
|
||||||
|
if (godaemon)
|
||||||
|
closelog();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user