FreeCalypso > hg > freecalypso-tools
annotate rvinterf/tmsh/oneshot.c @ 400:be2683e1ac5e
CHANGES: fc-shell key command addition documented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Mar 2018 01:59:34 +0000 |
parents | 27c41e4b21ae |
children |
rev | line source |
---|---|
71
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the one-shot mode of operation for fc-tmsh. |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/errno.h> |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <unistd.h> |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "exitcodes.h" |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern int oneshot_nowait; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int sock; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int got_tm_response; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 oneshot_command(argc, argv) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char **argv; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 fd_set fds; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int rc; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!oneshot_nowait) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 init(); /* to catch the response properly */ |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 rc = dispatch_oneshot_cmd(argc, argv); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (rc) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(rc); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (oneshot_nowait) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(0); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 /* wait for response */ |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 for (;;) { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 FD_ZERO(&fds); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 FD_SET(sock, &fds); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 rc = select(sock+1, &fds, 0, 0, 0); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (rc < 0) { |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (errno == EINTR) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 continue; |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 perror("select"); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(ERROR_UNIX); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (FD_ISSET(sock, &fds)) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 handle_rvinterf_input(); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (got_tm_response) |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 exit(0); |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
27c41e4b21ae
fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |