qemud.c: use virStrerror, not strerror
This commit is contained in:
parent
1e31bfb055
commit
d2758fa13e
@ -1,3 +1,7 @@
|
|||||||
|
Thu Feb 5 17:03:35 +0100 2009 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
|
qemud.c: use virStrerror, not strerror
|
||||||
|
|
||||||
Thu Feb 5 17:03:35 +0100 2009 Jim Meyering <meyering@redhat.com>
|
Thu Feb 5 17:03:35 +0100 2009 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
iptables.c: Use virStrerror, not strerror.
|
iptables.c: Use virStrerror, not strerror.
|
||||||
|
@ -231,8 +231,9 @@ remoteCheckCertFile(const char *type, const char *file)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(file, &sb) < 0) {
|
if (stat(file, &sb) < 0) {
|
||||||
VIR_ERROR(_("Cannot access %s '%s': %s (%d)"),
|
char ebuf[1024];
|
||||||
type, file, strerror(errno), errno);
|
VIR_ERROR(_("Cannot access %s '%s': %s"),
|
||||||
|
type, file, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -331,7 +332,9 @@ qemudDispatchSignalEvent(int watch ATTRIBUTE_UNUSED,
|
|||||||
virMutexLock(&server->lock);
|
virMutexLock(&server->lock);
|
||||||
|
|
||||||
if (saferead(server->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
|
if (saferead(server->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
|
||||||
VIR_ERROR(_("Failed to read from signal pipe: %s"), strerror(errno));
|
char ebuf[1024];
|
||||||
|
VIR_ERROR(_("Failed to read from signal pipe: %s"),
|
||||||
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
virMutexUnlock(&server->lock);
|
virMutexUnlock(&server->lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -459,33 +462,34 @@ static int qemudGoDaemon(void) {
|
|||||||
static int qemudWritePidFile(const char *pidFile) {
|
static int qemudWritePidFile(const char *pidFile) {
|
||||||
int fd;
|
int fd;
|
||||||
FILE *fh;
|
FILE *fh;
|
||||||
|
char ebuf[1024];
|
||||||
|
|
||||||
if (pidFile[0] == '\0')
|
if (pidFile[0] == '\0')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((fd = open(pidFile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
|
if ((fd = open(pidFile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
|
||||||
VIR_ERROR(_("Failed to open pid file '%s' : %s"),
|
VIR_ERROR(_("Failed to open pid file '%s' : %s"),
|
||||||
pidFile, strerror(errno));
|
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(fh = fdopen(fd, "w"))) {
|
if (!(fh = fdopen(fd, "w"))) {
|
||||||
VIR_ERROR(_("Failed to fdopen pid file '%s' : %s"),
|
VIR_ERROR(_("Failed to fdopen pid file '%s' : %s"),
|
||||||
pidFile, strerror(errno));
|
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
|
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
|
||||||
VIR_ERROR(_("Failed to write to pid file '%s' : %s"),
|
VIR_ERROR(_("Failed to write to pid file '%s' : %s"),
|
||||||
pidFile, strerror(errno));
|
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(fh) == EOF) {
|
if (fclose(fh) == EOF) {
|
||||||
VIR_ERROR(_("Failed to close pid file '%s' : %s"),
|
VIR_ERROR(_("Failed to close pid file '%s' : %s"),
|
||||||
pidFile, strerror(errno));
|
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,6 +502,7 @@ static int qemudListenUnix(struct qemud_server *server,
|
|||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
mode_t oldmask;
|
mode_t oldmask;
|
||||||
gid_t oldgrp;
|
gid_t oldgrp;
|
||||||
|
char ebuf[1024];
|
||||||
|
|
||||||
if (VIR_ALLOC(sock) < 0) {
|
if (VIR_ALLOC(sock) < 0) {
|
||||||
VIR_ERROR("%s", _("Failed to allocate memory for struct qemud_socket"));
|
VIR_ERROR("%s", _("Failed to allocate memory for struct qemud_socket"));
|
||||||
@ -511,7 +516,7 @@ static int qemudListenUnix(struct qemud_server *server,
|
|||||||
|
|
||||||
if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||||
VIR_ERROR(_("Failed to create socket: %s"),
|
VIR_ERROR(_("Failed to create socket: %s"),
|
||||||
strerror(errno));
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +538,7 @@ static int qemudListenUnix(struct qemud_server *server,
|
|||||||
|
|
||||||
if (bind(sock->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(sock->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
VIR_ERROR(_("Failed to bind socket to '%s': %s"),
|
VIR_ERROR(_("Failed to bind socket to '%s': %s"),
|
||||||
path, strerror(errno));
|
path, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
umask(oldmask);
|
umask(oldmask);
|
||||||
@ -542,7 +547,7 @@ static int qemudListenUnix(struct qemud_server *server,
|
|||||||
|
|
||||||
if (listen(sock->fd, 30) < 0) {
|
if (listen(sock->fd, 30) < 0) {
|
||||||
VIR_ERROR(_("Failed to listen for connections on '%s': %s"),
|
VIR_ERROR(_("Failed to listen for connections on '%s': %s"),
|
||||||
path, strerror(errno));
|
path, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,10 +592,11 @@ remoteMakeSockets (int *fds, int max_fds, int *nfds_r, const char *node, const c
|
|||||||
|
|
||||||
struct addrinfo *runp = ai;
|
struct addrinfo *runp = ai;
|
||||||
while (runp && *nfds_r < max_fds) {
|
while (runp && *nfds_r < max_fds) {
|
||||||
|
char ebuf[1024];
|
||||||
fds[*nfds_r] = socket (runp->ai_family, runp->ai_socktype,
|
fds[*nfds_r] = socket (runp->ai_family, runp->ai_socktype,
|
||||||
runp->ai_protocol);
|
runp->ai_protocol);
|
||||||
if (fds[*nfds_r] == -1) {
|
if (fds[*nfds_r] == -1) {
|
||||||
VIR_ERROR(_("socket: %s"), strerror (errno));
|
VIR_ERROR(_("socket: %s"), virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,14 +605,15 @@ remoteMakeSockets (int *fds, int max_fds, int *nfds_r, const char *node, const c
|
|||||||
|
|
||||||
if (bind (fds[*nfds_r], runp->ai_addr, runp->ai_addrlen) == -1) {
|
if (bind (fds[*nfds_r], runp->ai_addr, runp->ai_addrlen) == -1) {
|
||||||
if (errno != EADDRINUSE) {
|
if (errno != EADDRINUSE) {
|
||||||
VIR_ERROR(_("bind: %s"), strerror (errno));
|
VIR_ERROR(_("bind: %s"), virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close (fds[*nfds_r]);
|
close (fds[*nfds_r]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (listen (fds[*nfds_r], SOMAXCONN) == -1) {
|
if (listen (fds[*nfds_r], SOMAXCONN) == -1) {
|
||||||
VIR_ERROR(_("listen: %s"), strerror (errno));
|
VIR_ERROR(_("listen: %s"),
|
||||||
|
virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
++*nfds_r;
|
++*nfds_r;
|
||||||
@ -638,10 +645,12 @@ remoteListenTCP (struct qemud_server *server,
|
|||||||
|
|
||||||
for (i = 0; i < nfds; ++i) {
|
for (i = 0; i < nfds; ++i) {
|
||||||
struct sockaddr_storage sa;
|
struct sockaddr_storage sa;
|
||||||
|
char ebuf[1024];
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
|
|
||||||
if (VIR_ALLOC(sock) < 0) {
|
if (VIR_ALLOC(sock) < 0) {
|
||||||
VIR_ERROR(_("remoteListenTCP: calloc: %s"), strerror (errno));
|
VIR_ERROR(_("remoteListenTCP: calloc: %s"),
|
||||||
|
virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,7 +680,8 @@ remoteListenTCP (struct qemud_server *server,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (listen (sock->fd, 30) < 0) {
|
if (listen (sock->fd, 30) < 0) {
|
||||||
VIR_ERROR(_("remoteListenTCP: listen: %s"), strerror (errno));
|
VIR_ERROR(_("remoteListenTCP: listen: %s"),
|
||||||
|
virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1145,8 +1155,9 @@ int qemudGetSocketIdentity(int fd, uid_t *uid, pid_t *pid) {
|
|||||||
unsigned int cr_len = sizeof (cr);
|
unsigned int cr_len = sizeof (cr);
|
||||||
|
|
||||||
if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) < 0) {
|
if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) < 0) {
|
||||||
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to verify client credentials: %s"),
|
VIR_ERROR(_("Failed to verify client credentials: %s"),
|
||||||
strerror(errno));
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1169,9 +1180,11 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
|
|||||||
int no_slow_start = 1;
|
int no_slow_start = 1;
|
||||||
|
|
||||||
if ((fd = accept(sock->fd, (struct sockaddr *)&addr, &addrlen)) < 0) {
|
if ((fd = accept(sock->fd, (struct sockaddr *)&addr, &addrlen)) < 0) {
|
||||||
|
char ebuf[1024];
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN)
|
||||||
return 0;
|
return 0;
|
||||||
VIR_ERROR(_("Failed to accept connection: %s"), strerror(errno));
|
VIR_ERROR(_("Failed to accept connection: %s"),
|
||||||
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1476,13 +1489,15 @@ static ssize_t qemudClientReadBuf(struct qemud_client *client,
|
|||||||
/*qemudDebug ("qemudClientRead: len = %d", len);*/
|
/*qemudDebug ("qemudClientRead: len = %d", len);*/
|
||||||
|
|
||||||
if (!client->tlssession) {
|
if (!client->tlssession) {
|
||||||
|
char ebuf[1024];
|
||||||
ret = read (client->fd, data, len);
|
ret = read (client->fd, data, len);
|
||||||
if (ret == -1 && (errno == EAGAIN ||
|
if (ret == -1 && (errno == EAGAIN ||
|
||||||
errno == EINTR))
|
errno == EINTR))
|
||||||
return 0;
|
return 0;
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
VIR_ERROR(_("read: %s"), strerror (errno));
|
VIR_ERROR(_("read: %s"),
|
||||||
|
virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
qemudDispatchClientFailure(client);
|
qemudDispatchClientFailure(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1700,10 +1715,11 @@ static ssize_t qemudClientWriteBuf(struct qemud_client *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!client->tlssession) {
|
if (!client->tlssession) {
|
||||||
|
char ebuf[1024];
|
||||||
if ((ret = write(client->fd, data, len)) == -1) {
|
if ((ret = write(client->fd, data, len)) == -1) {
|
||||||
if (errno == EAGAIN || errno == EINTR)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
return 0;
|
return 0;
|
||||||
VIR_ERROR(_("write: %s"), strerror (errno));
|
VIR_ERROR(_("write: %s"), virStrerror (errno, ebuf, sizeof ebuf));
|
||||||
qemudDispatchClientFailure(client);
|
qemudDispatchClientFailure(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2004,9 +2020,10 @@ static int qemudOneLoop(void) {
|
|||||||
/* Check for any signal handling errors and log them. */
|
/* Check for any signal handling errors and log them. */
|
||||||
errors = sig_errors;
|
errors = sig_errors;
|
||||||
if (errors) {
|
if (errors) {
|
||||||
|
char ebuf[1024];
|
||||||
sig_errors -= errors;
|
sig_errors -= errors;
|
||||||
VIR_ERROR(_("Signal handler reported %d errors: last error: %s"),
|
VIR_ERROR(_("Signal handler reported %d errors: last error: %s"),
|
||||||
errors, strerror (sig_lasterrno));
|
errors, virStrerror (sig_lasterrno, ebuf, sizeof ebuf));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2743,8 +2760,10 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (godaemon) {
|
if (godaemon) {
|
||||||
|
char ebuf[1024];
|
||||||
if (qemudGoDaemon() < 0) {
|
if (qemudGoDaemon() < 0) {
|
||||||
VIR_ERROR(_("Failed to fork as daemon: %s"), strerror(errno));
|
VIR_ERROR(_("Failed to fork as daemon: %s"),
|
||||||
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error1;
|
goto error1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2765,7 +2784,9 @@ int main(int argc, char **argv) {
|
|||||||
qemudSetNonBlock(sigpipe[1]) < 0 ||
|
qemudSetNonBlock(sigpipe[1]) < 0 ||
|
||||||
qemudSetCloseExec(sigpipe[0]) < 0 ||
|
qemudSetCloseExec(sigpipe[0]) < 0 ||
|
||||||
qemudSetCloseExec(sigpipe[1]) < 0) {
|
qemudSetCloseExec(sigpipe[1]) < 0) {
|
||||||
VIR_ERROR(_("Failed to create pipe: %s"), strerror(errno));
|
char ebuf[1024];
|
||||||
|
VIR_ERROR(_("Failed to create pipe: %s"),
|
||||||
|
virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error2;
|
goto error2;
|
||||||
}
|
}
|
||||||
sigwrite = sigpipe[1];
|
sigwrite = sigpipe[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user