Move safewrite and saferead to a separate file.

We currently use safewrite from inside libvirt and don't want to publish
any such function name.  However, we do want to use it in applications
like virsh, libvirtd and libvirt_proxy that link with libvirt.  To that
end, this change moves that function definition (along with the nearly
identical saferead) into a new file, util-lib.c.  To avoid maintaining
separate copies of even such small functions, we simply include that new
file from util.c.  Then, the separate applications that need to use
safewrite simply compile and link with util-lib.c.

Of course, this does mean that each of those applications will
containing two copies of these functions.  However, the functions
are so small that it's not worth worrying about that.

* src/util.c (saferead, safewrite): Move function definitions to
util-lib.c and include that .c file.
* src/util-lib.c (saferead, safewrite): New file.  Functions from src/util.c
with slight change (s/int r =/ssize_t r =/) to reflect read/write return type.
* src/util-lib.h: Declare the two moved functions.
* src/util.h: Remove declarations.  Include src/util-lib.h.
* proxy/Makefile.am (libvirt_proxy_SOURCES): Add src/util-lib.c.
* qemud/Makefile.am (libvirtd_SOURCES): Likewise.
* src/Makefile.am (virsh_SOURCES): Add util-lib.c.  Remove some SP-before-TAB.
This commit is contained in:
Jim Meyering
2008-02-22 15:53:13 +00:00
parent 6187c6de9b
commit a178a4e7bf
9 changed files with 108 additions and 67 deletions

View File

@@ -2,7 +2,7 @@
* proxy_svr.c: root suid proxy server for Xen access to APIs with no
* side effects from unauthenticated clients.
*
* Copyright (C) 2006, 2007 Red Hat, Inc.
* Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -26,6 +26,7 @@
#include "internal.h"
#include "proxy_internal.h"
#include "util.h"
#include "xen_internal.h"
#include "xend_internal.h"
#include "xs_internal.h"
@@ -317,19 +318,12 @@ proxyWriteClientSocket(int nr, virProxyPacketPtr req) {
return(-1);
}
retry:
ret = write(pollInfos[nr].fd, (char *) req, req->len);
ret = safewrite(pollInfos[nr].fd, (char *) req, req->len);
if (ret < 0) {
if (errno == EINTR) {
if (debug > 0)
fprintf(stderr, "write socket %d to client %d interrupted\n",
pollInfos[nr].fd, nr);
goto retry;
}
fprintf(stderr, "write %d bytes to socket %d from client %d failed\n",
req->len, pollInfos[nr].fd, nr);
proxyCloseClientSocket(nr);
return(-1);
proxyCloseClientSocket(nr);
return(-1);
}
if (ret == 0) {
if (debug)