#include <sys/mman.h>
#include <wait.h>
#include <cap-ng.h>
+#include <getopt.h>
#include "common/module.h"
#include "common/secret.h"
static int parse_arguments(int argc, char *const *const argv,
const char **src, const char **node, const char **opts)
{
- int i;
+ int opt = 0;
+ static struct option long_options[] = {
+ { "help", no_argument, 0, 'h' },
+ { "no-mtab", no_argument, 0, 'n' },
+ { "verbose", no_argument, 0, 'v' },
+ { "fake", no_argument, 0, 'f' },
+ { "options", required_argument, 0, 'o' },
+ { 0, 0, 0, 0 }
+ };
if (argc < 2) {
// There were no arguments. Just show the usage.
// Parse the remaining options
*opts = EMPTY_STRING;
- for (i = 3; i < argc; ++i) {
- if (!strcmp("-h", argv[i]))
- return 1;
- else if (!strcmp("-n", argv[i]))
- skip_mtab_flag = true;
- else if (!strcmp("-v", argv[i]))
- verboseflag = true;
- else if (!strcmp("-f", argv[i]))
- fakeflag = true;
- else if (!strcmp("-o", argv[i])) {
- ++i;
- if (i >= argc) {
- fprintf(stderr, "Option -o requires an argument.\n\n");
+ while ((opt = getopt_long(argc, argv, "hnvfo:",
+ long_options, NULL)) != -1) {
+ switch (opt) {
+ case 'h' : // -h or --help
+ return 1;
+ case 'n' : // -n or --no-mtab
+ skip_mtab_flag = true;
+ break;
+ case 'v' : // -v or --verbose
+ verboseflag = true;
+ break;
+ case 'f' : // -f or --fake
+ fakeflag = true;
+ break;
+ case 'o' : // -o or --options
+ *opts = optarg;
+ break;
+ default:
return -EINVAL;
- }
- *opts = argv[i];
- } else {
- fprintf(stderr, "Can't understand option: '%s'\n\n", argv[i]);
- return -EINVAL;
}
}
return 0;
printf("usage: %s [src] [mount-point] [-n] [-v] [-o ceph-options]\n",
prog_name);
printf("options:\n");
- printf("\t-h: Print this help\n");
- printf("\t-n: Do not update /etc/mtab\n");
- printf("\t-v: Verbose\n");
- printf("\t-f: Fake mount, do not actually mount\n");
- printf("\tceph-options: refer to mount.ceph(8)\n");
+ printf("\t-h, --help\tPrint this help\n");
+ printf("\t-n, --no-mtab\tDo not update /etc/mtab\n");
+ printf("\t-v, --verbose\tVerbose\n");
+ printf("\t-f, --fake\tFake mount, do not actually mount\n");
+ printf("ceph-options: refer to mount.ceph(8)\n");
printf("\n");
}