]> sourceware.org Git - lvm2.git/commitdiff
libdaemon: Split daemon-shared.[hc] into daemon-io.[hc] and config-util.[hc].
authorPetr Rockai <prockai@redhat.com>
Wed, 26 Sep 2012 12:44:03 +0000 (14:44 +0200)
committerPetr Rockai <prockai@redhat.com>
Wed, 26 Sep 2012 15:26:23 +0000 (17:26 +0200)
daemons/lvmetad/lvmetad-core.c
include/.symlinks.in
lib/cache/lvmetad.h
libdaemon/client/Makefile.in
libdaemon/client/config-util.c [moved from libdaemon/client/daemon-shared.c with 76% similarity]
libdaemon/client/config-util.h [moved from libdaemon/client/daemon-shared.h with 88% similarity]
libdaemon/client/daemon-client.c
libdaemon/client/daemon-io.c [new file with mode: 0644]
libdaemon/client/daemon-io.h [new file with mode: 0644]
libdaemon/server/daemon-server.c

index 6c2303df91491ef4a283b7e50f1648cf6ebb81b7..0c39a778683a7ed035ef37438be039e5bb8fe148 100644 (file)
@@ -15,7 +15,8 @@
 #define _XOPEN_SOURCE 500  /* pthread */
 
 #include "configure.h"
-#include "daemon-shared.h"
+#include "daemon-io.h"
+#include "config-util.h"
 #include "daemon-server.h"
 #include "daemon-log.h"
 
index bd0eba7dc61b8e3ec865ac2de55236765c82b671..e94ff849877093de60eb837bd6850ad9fe645e69 100644 (file)
@@ -61,7 +61,8 @@
 @top_srcdir@/lib/report/report.h
 @top_srcdir@/lib/uuid/uuid.h
 @top_srcdir@/libdaemon/client/daemon-client.h
-@top_srcdir@/libdaemon/client/daemon-shared.h
+@top_srcdir@/libdaemon/client/daemon-io.h
+@top_srcdir@/libdaemon/client/config-util.h
 @top_srcdir@/libdm/libdevmapper.h
 @top_srcdir@/libdm/misc/dm-ioctl.h
 @top_srcdir@/libdm/misc/dm-logging.h
index 60110a007fecaadfac4d2bffca86bd3705a5a994..10c4b139e18053847be25dfd6928a84a6d9e423b 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef _LVM_METAD_H
 #define _LVM_METAD_H
 
-#include "daemon-shared.h" // XXX
+#include "config-util.h"
 
 struct volume_group;
 struct cmd_context;
index 4d8c436fe3575e4057d5c4d0ca7b38a196be17f2..d608816ab38f4d965dd597127005e21148c16d67 100644 (file)
@@ -15,6 +15,6 @@ top_srcdir = @top_srcdir@
 top_builddir = @top_builddir@
 
 LIB_STATIC = libdaemonclient.a
-SOURCES = daemon-shared.c daemon-client.c
+SOURCES = daemon-io.c config-util.c daemon-client.c
 
 include $(top_builddir)/make.tmpl
similarity index 76%
rename from libdaemon/client/daemon-shared.c
rename to libdaemon/client/config-util.c
index e6f17a03bce35b3d02dac6833c0eb1a19ee2a938..25731398075913e24a874bcf8e9b6bf70ec13977 100644 (file)
 #include <unistd.h>
 
 #include "dm-logging.h"
-#include "daemon-shared.h"
+#include "config-util.h"
 #include "libdevmapper.h"
 
-/*
- * Read a single message from a (socket) filedescriptor. Messages are delimited
- * by blank lines. This call will block until all of a message is received. The
- * memory will be allocated from heap. Upon error, all memory is freed and the
- * buffer pointer is set to NULL.
- *
- * See also write_buffer about blocking (read_buffer has identical behaviour).
- */
-int read_buffer(int fd, char **buffer) {
-       int bytes = 0;
-       int buffersize = 32;
-       char *new;
-       *buffer = dm_malloc(buffersize + 1);
-
-       while (1) {
-               int result = read(fd, (*buffer) + bytes, buffersize - bytes);
-               if (result > 0) {
-                       bytes += result;
-                       if (!strncmp((*buffer) + bytes - 4, "\n##\n", 4)) {
-                               *(*buffer + bytes - 4) = 0;
-                               break; /* success, we have the full message now */
-                       }
-                       if (bytes == buffersize) {
-                               buffersize += 1024;
-                               if (!(new = realloc(*buffer, buffersize + 1)))
-                                       goto fail;
-                               *buffer = new;
-                       }
-                       continue;
-               }
-               if (result == 0) {
-                       errno = ECONNRESET;
-                       goto fail; /* we should never encounter EOF here */
-               }
-               if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
-                       goto fail;
-               /* TODO call select here if we encountered EAGAIN/EWOULDBLOCK/EINTR */
-       }
-       return 1;
-fail:
-       dm_free(*buffer);
-       *buffer = NULL;
-       return 0;
-}
-
-/*
- * Write a buffer to a filedescriptor. Keep trying. Blocks (even on
- * SOCK_NONBLOCK) until all of the write went through.
- *
- * TODO use select on EWOULDBLOCK/EAGAIN/EINTR to avoid useless spinning
- */
-int write_buffer(int fd, const char *buffer, int length) {
-       static const char terminate[] = "\n##\n";
-       int done = 0;
-       int written = 0;
-write:
-       while (1) {
-               int result = write(fd, buffer + written, length - written);
-               if (result > 0)
-                       written += result;
-               if (result < 0 && errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR)
-                       return 0; /* too bad */
-               if (written == length) {
-                       if (done)
-                               return 1;
-                       else
-                               break; /* done */
-               }
-       }
-
-       buffer = terminate;
-       length = 4;
-       written = 0;
-       done = 1;
-       goto write;
-}
-
 char *format_buffer_v(const char *head, va_list ap)
 {
        char *buffer, *old;
similarity index 88%
rename from libdaemon/client/daemon-shared.h
rename to libdaemon/client/config-util.h
index acb71c6b2651f227a1f2e16402485c6c3a9b246e..ae5e5569f605d82e6162a39db51e2b3b44422030 100644 (file)
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef _LVM_DAEMON_SHARED_H
-#define _LVM_DAEMON_SHARED_H
+#ifndef _LVM_DAEMON_CONFIG_UTIL_H
+#define _LVM_DAEMON_CONFIG_UTIL_H
 
 #include "configure.h"
 #include "libdevmapper.h"
 
-#define _REENTRANT
-#define _GNU_SOURCE
-#define _FILE_OFFSET_BITS 64
-
-/* TODO function names */
-
 #include <stdarg.h>
 
-int read_buffer(int fd, char **buffer);
-int write_buffer(int fd, const char *buffer, int length);
 char *format_buffer_v(const char *head, va_list ap);
 char *format_buffer(const char *head, ...);
 
index 2de970acfb57614c2eb3572bd1008b89248f928e..e34a2a00f722c1a4cb688c27792ade6989bab419 100644 (file)
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "daemon-shared.h"
+#include "daemon-io.h"
+#include "config-util.h"
 #include "daemon-client.h"
+#include "dm-logging.h"
 
 #include <sys/un.h>
 #include <sys/socket.h>
diff --git a/libdaemon/client/daemon-io.c b/libdaemon/client/daemon-io.c
new file mode 100644 (file)
index 0000000..4af9343
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2011-2012 Red Hat, Inc.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "daemon-io.h"
+#include "dm-logging.h"
+#include "libdevmapper.h"
+
+/*
+ * Read a single message from a (socket) filedescriptor. Messages are delimited
+ * by blank lines. This call will block until all of a message is received. The
+ * memory will be allocated from heap. Upon error, all memory is freed and the
+ * buffer pointer is set to NULL.
+ *
+ * See also write_buffer about blocking (read_buffer has identical behaviour).
+ */
+int read_buffer(int fd, char **buffer) {
+       int bytes = 0;
+       int buffersize = 32;
+       char *new;
+       *buffer = dm_malloc(buffersize + 1);
+
+       while (1) {
+               int result = read(fd, (*buffer) + bytes, buffersize - bytes);
+               if (result > 0) {
+                       bytes += result;
+                       if (!strncmp((*buffer) + bytes - 4, "\n##\n", 4)) {
+                               *(*buffer + bytes - 4) = 0;
+                               break; /* success, we have the full message now */
+                       }
+                       if (bytes == buffersize) {
+                               buffersize += 1024;
+                               if (!(new = realloc(*buffer, buffersize + 1)))
+                                       goto fail;
+                               *buffer = new;
+                       }
+                       continue;
+               }
+               if (result == 0) {
+                       errno = ECONNRESET;
+                       goto fail; /* we should never encounter EOF here */
+               }
+               if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
+                       goto fail;
+               /* TODO call select here if we encountered EAGAIN/EWOULDBLOCK/EINTR */
+       }
+       return 1;
+fail:
+       dm_free(*buffer);
+       *buffer = NULL;
+       return 0;
+}
+
+/*
+ * Write a buffer to a filedescriptor. Keep trying. Blocks (even on
+ * SOCK_NONBLOCK) until all of the write went through.
+ *
+ * TODO use select on EWOULDBLOCK/EAGAIN/EINTR to avoid useless spinning
+ */
+int write_buffer(int fd, const char *buffer, int length) {
+       static const char terminate[] = "\n##\n";
+       int done = 0;
+       int written = 0;
+write:
+       while (1) {
+               int result = write(fd, buffer + written, length - written);
+               if (result > 0)
+                       written += result;
+               if (result < 0 && errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR)
+                       return 0; /* too bad */
+               if (written == length) {
+                       if (done)
+                               return 1;
+                       else
+                               break; /* done */
+               }
+       }
+
+       buffer = terminate;
+       length = 4;
+       written = 0;
+       done = 1;
+       goto write;
+}
diff --git a/libdaemon/client/daemon-io.h b/libdaemon/client/daemon-io.h
new file mode 100644 (file)
index 0000000..e6e5f06
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011-2012 Red Hat, Inc.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _LVM_DAEMON_IO_H
+#define _LVM_DAEMON_IO_H
+
+#include "configure.h"
+#include "libdevmapper.h"
+
+#define _REENTRANT
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+
+/* TODO function names */
+
+int read_buffer(int fd, char **buffer);
+int write_buffer(int fd, const char *buffer, int length);
+
+#endif /* _LVM_DAEMON_SHARED_H */
index 50bf065600be1f679ffa6d7da20e9d9f5ca59661..b15a7cc94a21ee5f8e5ce912dc62630713696383 100644 (file)
@@ -10,7 +10,8 @@
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "daemon-shared.h"
+#include "daemon-io.h"
+#include "config-util.h"
 #include "daemon-server.h"
 #include "daemon-log.h"
 
This page took 0.053112 seconds and 5 git commands to generate.