server: Better newstyle .open failure handling
[nbdkit/ericb.git] / server / options.h
blobc74e0b8bf9a3de5349bea0b87cdbba8e12115e9f
1 /* nbdkit
2 * Copyright (C) 2013-2019 Red Hat Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Red Hat nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #ifndef NBDKIT_OPTIONS_H
34 #define NBDKIT_OPTIONS_H
36 #include <stdbool.h>
37 #include <getopt.h>
38 #include <limits.h>
39 #include <string.h>
41 enum {
42 HELP_OPTION = CHAR_MAX + 1,
43 DUMP_CONFIG_OPTION,
44 DUMP_PLUGIN_OPTION,
45 EXIT_WITH_PARENT_OPTION,
46 FILTER_OPTION,
47 LOG_OPTION,
48 LONG_OPTIONS_OPTION,
49 MASK_HANDSHAKE_OPTION,
50 NO_SR_OPTION,
51 RUN_OPTION,
52 SELINUX_LABEL_OPTION,
53 SHORT_OPTIONS_OPTION,
54 TLS_OPTION,
55 TLS_CERTIFICATES_OPTION,
56 TLS_PSK_OPTION,
57 TLS_VERIFY_PEER_OPTION,
60 static const char *short_options = "D:e:fg:i:nop:P:rst:u:U:vV";
61 static const struct option long_options[] = {
62 { "debug", required_argument, NULL, 'D' },
63 { "dump-config", no_argument, NULL, DUMP_CONFIG_OPTION },
64 { "dump-plugin", no_argument, NULL, DUMP_PLUGIN_OPTION },
65 { "exit-with-parent", no_argument, NULL, EXIT_WITH_PARENT_OPTION },
66 { "export", required_argument, NULL, 'e' },
67 { "export-name", required_argument, NULL, 'e' },
68 { "exportname", required_argument, NULL, 'e' },
69 { "filter", required_argument, NULL, FILTER_OPTION },
70 { "foreground", no_argument, NULL, 'f' },
71 { "no-fork", no_argument, NULL, 'f' },
72 { "group", required_argument, NULL, 'g' },
73 { "help", no_argument, NULL, HELP_OPTION },
74 { "ip-addr", required_argument, NULL, 'i' },
75 { "ipaddr", required_argument, NULL, 'i' },
76 { "log", required_argument, NULL, LOG_OPTION },
77 { "long-options", no_argument, NULL, LONG_OPTIONS_OPTION },
78 { "mask-handshake", required_argument, NULL, MASK_HANDSHAKE_OPTION },
79 { "new-style", no_argument, NULL, 'n' },
80 { "newstyle", no_argument, NULL, 'n' },
81 { "no-sr", no_argument, NULL, NO_SR_OPTION },
82 { "old-style", no_argument, NULL, 'o' },
83 { "oldstyle", no_argument, NULL, 'o' },
84 { "pid-file", required_argument, NULL, 'P' },
85 { "pidfile", required_argument, NULL, 'P' },
86 { "port", required_argument, NULL, 'p' },
87 { "read-only", no_argument, NULL, 'r' },
88 { "readonly", no_argument, NULL, 'r' },
89 { "run", required_argument, NULL, RUN_OPTION },
90 { "selinux-label", required_argument, NULL, SELINUX_LABEL_OPTION },
91 { "short-options", no_argument, NULL, SHORT_OPTIONS_OPTION },
92 { "single", no_argument, NULL, 's' },
93 { "stdin", no_argument, NULL, 's' },
94 { "threads", required_argument, NULL, 't' },
95 { "tls", required_argument, NULL, TLS_OPTION },
96 { "tls-certificates", required_argument, NULL, TLS_CERTIFICATES_OPTION },
97 { "tls-psk", required_argument, NULL, TLS_PSK_OPTION },
98 { "tls-verify-peer", no_argument, NULL, TLS_VERIFY_PEER_OPTION },
99 { "unix", required_argument, NULL, 'U' },
100 { "user", required_argument, NULL, 'u' },
101 { "verbose", no_argument, NULL, 'v' },
102 { "version", no_argument, NULL, 'V' },
103 { NULL },
106 /* Is it a plugin or filter name relative to the plugindir/filterdir? */
107 static inline bool
108 is_short_name (const char *filename)
110 return strchr (filename, '.') == NULL && strchr (filename, '/') == NULL;
113 #endif /* NBDKIT_OPTIONS_H */