mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
const: lvmpolld long_options
Rework usage of long_options so it can be constified, and also correct use of 'enum action_index'.
This commit is contained in:
parent
c140601cf6
commit
495ea0f058
@ -867,14 +867,14 @@ enum action_index {
|
|||||||
ACTION_MAX /* keep at the end */
|
ACTION_MAX /* keep at the end */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const action_fn_t actions[ACTION_MAX] = { [ACTION_DUMP] = action_dump };
|
|
||||||
|
|
||||||
static int _make_action(enum action_index idx, void *args)
|
static int _make_action(enum action_index idx, void *args)
|
||||||
{
|
{
|
||||||
return idx < ACTION_MAX ? actions[idx](args) : 0;
|
static const action_fn_t _actions[ACTION_MAX] = { [ACTION_DUMP] = action_dump };
|
||||||
|
|
||||||
|
return idx < ACTION_MAX ? _actions[idx](args) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _lvmpolld_client(const char *socket, unsigned action)
|
static int _lvmpolld_client(const char *socket, enum action_index action)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -892,10 +892,9 @@ static int _lvmpolld_client(const char *socket, unsigned action)
|
|||||||
return r ? EXIT_SUCCESS : EXIT_FAILURE;
|
return r ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int action_idx = ACTION_MAX;
|
static const struct option _long_options[] = {
|
||||||
static struct option long_options[] = {
|
|
||||||
/* Have actions always at the beginning of the array. */
|
/* Have actions always at the beginning of the array. */
|
||||||
{"dump", no_argument, &action_idx, ACTION_DUMP }, /* or an option_index ? */
|
{"dump", no_argument, 0, ACTION_DUMP }, /* or an option_index ? */
|
||||||
|
|
||||||
/* other options */
|
/* other options */
|
||||||
{"binary", required_argument, 0, 'B' },
|
{"binary", required_argument, 0, 'B' },
|
||||||
@ -914,7 +913,7 @@ int main(int argc, char *argv[])
|
|||||||
int opt;
|
int opt;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int client = 0, server = 0;
|
int client = 0, server = 0;
|
||||||
unsigned action = ACTION_MAX;
|
enum action_index action = ACTION_MAX;
|
||||||
struct timespec timeout;
|
struct timespec timeout;
|
||||||
daemon_idle di = { .ptimeout = &timeout };
|
daemon_idle di = { .ptimeout = &timeout };
|
||||||
struct lvmpolld_state ls = { .log_config = "" };
|
struct lvmpolld_state ls = { .log_config = "" };
|
||||||
@ -930,16 +929,16 @@ int main(int argc, char *argv[])
|
|||||||
.socket_path = getenv("LVM_LVMPOLLD_SOCKET") ?: LVMPOLLD_SOCKET,
|
.socket_path = getenv("LVM_LVMPOLLD_SOCKET") ?: LVMPOLLD_SOCKET,
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "fhVl:p:s:B:t:", long_options, &option_index)) != -1) {
|
while ((opt = getopt_long(argc, argv, "fhVl:p:s:B:t:", _long_options, &option_index)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 0 :
|
case 0 :
|
||||||
if (action < ACTION_MAX) {
|
if (action != ACTION_MAX) {
|
||||||
fprintf(stderr, "Can't perform more actions. Action already requested: %s\n",
|
fprintf(stderr, "Can't perform more actions. Action already requested: %s\n",
|
||||||
long_options[action].name);
|
_long_options[action].name);
|
||||||
_usage(argv[0], stderr);
|
_usage(argv[0], stderr);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
action = action_idx;
|
action = ACTION_DUMP;
|
||||||
client = 1;
|
client = 1;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
|
Loading…
Reference in New Issue
Block a user