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

tests: Support libssh server logging into separate file

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Norbert Pocs <npocs@redhat.com>
This commit is contained in:
Jakub Jelen
2023-01-20 11:02:04 +01:00
parent 9b263cf5e1
commit 20f52432fc
2 changed files with 28 additions and 4 deletions

View File

@ -40,7 +40,7 @@
void free_server_state(struct server_state_st *state)
{
if (state == NULL) {
goto end;
return;
}
SAFE_FREE(state->address);
@ -55,9 +55,7 @@ void free_server_state(struct server_state_st *state)
SAFE_FREE(state->expected_username);
SAFE_FREE(state->expected_password);
SAFE_FREE(state->config_file);
end:
return;
SAFE_FREE(state->log_file);
}
/* SIGCHLD handler for cleaning up dead children. */
@ -94,6 +92,30 @@ int run_server(struct server_state_st *state)
return SSH_ERROR;
}
/* Redirect all the output and errors to the file to avoid mixing up with
* the output from the client */
if (state->log_file != NULL) {
int fd;
FILE *f = fopen(state->log_file, "a");
if (f == NULL) {
fprintf(stderr, "Failed to open the log file: %s\n", strerror(errno));
return SSH_ERROR;
}
fd = dup2(fileno(f), STDERR_FILENO);
if (fd == -1) {
fprintf(stderr, "dup2 of log file to stderr failed: %s\n",
strerror(errno));
return SSH_ERROR;
}
fd = dup2(fileno(f), STDOUT_FILENO);
if (fd == -1) {
fprintf(stderr, "dup2 of log file to stdout failed: %s\n",
strerror(errno));
return SSH_ERROR;
}
fclose(f);
}
if (state->address == NULL) {
fprintf(stderr, "Missing bind address\n");
return SSH_ERROR;

View File

@ -52,6 +52,8 @@ struct server_state_st {
char *config_file;
bool parse_global_config;
char *log_file;
/* State */
int max_tries;
int error;