mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +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:
@ -40,7 +40,7 @@
|
|||||||
void free_server_state(struct server_state_st *state)
|
void free_server_state(struct server_state_st *state)
|
||||||
{
|
{
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
goto end;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SAFE_FREE(state->address);
|
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_username);
|
||||||
SAFE_FREE(state->expected_password);
|
SAFE_FREE(state->expected_password);
|
||||||
SAFE_FREE(state->config_file);
|
SAFE_FREE(state->config_file);
|
||||||
|
SAFE_FREE(state->log_file);
|
||||||
end:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SIGCHLD handler for cleaning up dead children. */
|
/* SIGCHLD handler for cleaning up dead children. */
|
||||||
@ -94,6 +92,30 @@ int run_server(struct server_state_st *state)
|
|||||||
return SSH_ERROR;
|
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) {
|
if (state->address == NULL) {
|
||||||
fprintf(stderr, "Missing bind address\n");
|
fprintf(stderr, "Missing bind address\n");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
|
@ -52,6 +52,8 @@ struct server_state_st {
|
|||||||
char *config_file;
|
char *config_file;
|
||||||
bool parse_global_config;
|
bool parse_global_config;
|
||||||
|
|
||||||
|
char *log_file;
|
||||||
|
|
||||||
/* State */
|
/* State */
|
||||||
int max_tries;
|
int max_tries;
|
||||||
int error;
|
int error;
|
||||||
|
Reference in New Issue
Block a user