1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-31 00:03:07 +03:00

tests: Support logging into separate file for exec-ed libssh test server

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2024-04-04 17:43:16 +02:00
committed by Andreas Schneider
parent 9170320298
commit 8577f588c3
4 changed files with 39 additions and 2 deletions

View File

@ -59,6 +59,7 @@ struct arguments_st {
char *password;
char *config_file;
char *log_file;
bool with_global_config;
char *pid_file;
};
@ -84,6 +85,7 @@ static void free_arguments(struct arguments_st *arguments)
SAFE_FREE(arguments->username);
SAFE_FREE(arguments->password);
SAFE_FREE(arguments->config_file);
SAFE_FREE(arguments->log_file);
SAFE_FREE(arguments->pid_file);
end:
@ -174,6 +176,7 @@ static void print_server_state(struct server_state_st *state)
state->parse_global_config? "TRUE": "FALSE");
printf("config_file = %s\n",
state->config_file? state->config_file: "NULL");
printf("log_file = %s\n", state->log_file ? state->log_file : "NULL");
printf("=================================================\n");
}
}
@ -297,6 +300,11 @@ static int init_server_state(struct server_state_st *state,
arguments->config_file = NULL;
}
if (arguments->log_file) {
state->log_file = arguments->log_file;
arguments->log_file = NULL;
}
/* TODO make configurable */
state->max_tries = 3;
state->error = 0;
@ -440,6 +448,14 @@ static struct argp_option options[] = {
.doc = "Use this server configuration file.",
.group = 0
},
{
.name = "log_file",
.key = 'l',
.arg = "LOG_FILE",
.flags = 0,
.doc = "Output log to this file.",
.group = 0
},
{ .name = NULL }
};
@ -553,6 +569,14 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
goto end;
}
break;
case 'l':
arguments->log_file = strdup(arg);
if (arguments->log_file == NULL) {
fprintf(stderr, "Out of memory\n");
rc = ENOMEM;
goto end;
}
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */