Compare commits
No commits in common. "b8cbb8a7a013c547187c4263ef4187c60eb25061" and "1e247d1c89bd3b3266550a85e7c9db7c743a56da" have entirely different histories.
b8cbb8a7a0
...
1e247d1c89
1 changed files with 40 additions and 57 deletions
97
irena.c
97
irena.c
|
|
@ -26,15 +26,26 @@ const char version[] = "$Id$";
|
|||
#include <sys/un.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
FILE *mout;
|
||||
|
||||
int maintainance = 0;
|
||||
|
||||
int verbosity[2] = {1,1};
|
||||
static inline void silent(int v) { if (verbosity[0] < v) verbosity[1] = 0; }
|
||||
static inline void unsilent() { verbosity[1] = verbosity[0]; }
|
||||
static inline void loud(int v) { if (v > verbosity[0]) verbosity[1] = v; }
|
||||
static inline int verbose(int v) { v = verbosity[1] >= v; unsilent(); return v; }
|
||||
int verbosity = 1;
|
||||
int next_verbosity = 1;
|
||||
static inline void silent(int v) {
|
||||
if (verbosity < v)
|
||||
next_verbosity = 0;
|
||||
}
|
||||
static inline void loud(int v) {
|
||||
if (v > verbosity)
|
||||
next_verbosity = v;
|
||||
}
|
||||
static inline int verbose(int v)
|
||||
{
|
||||
v = next_verbosity >= v;
|
||||
next_verbosity = verbosity;
|
||||
return v;
|
||||
}
|
||||
|
||||
// replacement for perror()
|
||||
void merror(const char *s)
|
||||
|
|
@ -44,9 +55,8 @@ void merror(const char *s)
|
|||
fprintf(mout, "%s: %s\n", s, strerror(e));
|
||||
}
|
||||
|
||||
#define DEBUG 3
|
||||
#ifdef DEBUG
|
||||
# define debug(fmt, ...) if (verbose(DEBUG)) fprintf(mout, fmt, __VA_ARGS__)
|
||||
# define debug(fmt, ...) fprintf(mout, fmt, __VA_ARGS__)
|
||||
#else
|
||||
# define debug(fmt, ...)
|
||||
#endif
|
||||
|
|
@ -1951,11 +1961,8 @@ int send_irena_command(const char *c)
|
|||
}
|
||||
no_uart=0;
|
||||
time_t t = time(0);
|
||||
if (last_irena_command_sent+1 >= t) {
|
||||
if (verbose(3))
|
||||
fprintf(mout, "IRENA CMD postponed: %s\n", c);
|
||||
if (last_irena_command_sent+1 >= t)
|
||||
return -2;
|
||||
}
|
||||
size_t sl = strlen(c);
|
||||
int n = write(i_buf.fd, c, sl);
|
||||
last_irena_command_sent = t;
|
||||
|
|
@ -1996,7 +2003,6 @@ void send_fct(time_t t)
|
|||
fct_ack = -1;
|
||||
fct_status = fct_size;
|
||||
}
|
||||
unsilent();
|
||||
return;
|
||||
}
|
||||
snprintf(fct_cmd, sizeof(fct_cmd), "u/f=%d", fct_size);
|
||||
|
|
@ -2014,7 +2020,6 @@ void send_fct(time_t t)
|
|||
fct_got_data = 0;
|
||||
fct_sent++;
|
||||
}
|
||||
unsilent();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2095,7 +2100,7 @@ int send_file(const char *fn)
|
|||
for (int i=0; i < n; ) {
|
||||
char cmd[64];
|
||||
int retry = 0;
|
||||
int c = snprintf(cmd, 64, "v f[%d]=:=", i>>2);
|
||||
int c = snprintf(cmd, 64, "v f[%d]=:", i>>2);
|
||||
while (c<58) {
|
||||
int nn = -i & 3;
|
||||
if (c < 54 || nn > n-i)
|
||||
|
|
@ -2222,20 +2227,6 @@ int close_cmd_socket()
|
|||
return 0;
|
||||
}
|
||||
|
||||
void print_asocket(FILE *mout)
|
||||
{
|
||||
char *mode = cmd_socket_flags & SOCK_SHALL_BE_MOUT ? "interactive " : "";
|
||||
if (acmd_socket_addr.g.sa_family == AF_INET) {
|
||||
unsigned int ip = ntohl(acmd_socket_addr.i.sin_addr.s_addr);
|
||||
fprintf(mout, "%ssocket connection from %d.%d.%d.%d:%d\n",
|
||||
mode,
|
||||
(ip>>24) & 0xff, (ip>>16) & 0xff, (ip>>8) & 0xff, ip & 0xff,
|
||||
ntohs(acmd_socket_addr.i.sin_port) );
|
||||
}
|
||||
else if (acmd_socket_addr.g.sa_family == AF_UNIX)
|
||||
fprintf(mout, "%sunix socket connection\n", mode);
|
||||
}
|
||||
|
||||
int open_cmd_socket(int na, char **av)
|
||||
{
|
||||
if (!strcmp(av[na-1], "close")) {
|
||||
|
|
@ -2272,7 +2263,6 @@ int open_cmd_socket(int na, char **av)
|
|||
else if (na==1) {
|
||||
is_open:
|
||||
fprintf(mout, "command socket is %s«%s»\n", mode, cmd_socket_name());
|
||||
print_asocket(mout);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
|
@ -2292,7 +2282,6 @@ int open_cmd_socket(int na, char **av)
|
|||
setsockopt(cmd_socket_fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int));
|
||||
|
||||
if (bind(cmd_socket_fd, &cmd_socket_addr.g, sizeof(cmd_socket_addr.u))<0) {
|
||||
|
||||
merror("bind");
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -2338,7 +2327,10 @@ int accept_cmd_socket(struct line_buffer *b, int fd)
|
|||
buffer_reset(b);
|
||||
b->fd = sfd;
|
||||
|
||||
char *mode = "";
|
||||
|
||||
if (cmd_socket_flags & SOCK_SHALL_BE_MOUT) {
|
||||
mode = "interactive ";
|
||||
int fd = dup(sfd);
|
||||
if (fd<0) {
|
||||
merror("dup socket");
|
||||
|
|
@ -2355,9 +2347,15 @@ int accept_cmd_socket(struct line_buffer *b, int fd)
|
|||
fprintf(mout, "irena %s\n", version);
|
||||
}
|
||||
|
||||
if (verbose(0))
|
||||
print_asocket(stderr);
|
||||
|
||||
if (acmd_socket_addr.g.sa_family == AF_INET) {
|
||||
unsigned int ip = ntohl(acmd_socket_addr.i.sin_addr.s_addr);
|
||||
fprintf(stderr, "accepting %ssocket connection from %d.%d.%d.%d:%d\n",
|
||||
mode,
|
||||
(ip>>24) & 0xff, (ip>>16) & 0xff, (ip>>8) & 0xff, ip & 0xff,
|
||||
ntohs(acmd_socket_addr.i.sin_port) );
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "accepting %sunix socket connection\n", mode);
|
||||
return sfd;
|
||||
}
|
||||
|
||||
|
|
@ -2370,17 +2368,12 @@ int close_acmd_socket(struct line_buffer *b)
|
|||
if (r)
|
||||
merror("fclose socket");
|
||||
}
|
||||
if (verbose(0)) {
|
||||
print_asocket(stderr);
|
||||
fprintf(stderr, "closing socket connection\n");
|
||||
}
|
||||
if (b->fd >= 0) {
|
||||
close(b->fd);
|
||||
if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, b->fd, 0))
|
||||
merror("EPOLL_CTL_DEL acmd socket");
|
||||
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, b->fd, 0);
|
||||
fprintf(stderr, "closing socket connection\n");
|
||||
}
|
||||
b->fd = -1;
|
||||
cmd_socket_addr.g.sa_family = AF_UNSPEC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2471,8 +2464,7 @@ struct numbers {
|
|||
{.name="time_resolution", .doc="seconds", .i=&time_resolution, .flags=NU_INT},
|
||||
{.name="highgain", .doc="ch#", .i=high_gain_ch, .flags=NU_INT, .size=18},
|
||||
{.name="lowgain", .doc="ch#", .i=low_gain_ch, .flags=NU_INT, .size=18},
|
||||
{.name="verbosity", .doc="int", .i=verbosity, .flags=NU_INT, .size=2},
|
||||
{.name="maintainance", .doc="int", .i=&maintainance, .flags=NU_INT},
|
||||
{.name="verbosity", .doc="int", .i=&verbosity, .flags=NU_INT},
|
||||
{.name=0}
|
||||
};
|
||||
|
||||
|
|
@ -3011,7 +3003,7 @@ int main(int argc, char **argv)
|
|||
close_acmd_socket(&s_buf);
|
||||
while (l) {
|
||||
process_cmd(l);
|
||||
l = get_line(&s_buf, 0);
|
||||
l = get_line(&c_buf, 0);
|
||||
}
|
||||
}
|
||||
else if (eev[i].data.fd) {
|
||||
|
|
@ -3021,23 +3013,14 @@ int main(int argc, char **argv)
|
|||
char *l = get_line(&c_buf, eev[i].events);
|
||||
while (l) {
|
||||
process_cmd(l);
|
||||
if (prompt) {
|
||||
if (maintainance)
|
||||
fprintf(stderr, "M:%s", prompt);
|
||||
else
|
||||
fprintf(stderr, prompt);
|
||||
}
|
||||
if (prompt)
|
||||
fprintf(stderr, prompt);
|
||||
l = get_line(&c_buf, 0);
|
||||
}
|
||||
if (eev[i].events & EPOLLHUP)
|
||||
if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, 0, 0))
|
||||
merror("EPOLL_CTL_DEL <stdin>");
|
||||
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (maintainance)
|
||||
continue;
|
||||
|
||||
int tick = t/time_resolution;
|
||||
if (tick != last_tick) {
|
||||
sync_clocks(t);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue