FreeCalypso > hg > themwi-rtp-mgr
comparison rtp-mgr/ctrl_sock.c @ 2:247f4bbde24c
rtp-mgr: daemon ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 27 May 2024 19:42:19 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:560a3765ab30 | 2:247f4bbde24c |
---|---|
1 /* | |
2 * In this module we implement the logic of listening on the RTP | |
3 * allocator control socket and accepting control connections. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/stat.h> | |
8 #include <sys/socket.h> | |
9 #include <sys/un.h> | |
10 #include <netinet/in.h> | |
11 #include <stdio.h> | |
12 #include <stdint.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <strings.h> | |
16 #include <syslog.h> | |
17 #include <unistd.h> | |
18 #include "struct.h" | |
19 #include "select.h" | |
20 | |
21 static const char ctrl_socket_pathname[] = "/var/gsm/rtp_alloc_socket"; | |
22 | |
23 extern void ctrl_message_handler(); | |
24 | |
25 void | |
26 ctrlsock_accept_handler(listener_fd) | |
27 { | |
28 struct sockaddr_un sa; | |
29 socklen_t sa_len; | |
30 int conn_fd; | |
31 | |
32 sa_len = sizeof sa; | |
33 conn_fd = accept(listener_fd, (struct sockaddr *) &sa, &sa_len); | |
34 if (conn_fd < 0) { | |
35 syslog(LOG_CRIT, "accept on UNIX socket: %m"); | |
36 exit(1); | |
37 } | |
38 update_max_fd(conn_fd); | |
39 FD_SET(conn_fd, &select_for_read); | |
40 select_handlers[conn_fd] = ctrl_message_handler; | |
41 syslog(LOG_DEBUG, "accepted ctrl connection"); | |
42 } | |
43 | |
44 create_ctrl_socket() | |
45 { | |
46 struct sockaddr_un sa; | |
47 unsigned sa_len; | |
48 int fd, rc; | |
49 | |
50 fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); | |
51 if (fd < 0) { | |
52 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m"); | |
53 return(-1); | |
54 } | |
55 unlink(ctrl_socket_pathname); | |
56 fill_sockaddr_un(ctrl_socket_pathname, &sa, &sa_len); | |
57 rc = bind(fd, (struct sockaddr *) &sa, sa_len); | |
58 if (rc < 0) { | |
59 syslog(LOG_ERR, "bind to %s: %m", ctrl_socket_pathname); | |
60 return(-1); | |
61 } | |
62 rc = listen(fd, 3); | |
63 if (rc < 0) { | |
64 syslog(LOG_CRIT, "listen on UNIX socket: %m"); | |
65 return(-1); | |
66 } | |
67 chmod(ctrl_socket_pathname, 0775); | |
68 update_max_fd(fd); | |
69 FD_SET(fd, &select_for_read); | |
70 select_handlers[fd] = ctrlsock_accept_handler; | |
71 return(0); | |
72 } |