1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

command: Skip some memory zeroing.

commands[] is in bss, its content wouldn't change if reinitialised
and unregister has no memory to free so don't bother.
This commit is contained in:
Alasdair G Kergon 2018-01-13 03:36:53 +00:00
parent e4e2abc8bc
commit da37cbd24f
2 changed files with 6 additions and 17 deletions

View File

@ -1356,13 +1356,11 @@ static void _create_opt_names_alpha(void)
qsort(opt_names_alpha, ARG_COUNT, sizeof(long), _long_name_compare);
}
static int _copy_line(char *line, int max_line, int *position)
static int _copy_line(char *line, int max_line, int *position, int *len)
{
int p = *position;
int i = 0;
memset(line, 0, max_line);
while (1) {
line[i] = _command_input[p];
i++;
@ -1376,7 +1374,9 @@ static int _copy_line(char *line, int max_line, int *position)
if (i == (max_line - 1))
break;
}
line[i] = '\0';
*position = p;
*len = i + 1;
return 1;
}
@ -1394,6 +1394,7 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
int prev_was_oo = 0;
int prev_was_op = 0;
int copy_pos = 0;
int copy_len = 0;
int skip = 0;
int i;
@ -1404,14 +1405,14 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
/* Process each line of command-lines-input.h (from command-lines.in) */
while (_copy_line(line, MAX_LINE, &copy_pos)) {
while (_copy_line(line, MAX_LINE, &copy_pos, &copy_len)) {
if (line[0] == '\n')
break;
if ((n = strchr(line, '\n')))
*n = '\0';
memcpy(line_orig, line, sizeof(line));
memcpy(line_orig, line, copy_len);
_split_line(line, &line_argc, line_argv, ' ');
if (!line_argc)

View File

@ -1262,15 +1262,6 @@ static const struct command_function *_find_command_id_function(int command_enum
return NULL;
}
static void _unregister_commands(void)
{
_cmdline.commands = NULL;
_cmdline.num_commands = 0;
_cmdline.command_names = NULL;
_cmdline.num_command_names = 0;
memset(&commands, 0, sizeof(commands));
}
int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
{
int i;
@ -1279,8 +1270,6 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
if (_cmdline.commands)
return 1;
memset(&commands, 0, sizeof(commands));
/*
* populate commands[] array with command definitions
* by parsing command-lines.in/command-lines-input.h
@ -3335,7 +3324,6 @@ struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
void lvm_fin(struct cmd_context *cmd)
{
_unregister_commands();
destroy_toolcontext(cmd);
udev_fin_library_context();
}