mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
pipe: add -t switch to terminate execution after a given time
This commit is contained in:
parent
b44289022d
commit
2b7687cc4d
2 changed files with 13 additions and 2 deletions
|
@ -309,6 +309,7 @@ void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx))
|
|||
sigemptyset(&sa_quit.sa_mask);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
sigaction(SIGALRM, &sa_quit, NULL);
|
||||
|
||||
struct sigaction sa_chld = {
|
||||
.sa_flags = 0,
|
||||
|
|
14
src/pipe.c
14
src/pipe.c
|
@ -58,6 +58,9 @@ pthread_t ptid; /**< Parent thread id */
|
|||
|
||||
static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
||||
{
|
||||
if (signal == SIGALRM)
|
||||
info("Reached timeout. Terminating...");
|
||||
|
||||
if (recvv.enabled) {
|
||||
pthread_cancel(recvv.thread);
|
||||
pthread_join(recvv.thread, NULL);
|
||||
|
@ -92,6 +95,7 @@ static void usage()
|
|||
printf(" -x swap read / write endpoints\n");
|
||||
printf(" -s only read data from stdin and send it to node\n");
|
||||
printf(" -r only read data from node and write it to stdout\n");
|
||||
printf(". -t NUM terminate after NUM seconds\n");
|
||||
printf(" -L NUM terminate after NUM samples sent\n");
|
||||
printf(" -l NUM terminate after NUM samples received\n\n");
|
||||
|
||||
|
@ -205,6 +209,7 @@ int main(int argc, char *argv[])
|
|||
int ret, level = V;
|
||||
|
||||
bool reverse = false;
|
||||
double timeout = 0;
|
||||
|
||||
sendd = recvv = (struct dir) {
|
||||
.enabled = true,
|
||||
|
@ -214,7 +219,7 @@ int main(int argc, char *argv[])
|
|||
ptid = pthread_self();
|
||||
|
||||
char c, *endptr;
|
||||
while ((c = getopt(argc, argv, "hxrsd:l:L:")) != -1) {
|
||||
while ((c = getopt(argc, argv, "hxrsd:l:L:t:")) != -1) {
|
||||
switch (c) {
|
||||
case 'x':
|
||||
reverse = true;
|
||||
|
@ -234,6 +239,9 @@ int main(int argc, char *argv[])
|
|||
case 'L':
|
||||
sendd.limit = strtoul(optarg, &endptr, 10);
|
||||
goto check;
|
||||
case 't':
|
||||
timeout = strtod(optarg, &endptr);
|
||||
goto check;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage();
|
||||
|
@ -297,8 +305,10 @@ check: if (optarg == endptr)
|
|||
if (sendd.enabled)
|
||||
pthread_create(&sendd.thread, NULL, send_loop, NULL);
|
||||
|
||||
ualarm(timeout * 1e6);
|
||||
|
||||
for (;;)
|
||||
sleep(1);
|
||||
pause();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue