-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodeusers.c
83 lines (78 loc) · 1.67 KB
/
nodeusers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <signal.h>
#include <syslog.h>
/* #include <netax25/kernel_ax25.h>
#include <netax25/kernel_rose.h>
*/
#include <netax25/axlib.h>
#include <netax25/procutils.h>
#include "node.h"
#include "config.h"
char *NodeId = "Nodeusers:";
int LogLevel = LOGLVL_NONE;
ax25io *NodeIo = NULL;
static void pipe_handler(int sig)
{
syslog(LOG_ERR, "received SIGPIPE");
axio_end(NodeIo);
exit(1);
}
int main(int argc, char **argv)
{
int n, len = 1024;
char *cp = UNSPEC_EOL;
int inet = 0;
int logging = 0;
while ((n = getopt(argc, argv, "ail")) != -1) {
switch (n) {
case 'a':
cp = AX25_EOL;
len = 128;
break;
case 'i':
cp = INET_EOL;
inet = 1;
break;
case 'l':
logging = 1;
break;
default:
fprintf(stderr, "usage: nodeusers [-a] [-i] [-l]\r\n");
return 1;
}
}
if (logging)
openlog("nodeusers", LOG_PID, LOG_DAEMON);
signal(SIGPIPE, pipe_handler);
NodeIo = axio_init(STDIN_FILENO, STDOUT_FILENO, len, cp);
if (NodeIo == NULL) {
fprintf(stderr, "nodeusers: axio_init failes\r\n");
return 1;
}
if (inet && axio_getline(NodeIo) == NULL) {
if (logging)
syslog(LOG_ERR, "axio_getline: %m");
axio_printf(NodeIo,"\n");
axio_end(NodeIo);
return 1;
}
n = user_count();
axio_printf(NodeIo,"\n%s (%s), %d user%s.\n",
VERSION, COMPILING, n, n == 1 ? "" : "s");
user_list(0, NULL);
if (n > 0)
axio_printf(NodeIo,"\n");
if (axio_flush(NodeIo) == -1 && logging)
syslog(LOG_ERR, "axio_flush: %m");
axio_end(NodeIo);
usleep(500000L);
closelog();
return 0;
}