public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/daemons/common daemon-client.c daemon-cli ...
@ 2012-02-26  8:46 mornfall
  0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2012-02-26  8:46 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2012-02-26 08:46:28

Modified files:
	daemons/common : daemon-client.c daemon-client.h daemon-shared.c 

Log message:
	Improve error handling & reporting in common daemon code.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.h.diff?cvsroot=lvm2&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-shared.c.diff?cvsroot=lvm2&r1=1.10&r2=1.11

--- LVM2/daemons/common/daemon-client.c	2012/02/24 00:02:54	1.14
+++ LVM2/daemons/common/daemon-client.c	2012/02/26 08:46:28	1.15
@@ -9,22 +9,18 @@
 #include <errno.h> // ENOMEM
 
 daemon_handle daemon_open(daemon_info i) {
-	daemon_handle h = { .protocol_version = 0 };
+	daemon_handle h = { .protocol_version = 0, .error = 0 };
 	daemon_reply r = { .cft = NULL };
 	struct sockaddr_un sockaddr;
 
-	if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM /* | SOCK_NONBLOCK */, 0)) < 0) {
-		perror("socket");
+	if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM /* | SOCK_NONBLOCK */, 0)) < 0)
 		goto error;
-	}
+
 	memset(&sockaddr, 0, sizeof(sockaddr));
-	fprintf(stderr, "[C] connecting to %s\n", i.socket);
 	strcpy(sockaddr.sun_path, i.socket);
 	sockaddr.sun_family = AF_UNIX;
-	if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
-		perror("connect");
+	if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr)))
 		goto error;
-	}
 
 	r = daemon_send_simple(h, "hello", NULL);
 	if (r.error || strcmp(daemon_reply_str(r, "response", "unknown"), "OK"))
@@ -42,7 +38,9 @@
 
 	daemon_reply_destroy(r);
 	return h;
+
 error:
+	h.error = errno;
 	if (h.socket_fd >= 0)
 		close(h.socket_fd);
 	if (r.cft)
@@ -61,13 +59,15 @@
 	}
 
 	assert(rq.buffer);
-	write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer));
+	if (!write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer)))
+		reply.error = errno;
+
 	dm_free(rq.buffer);
 
 	if (read_buffer(h.socket_fd, &reply.buffer)) {
 		reply.cft = dm_config_from_string(reply.buffer);
 	} else
-		reply.error = 1;
+		reply.error = errno;
 
 	return reply;
 }
--- LVM2/daemons/common/daemon-client.h	2012/02/23 23:52:11	1.10
+++ LVM2/daemons/common/daemon-client.h	2012/02/26 08:46:28	1.11
@@ -21,6 +21,7 @@
 	int socket_fd; /* the fd we use to talk to the daemon */
 	const char *protocol;
 	int protocol_version;  /* version of the protocol the daemon uses */
+	int error;
 } daemon_handle;
 
 typedef struct {
--- LVM2/daemons/common/daemon-shared.c	2012/01/25 13:06:57	1.10
+++ LVM2/daemons/common/daemon-shared.c	2012/02/26 08:46:28	1.11
@@ -24,12 +24,14 @@
 		int result = read(fd, (*buffer) + bytes, buffersize - bytes);
 		if (result > 0)
 			bytes += result;
-		if (result == 0)
+		if (result == 0) {
+			errno = ECONNRESET;
 			goto fail; /* we should never encounter EOF here */
+		}
 		if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK)
 			goto fail;
 
-		if ((!strncmp((*buffer) + bytes - 4, "\n##\n", 4))) {
+		if (!strncmp((*buffer) + bytes - 4, "\n##\n", 4)) {
 			*(*buffer + bytes - 4) = 0;
 			break; /* success, we have the full message now */
 		}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* LVM2/daemons/common daemon-client.c daemon-cli ...
@ 2012-01-15 15:16 mornfall
  0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2012-01-15 15:16 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2012-01-15 15:16:50

Modified files:
	daemons/common : daemon-client.c daemon-client.h 

Log message:
	Fix prototypes for daemon_send_simple (const char).

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.h.diff?cvsroot=lvm2&r1=1.8&r2=1.9

--- LVM2/daemons/common/daemon-client.c	2011/10/30 21:58:59	1.9
+++ LVM2/daemons/common/daemon-client.c	2012/01/15 15:16:50	1.10
@@ -57,7 +57,7 @@
 		dm_config_destroy(r.cft);
 }
 
-daemon_reply daemon_send_simple(daemon_handle h, char *id, ...)
+daemon_reply daemon_send_simple(daemon_handle h, const char *id, ...)
 {
 	static const daemon_reply err = { .error = ENOMEM, .buffer = NULL, .cft = NULL };
 	daemon_request rq = { .cft = NULL };
--- LVM2/daemons/common/daemon-client.h	2011/08/30 15:42:57	1.8
+++ LVM2/daemons/common/daemon-client.h	2012/01/15 15:16:50	1.9
@@ -77,7 +77,7 @@
  * type (string, integer) of the value is indicated by a character substituted
  * for ? in %?: d for integer, s for string.
  */
-daemon_reply daemon_send_simple(daemon_handle h, char *id, ...);
+daemon_reply daemon_send_simple(daemon_handle h, const char *id, ...);
 
 void daemon_reply_destroy(daemon_reply r);
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* LVM2/daemons/common daemon-client.c daemon-cli ...
@ 2011-08-30 15:42 mornfall
  0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2011-08-30 15:42 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2011-08-30 15:42:57

Modified files:
	daemons/common : daemon-client.c daemon-client.h daemon-server.c 
	                 daemon-server.h 

Log message:
	Adapt the daemon/common code to use the new dm_config interface.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.h.diff?cvsroot=lvm2&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-server.c.diff?cvsroot=lvm2&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-server.h.diff?cvsroot=lvm2&r1=1.9&r2=1.10

--- LVM2/daemons/common/daemon-client.c	2011/06/29 22:20:14	1.5
+++ LVM2/daemons/common/daemon-client.c	2011/08/30 15:42:56	1.6
@@ -44,7 +44,7 @@
 	write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer));
 
 	if (read_buffer(h.socket_fd, &reply.buffer)) {
-		reply.cft = create_config_tree_from_string(reply.buffer);
+		reply.cft = dm_config_from_string(reply.buffer);
 	} else
 		reply.error = 1;
 
--- LVM2/daemons/common/daemon-client.h	2011/07/18 14:46:54	1.7
+++ LVM2/daemons/common/daemon-client.h	2011/08/30 15:42:57	1.8
@@ -13,7 +13,6 @@
  */
 
 #include "libdevmapper.h" // for dm_list, needed by config.h
-#include "config.h" // should become part of libdevmapper later
 
 #ifndef _LVM_DAEMON_COMMON_CLIENT_H
 #define _LVM_DAEMON_COMMON_CLIENT_H
@@ -42,13 +41,13 @@
 	 *        knobs = [ "twiddle", "tweak" ]
 	 *    }
 	 */
-	struct config_tree *cft;
+	struct dm_config_tree *cft;
 } daemon_request;
 
 typedef struct {
 	int error; /* 0 for success */
 	char *buffer; /* textual reply */
-	struct config_tree *cft; /* parsed reply, if available */
+	struct dm_config_tree *cft; /* parsed reply, if available */
 } daemon_reply;
 
 /*
@@ -83,11 +82,11 @@
 void daemon_reply_destroy(daemon_reply r);
 
 static inline int daemon_reply_int(daemon_reply r, const char *path, int def) {
-	return find_config_int(r.cft->root, path, def);
+	return dm_config_find_int(r.cft->root, path, def);
 }
 
 static inline const char *daemon_reply_str(daemon_reply r, const char *path, const char *def) {
-	return find_config_str(r.cft->root, path, def);
+	return dm_config_find_str(r.cft->root, path, def);
 }
 
 
--- LVM2/daemons/common/daemon-server.c	2011/07/20 18:23:33	1.9
+++ LVM2/daemons/common/daemon-server.c	2011/08/30 15:42:57	1.10
@@ -242,7 +242,7 @@
 		if (!read_buffer(b->client.socket_fd, &req.buffer))
 			goto fail;
 
-		req.cft = create_config_tree_from_string(req.buffer);
+		req.cft = dm_config_from_string(req.buffer);
 		if (!req.cft)
 			fprintf(stderr, "error parsing request:\n %s\n", req.buffer);
 		response res = b->s.handler(b->s, b->client, req);
@@ -251,7 +251,7 @@
 		dm_free(req.buffer);
 
 		if (!res.buffer) {
-			write_config_node(res.cft->root, buffer_line, &res);
+			dm_config_write_node(res.cft->root, buffer_line, &res);
 			buffer_rewrite(&res.buffer, "%s\n\n", NULL);
 			destroy_config_tree(res.cft);
 		}
@@ -323,6 +323,7 @@
 	signal(SIGHUP, &_exit_handler);
 	signal(SIGQUIT, &_exit_handler);
 	signal(SIGTERM, &_exit_handler);
+	signal(SIGALRM, &_exit_handler);
 	signal(SIGPIPE, SIG_IGN);
 
 #ifdef linux
--- LVM2/daemons/common/daemon-server.h	2011/07/18 14:46:54	1.9
+++ LVM2/daemons/common/daemon-server.h	2011/08/30 15:42:57	1.10
@@ -13,7 +13,6 @@
  */
 
 #include "daemon-client.h"
-#include "config.h" // XXX will be in libdevmapper.h later
 
 #ifndef _LVM_DAEMON_COMMON_SERVER_H
 #define _LVM_DAEMON_COMMON_SERVER_H
@@ -26,13 +25,13 @@
 } client_handle;
 
 typedef struct {
-	struct config_tree *cft;
+	struct dm_config_tree *cft;
 	char *buffer;
 } request;
 
 typedef struct {
 	int error;
-	struct config_tree *cft;
+	struct dm_config_tree *cft;
 	char *buffer;
 } response;
 
@@ -47,13 +46,13 @@
 static inline int daemon_request_int(request r, const char *path, int def) {
 	if (!r.cft)
 		return def;
-	return find_config_int(r.cft->root, path, def);
+	return dm_config_find_int(r.cft->root, path, def);
 }
 
 static inline const char *daemon_request_str(request r, const char *path, const char *def) {
 	if (!r.cft)
 		return def;
-	return find_config_str(r.cft->root, path, def);
+	return dm_config_find_str(r.cft->root, path, def);
 }
 
 /*


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-26  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-26  8:46 LVM2/daemons/common daemon-client.c daemon-cli mornfall
  -- strict thread matches above, loose matches on Subject: below --
2012-01-15 15:16 mornfall
2011-08-30 15:42 mornfall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).