aboutsummaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-08-16 18:11:00 +0200
committerAndreas Schneider <asn@cryptomilk.org>2020-03-29 10:00:57 +0200
commitf529659f76a27f05b02824a539c908d9bd728e42 (patch)
treea01add530b7c8145f702102940f1e4a263dbb191 /tests/server
parent3aea2ad53fe9c53160ca28a037cb4257ad2060d8 (diff)
downloadlibssh-f529659f76a27f05b02824a539c908d9bd728e42.tar.gz
libssh-f529659f76a27f05b02824a539c908d9bd728e42.tar.xz
libssh-f529659f76a27f05b02824a539c908d9bd728e42.zip
test_server: Added an option to write PID to file
Using the added option it is possible to set a path to a file in which the server will write its PID. This can be used later to kill the server. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/server')
-rw-r--r--tests/server/test_server/main.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/server/test_server/main.c b/tests/server/test_server/main.c
index 87ff6c8e..b4676b4b 100644
--- a/tests/server/test_server/main.c
+++ b/tests/server/test_server/main.c
@@ -61,6 +61,7 @@ struct arguments_st {
char *config_file;
bool with_global_config;
+ char *pid_file;
};
static void free_arguments(struct arguments_st *arguments)
@@ -85,6 +86,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->pid_file);
end:
return;
@@ -402,6 +404,14 @@ static struct argp_option options[] = {
.group = 0
},
{
+ .name = "pid_file",
+ .key = 'i',
+ .arg = "FILE",
+ .flags = 0,
+ .doc = "The server will write its pid in this file, if provided.",
+ .group = 0
+ },
+ {
.name = "auth-methods",
.key = 'a',
.arg = "METHODS",
@@ -500,6 +510,14 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
goto end;
}
break;
+ case 'i':
+ arguments->pid_file = strdup(arg);
+ if (arguments->pid_file == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ rc = ENOMEM;
+ goto end;
+ }
+ break;
case 'k':
arguments->host_key = strdup(arg);
if (arguments->host_key == NULL) {
@@ -598,6 +616,8 @@ static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
{
int rc;
+ FILE *pid_file;
+ pid_t pid;
struct arguments_st arguments = {
.address = NULL,
@@ -611,6 +631,17 @@ int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
argp_parse (&argp, argc, argv, 0, 0, &arguments);
#endif
+ if (arguments.pid_file) {
+ pid_file = fopen(arguments.pid_file, "w");
+ if (pid_file == NULL) {
+ rc = -1;
+ goto free_arguments;
+ }
+ pid = getpid();
+ fprintf(pid_file, "%d\n", pid);
+ fclose(pid_file);
+ }
+
/* Initialize the state using default or given parameters */
rc = init_server_state(&state, &arguments);
if (rc != 0) {