All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Teigland <teigland@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH] lvmetad: --dump option to print state
Date: Fri, 4 Jan 2013 11:42:22 -0500	[thread overview]
Message-ID: <20130104164222.GA10211@redhat.com> (raw)

Also add long opts for other options.
---
 daemons/lvmetad/lvmetad-core.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 0a1c884..ab8d83e 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -20,11 +20,13 @@
 #include "daemon-server.h"
 #include "daemon-log.h"
 #include "lvm-version.h"
+#include "lvmetad-client.h"
 
 #include <assert.h>
 #include <pthread.h>
 #include <stdint.h>
 #include <unistd.h>
+#include <getopt.h>
 
 typedef struct {
 	log_state *log; /* convenience */
@@ -1019,6 +1021,19 @@ static response dump(lvmetad_state *s)
 	return res;
 }
 
+static void print_dump(const char *socket_path)
+{
+	daemon_handle h = lvmetad_open(socket_path);
+	daemon_reply reply;
+
+	reply = daemon_send_simple(h, "dump", NULL);
+
+	printf("%s\n", reply.buffer.mem);
+
+	daemon_reply_destroy(reply);
+	daemon_close(h);
+}
+
 static response handler(daemon_state s, client_handle h, request r)
 {
 	lvmetad_state *state = s.private;
@@ -1146,6 +1161,7 @@ static void usage(char *prog, FILE *file)
 int main(int argc, char *argv[])
 {
 	signed char opt;
+	int option_index = 0;
 	daemon_state s = { .private = NULL };
 	lvmetad_state ls;
 	int _socket_override = 1;
@@ -1165,8 +1181,17 @@ int main(int argc, char *argv[])
 	s.protocol_version = 1;
 	ls.log_config = "";
 
-	// use getopt_long
-	while ((opt = getopt(argc, argv, "?fhVl:s:")) != EOF) {
+	static struct option long_options[] = {
+		{"help",       no_argument,       0, 'h' },
+		{"dump",       no_argument,       0, 'd' },
+		{"foreground", no_argument,       0, 'f' },
+		{"log_config", required_argument, 0, 'l' },
+		{"socket",     required_argument, 0, 's' },
+		{"version",    no_argument,       0, 'V' },
+		{0,            0,                 0,  0  }
+	};
+
+	while ((opt = getopt_long(argc, argv, "hdfl:s:V", long_options, &option_index)) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage(argv[0], stdout);
@@ -1174,6 +1199,9 @@ int main(int argc, char *argv[])
 		case '?':
 			usage(argv[0], stderr);
 			exit(0);
+		case 'd':
+			print_dump(s.socket_path);
+			exit(0);
 		case 'f':
 			s.foreground = 1;
 			break;
-- 
1.8.1.rc1.5.g7e0651a



                 reply	other threads:[~2013-01-04 16:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130104164222.GA10211@redhat.com \
    --to=teigland@redhat.com \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.