From: Jes.Sorensen@redhat.com
To: neilb@suse.de
Cc: linux-raid@vger.kernel.org, dledford@redhat.com, kay@redhat.com,
harald@redhat.com, lpoetter@redhat.com, mschmidt@redhat.com
Subject: [PATCH 1/4] mdmon: Use getopt_long() to parse command line options
Date: Mon, 23 Jan 2012 12:18:22 +0100 [thread overview]
Message-ID: <1327317505-14782-2-git-send-email-Jes.Sorensen@redhat.com> (raw)
In-Reply-To: <1327317505-14782-1-git-send-email-Jes.Sorensen@redhat.com>
From: Jes Sorensen <Jes.Sorensen@redhat.com>
This changes mdmon over to use getopt_long() for option parsing,
making it easier to add new options. In addition this patch introduces
a short version -t for --takeover and adds -h/--help.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
mdmon.c | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/mdmon.c b/mdmon.c
index b6ae0e6..a65c4a4 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -265,7 +265,14 @@ static int do_fork(void)
void usage(void)
{
- fprintf(stderr, "Usage: mdmon [--all] [--takeover] CONTAINER\n");
+ fprintf(stderr,
+"Usage: mdmon [options] CONTAINER\n"
+"\n"
+"Options are:\n"
+" --help -h : This message\n"
+" --all : All devices\n"
+" --takeover -t : Takeover container\n"
+);
exit(2);
}
@@ -277,25 +284,47 @@ int main(int argc, char *argv[])
int devnum;
char *devname;
int status = 0;
- int arg;
+ int opt;
int all = 0;
int takeover = 0;
-
- for (arg = 1; arg < argc; arg++) {
- if (strncmp(argv[arg], "--all",5) == 0 ||
- strcmp(argv[arg], "/proc/mdstat") == 0) {
- container_name = argv[arg];
+ static struct option options[] = {
+ {"all", 0, NULL, 'a'},
+ {"takeover", 0, NULL, 't'},
+ {"help", 0, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
+ while ((opt = getopt_long(argc, argv, "th", options, NULL)) != -1) {
+ switch (opt) {
+ case 'a':
+ container_name = argv[optind-1];
all = 1;
- } else if (strcmp(argv[arg], "--takeover") == 0)
+ break;
+ case 't':
+ container_name = optarg;
takeover = 1;
- else if (container_name == NULL)
- container_name = argv[arg];
- else
+ break;
+ case 'h':
+ default:
usage();
+ break;
+ }
}
+
+ if (all == 0 && container_name == NULL) {
+ if (argv[optind])
+ container_name = argv[optind];
+ }
+
if (container_name == NULL)
usage();
+ if (argc - optind > 1)
+ usage();
+
+ if (strcmp(container_name, "/proc/mdstat") == 0)
+ all = 1;
+
if (all) {
struct mdstat_ent *mdstat, *e;
int container_len = strlen(container_name);
--
1.7.8.3
next prev parent reply other threads:[~2012-01-23 11:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-23 11:18 [PATCH v2 0/4] add --preboot argument to mdadm/mdmon Jes.Sorensen
2012-01-23 11:18 ` Jes.Sorensen [this message]
2012-01-23 11:18 ` [PATCH 2/4] Add --preboot argument to mdadm Jes.Sorensen
2012-01-23 11:18 ` [PATCH 3/4] Add --preboot argument to mdmon Jes.Sorensen
2012-01-23 11:18 ` [PATCH 4/4] Spawn mdmon with --preboot if mdadm was launched with --preboot Jes.Sorensen
2012-01-23 16:24 ` [PATCH v2 0/4] add --preboot argument to mdadm/mdmon Doug Ledford
2012-01-23 16:39 ` Jes Sorensen
2012-01-23 16:52 ` Doug Ledford
2012-01-23 17:04 ` John Robinson
2012-01-23 18:05 ` Jes Sorensen
2012-01-23 17:04 ` Krzysztof Adamski
2012-01-23 20:52 ` Lennart Poettering
-- strict thread matches above, loose matches on Subject: below --
2012-01-25 15:18 [PATCH v3 0/4] add --offroot " Jes.Sorensen
2012-01-25 15:18 ` [PATCH 1/4] mdmon: Use getopt_long() to parse command line options Jes.Sorensen
2012-01-17 10:48 [PATCH 0/4] add --initrd argument to mdadm/mdmon Jes.Sorensen
2012-01-17 10:48 ` [PATCH 1/4] mdmon: Use getopt_long() to parse command line options Jes.Sorensen
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=1327317505-14782-2-git-send-email-Jes.Sorensen@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=dledford@redhat.com \
--cc=harald@redhat.com \
--cc=kay@redhat.com \
--cc=linux-raid@vger.kernel.org \
--cc=lpoetter@redhat.com \
--cc=mschmidt@redhat.com \
--cc=neilb@suse.de \
/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 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 NNTP newsgroup(s).