mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
Fri Feb 23 12:46:44 IST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/qemud.c: add --pid-file and default to writing out a PID file to /var/run/libvirt_qemud.pid in daemon mode. * configure.in: add --with-pid-file arg
This commit is contained in:
parent
cf0e5df048
commit
d758313d67
@ -1,3 +1,11 @@
|
|||||||
|
Fri Feb 23 12:46:44 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||||
|
|
||||||
|
* qemud/qemud.c: add --pid-file and default to writing
|
||||||
|
out a PID file to /var/run/libvirt_qemud.pid in daemon
|
||||||
|
mode.
|
||||||
|
|
||||||
|
* configure.in: add --with-pid-file arg
|
||||||
|
|
||||||
Fri Feb 23 12:45:08 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
Fri Feb 23 12:45:08 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||||
|
|
||||||
* qemud/Makefile.am: install libvirt_qemud in /usr/sbin
|
* qemud/Makefile.am: install libvirt_qemud in /usr/sbin
|
||||||
|
15
configure.in
15
configure.in
@ -86,6 +86,21 @@ if test x"$enable_debug" = x"yes"; then
|
|||||||
AC_DEFINE(ENABLE_DEBUG, [], [whether debugging is enabled])
|
AC_DEFINE(ENABLE_DEBUG, [], [whether debugging is enabled])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dnl
|
||||||
|
dnl PID file
|
||||||
|
dnl
|
||||||
|
AC_MSG_CHECKING([where to write libvirt_qemud PID file])
|
||||||
|
AC_ARG_WITH(pid-file, AC_HELP_STRING([--with-qemud-pid-file=[pidfile|none]], [PID file for libvirt_qemud]))
|
||||||
|
if test "x$with_qemud_pid_file" == "x" ; then
|
||||||
|
QEMUD_PID_FILE="$localstatedir/run/libvirt_qemud.pid"
|
||||||
|
elif test "x$with_qemud_pid_file" == "xnone" ; then
|
||||||
|
QEMUD_PID_FILE=""
|
||||||
|
else
|
||||||
|
QEMUD_PID_FILE="$with_qemud_pid_file"
|
||||||
|
fi
|
||||||
|
AC_DEFINE_UNQUOTED(QEMUD_PID_FILE, "$QEMUD_PID_FILE", [PID file path for qemud])
|
||||||
|
AC_MSG_RESULT($QEMUD_PID_FILE)
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl allow the creation of iptables rules in chains with a
|
dnl allow the creation of iptables rules in chains with a
|
||||||
dnl specific prefix rather than in the standard toplevel chains
|
dnl specific prefix rather than in the standard toplevel chains
|
||||||
|
@ -301,6 +301,42 @@ static int qemudGoDaemon(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int qemudWritePidFile(const char *pidFile) {
|
||||||
|
int fd;
|
||||||
|
FILE *fh;
|
||||||
|
|
||||||
|
if (pidFile[0] == '\0')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ((fd = open(pidFile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
|
||||||
|
qemudLog(QEMUD_ERR, "Failed to open pid file '%s' : %s",
|
||||||
|
pidFile, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(fh = fdopen(fd, "w"))) {
|
||||||
|
qemudLog(QEMUD_ERR, "Failed to fdopen pid file '%s' : %s",
|
||||||
|
pidFile, strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
|
||||||
|
qemudLog(QEMUD_ERR, "Failed to write to pid file '%s' : %s",
|
||||||
|
pidFile, strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fclose(fh) == EOF) {
|
||||||
|
qemudLog(QEMUD_ERR, "Failed to close pid file '%s' : %s",
|
||||||
|
pidFile, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int qemudListenUnix(struct qemud_server *server,
|
static int qemudListenUnix(struct qemud_server *server,
|
||||||
const char *path, int readonly) {
|
const char *path, int readonly) {
|
||||||
struct qemud_socket *sock = calloc(1, sizeof(struct qemud_socket));
|
struct qemud_socket *sock = calloc(1, sizeof(struct qemud_socket));
|
||||||
@ -1483,12 +1519,15 @@ int main(int argc, char **argv) {
|
|||||||
struct qemud_server *server;
|
struct qemud_server *server;
|
||||||
struct sigaction sig_action;
|
struct sigaction sig_action;
|
||||||
int sigpipe[2];
|
int sigpipe[2];
|
||||||
|
char *pid_file = NULL;
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
struct option opts[] = {
|
struct option opts[] = {
|
||||||
{ "verbose", no_argument, &verbose, 1},
|
{ "verbose", no_argument, &verbose, 1},
|
||||||
{ "daemon", no_argument, &godaemon, 1},
|
{ "daemon", no_argument, &godaemon, 1},
|
||||||
{ "system", no_argument, &sys, 1},
|
{ "system", no_argument, &sys, 1},
|
||||||
{ "timeout", required_argument, 0, 't'},
|
{ "timeout", required_argument, 0, 't'},
|
||||||
|
{ "pid-file", required_argument, 0, 'p'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1497,7 +1536,7 @@ int main(int argc, char **argv) {
|
|||||||
int c;
|
int c;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "vsdt:", opts, &optidx);
|
c = getopt_long(argc, argv, "vsdt:p:", opts, &optidx);
|
||||||
|
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -1524,6 +1563,11 @@ int main(int argc, char **argv) {
|
|||||||
if (timeout <= 0)
|
if (timeout <= 0)
|
||||||
timeout = -1;
|
timeout = -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
pid_file = strdup(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return 2;
|
return 2;
|
||||||
break;
|
break;
|
||||||
@ -1541,7 +1585,7 @@ int main(int argc, char **argv) {
|
|||||||
qemudSetNonBlock(sigpipe[1]) < 0) {
|
qemudSetNonBlock(sigpipe[1]) < 0) {
|
||||||
qemudLog(QEMUD_ERR, "Failed to create pipe: %s",
|
qemudLog(QEMUD_ERR, "Failed to create pipe: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 1;
|
goto error1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sigwrite = sigpipe[1];
|
sigwrite = sigpipe[1];
|
||||||
@ -1564,14 +1608,19 @@ int main(int argc, char **argv) {
|
|||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
qemudLog(QEMUD_ERR, "Failed to fork as daemon: %s",
|
qemudLog(QEMUD_ERR, "Failed to fork as daemon: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 1;
|
goto error1;
|
||||||
}
|
}
|
||||||
if (pid > 0)
|
if (pid > 0)
|
||||||
return 0;
|
goto out;
|
||||||
|
|
||||||
|
if (qemudWritePidFile(pid_file ? pid_file : QEMUD_PID_FILE) < 0)
|
||||||
|
goto error1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(server = qemudInitialize(sys, sigpipe[0])))
|
if (!(server = qemudInitialize(sys, sigpipe[0]))) {
|
||||||
return 2;
|
ret = 2;
|
||||||
|
goto error2;
|
||||||
|
}
|
||||||
|
|
||||||
qemudRunLoop(server, timeout);
|
qemudRunLoop(server, timeout);
|
||||||
|
|
||||||
@ -1582,7 +1631,18 @@ int main(int argc, char **argv) {
|
|||||||
if (godaemon)
|
if (godaemon)
|
||||||
closelog();
|
closelog();
|
||||||
|
|
||||||
return 0;
|
out:
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
error2:
|
||||||
|
if (godaemon)
|
||||||
|
unlink(pid_file ? pid_file : QEMUD_PID_FILE);
|
||||||
|
|
||||||
|
error1:
|
||||||
|
if (pid_file)
|
||||||
|
free(pid_file);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user