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:
committed by
Andreas Schneider
parent
9170320298
commit
8577f588c3
@ -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. */
|
||||
|
@ -54,6 +54,8 @@ static int libssh_server_setup(void **state)
|
||||
struct test_server_st *tss = NULL;
|
||||
struct torture_state *s = NULL;
|
||||
|
||||
char log_file[1024];
|
||||
|
||||
assert_non_null(state);
|
||||
|
||||
tss = (struct test_server_st*)calloc(1, sizeof(struct test_server_st));
|
||||
@ -62,6 +64,13 @@ static int libssh_server_setup(void **state)
|
||||
torture_setup_socket_dir((void **)&s);
|
||||
torture_setup_create_libssh_config((void **)&s);
|
||||
|
||||
snprintf(log_file,
|
||||
sizeof(log_file),
|
||||
"%s/sshd/log",
|
||||
s->socket_dir);
|
||||
|
||||
s->log_file = strdup(log_file);
|
||||
|
||||
/* The second argument is the relative path to the "server" directory binary
|
||||
*/
|
||||
torture_setup_libssh_server((void **)&s, "./test_server/test_server");
|
||||
|
@ -1020,10 +1020,12 @@ void torture_setup_libssh_server(void **state, const char *server_path)
|
||||
/* Write the start command */
|
||||
printed = snprintf(start_cmd, sizeof(start_cmd),
|
||||
"%s"
|
||||
"%s -f%s -v4 -p22 -i%s -C%s%s%s",
|
||||
"%s -f%s -v4 -p22 -i%s -C%s%s%s%s%s",
|
||||
timeout_cmd,
|
||||
server_path, s->pcap_file, s->srv_pidfile,
|
||||
s->srv_config, extra_options, TORTURE_SSH_SERVER);
|
||||
s->srv_config,
|
||||
s->log_file ? " -l " : "", s->log_file ? s->log_file : "",
|
||||
extra_options, TORTURE_SSH_SERVER);
|
||||
if (printed < 0) {
|
||||
fail_msg("Failed to print start command!");
|
||||
/* Unreachable */
|
||||
@ -1116,6 +1118,7 @@ void torture_free_state(struct torture_state *s)
|
||||
free(s->srv_config);
|
||||
free(s->socket_dir);
|
||||
free(s->pcap_file);
|
||||
free(s->log_file);
|
||||
free(s->srv_pidfile);
|
||||
free(s->srv_additional_config);
|
||||
free(s);
|
||||
|
@ -68,6 +68,7 @@ struct torture_sftp {
|
||||
struct torture_state {
|
||||
char *socket_dir;
|
||||
char *pcap_file;
|
||||
char *log_file;
|
||||
char *srv_pidfile;
|
||||
char *srv_config;
|
||||
bool srv_pam;
|
||||
|
Reference in New Issue
Block a user