annotate rtp-mgr/main.c @ 10:9499d41fc393 default tip

daemon: change config file name to themwi-rtp-mgr.cfg
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 27 May 2024 22:47:19 +0000
parents 247f4bbde24c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Main module for themwi-rtp-mgr.
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/time.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/errno.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <signal.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <unistd.h>
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int syslog_facility;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 fd_set select_for_read;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 void (*select_handlers[FD_SETSIZE])();
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void *select_data[FD_SETSIZE];
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static int max_fd;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 update_max_fd(newfd)
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (newfd >= FD_SETSIZE) {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 syslog(LOG_CRIT, "FATAL: file descriptor %d >= FD_SETSIZE",
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 newfd);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (newfd > max_fd)
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 max_fd = newfd;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 main(argc, argv)
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char **argv;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fd_set fds;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 int cc, i;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 read_config_file();
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 openlog("themwi-rtp-mgr", 0, syslog_facility);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (create_ctrl_socket() < 0) {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr,
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 "error creating RTP allocator control socket\n");
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 exit(1);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 signal(SIGPIPE, SIG_IGN);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 /* main select loop */
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 for (;;) {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 bcopy(&select_for_read, &fds, sizeof(fd_set));
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 cc = select(max_fd+1, &fds, 0, 0, 0);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (cc < 0) {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (errno == EINTR)
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 continue;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 syslog(LOG_CRIT, "select: %m");
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 for (i = 0; cc && i <= max_fd; i++) {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (FD_ISSET(i, &fds)) {
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 select_handlers[i](i, select_data[i]);
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 cc--;
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
247f4bbde24c rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }