File: nodeusers.c

package info (click to toggle)
node 0.3.0-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 420 kB
  • ctags: 431
  • sloc: ansic: 3,379; makefile: 86; sh: 78
file content (87 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download | duplicates (2)
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
84
85
86
87
#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 "kernel_ax25.h"
#include "kernel_rose.h"
#include <netax25/axlib.h>
#include <netax25/procutils.h>

#include "node.h"

/*
 * These are needed for util.c to link
 */
int LogLevel		= L_NONE;
char *NodeId		= "Nodeusers:";
char *NodePrompt       	= "\n";
char *expand_string(char *str, int argc, char **argv) { return str; }

ax25io *NodeIo		= NULL;

static int logging	= 0;

static void pipe_handler(int sig)
{
	if (logging)
		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;

	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 failed\r\n");
		return 1;
	}
	if (inet && axio_getline(NodeIo) == NULL) {
		if (logging)
			syslog(LOG_ERR, "axio_getline: %m");
		axio_end(NodeIo);
		return 1;
	}
	n = user_count();
	nprintf("\n%s - %d user%s.\n\n", VERSION, n, n == 1 ? "" : "s");
	user_list(1);
	if (n > 0)
		nputs("\n");
	if (axio_flush(NodeIo) == -1 && logging)
		syslog(LOG_ERR, "axio_flush: %m");
	axio_end(NodeIo);
	usleep(500000L);
	closelog();
	return 0;
}