annotate rvinterf/asyncshell/main.c @ 1002:e6ccc8788b96

gsm-fw/riviera/rvt: TCH and KEEPALIVE channel definitions added
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Thu, 17 Mar 2016 05:39:51 +0000
parents bd873572ef2c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the main() function for fc-shell.
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/errno.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <unistd.h>
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 char *socket_pathname = "/tmp/rvinterf_socket";
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 char *rvinterf_ttyport;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 int ttyhacks, dflag;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 int sock;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 main(argc, argv)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 char **argv;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 extern int optind;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 extern char *optarg;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 int c, sopt = 0;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 fd_set fds;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 while ((c = getopt(argc, argv, "B:dl:p:s:w:")) != EOF)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 switch (c) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 case 'B':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 rvinterf_Bopt = optarg;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 case 'd':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 dflag++;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 case 'l':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 rvinterf_lopt = optarg;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 case 'p':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 rvinterf_ttyport = optarg;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 case 's':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 socket_pathname = optarg;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 sopt++;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 case 'w':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 rvinterf_wopt = optarg;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 case '?':
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 default:
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 usage: fprintf(stderr,
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 "usage: %s [options] [command]\n", argv[0]);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 if (rvinterf_ttyport) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 if (sopt) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 fprintf(stderr,
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 "%s error: -p and -s options are mutually exclusive\n",
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 argv[0]);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 launch_rvinterf(rvinterf_ttyport);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 } else {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
64 fprintf(stderr,
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
65 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
66 argv[0]);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
67 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
68 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
69 connect_local_socket();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
70 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
71
965
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 872
diff changeset
72 if (argv[optind])
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 872
diff changeset
73 return oneshot_command(argc - optind, argv + optind);
bd873572ef2c fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 872
diff changeset
74
872
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
75 ttyhacks = isatty(0) && !dflag;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76 init();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 tty_init();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78 for (;;) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 FD_ZERO(&fds);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 FD_SET(0, &fds);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81 FD_SET(sock, &fds);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 c = select(sock+1, &fds, 0, 0, 0);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 if (c < 0) {
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 if (errno == EINTR)
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85 continue;
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 tty_cleanup();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 perror("select");
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 exit(1);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90 if (FD_ISSET(0, &fds))
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 handle_tty_input();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
92 if (FD_ISSET(sock, &fds))
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
93 handle_rvinterf_input();
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
94 fflush(stdout);
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
95 }
5e46679bdb6a fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
96 }