Add a simple load-tester utility to initiate over control socket
This commit is contained in:
parent
d65683eef4
commit
965f7bd54f
|
@ -0,0 +1 @@
|
|||
load-tester
|
|
@ -21,3 +21,6 @@ libstrongswan_load_tester_la_SOURCES = \
|
|||
load_tester_diffie_hellman.c load_tester_diffie_hellman.h
|
||||
|
||||
libstrongswan_load_tester_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
ipsec_PROGRAMS = load-tester
|
||||
load_tester_SOURCES = load_tester.c
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Martin Willi
|
||||
* Copyright (C) 2012 revosec AG
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "load_tester_control.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
/**
|
||||
* Connect to the daemon, return stream
|
||||
*/
|
||||
static FILE* make_connection()
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
FILE *stream;
|
||||
int fd;
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy(addr.sun_path, LOAD_TESTER_SOCKET);
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "opening socket failed: %s\n", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
if (connect(fd, (struct sockaddr *)&addr,
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) < 0)
|
||||
{
|
||||
fprintf(stderr, "connecting to %s failed: %s\n",
|
||||
LOAD_TESTER_SOCKET, strerror(errno));
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
stream = fdopen(fd, "r+");
|
||||
if (!stream)
|
||||
{
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate load-tests
|
||||
*/
|
||||
static int initiate(unsigned int count)
|
||||
{
|
||||
FILE *stream;
|
||||
char c;
|
||||
|
||||
stream = make_connection();
|
||||
if (!stream)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stream, "%u\n", count);
|
||||
|
||||
while (1)
|
||||
{
|
||||
fflush(stream);
|
||||
c = fgetc(stream);
|
||||
if (c == EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (fputc(c, stdout) == EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
fclose(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 3 && strcmp(argv[1], "initiate") == 0)
|
||||
{
|
||||
return initiate(atoi(argv[2]));
|
||||
}
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, " %s initiate <count>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue