summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-10-31 19:18:41 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-10-31 19:18:41 +0700
commit04ac4751701a28b7bec0c812a98d8a7ca1008a69 (patch)
tree837a4d4cfa318008f68e1004a6a9dee3d14a0e0d /utils.c
parent0578d751b1ea0ac10ad2b033f9b73c922f120fdb (diff)
sock_events.c: also track child file descriptors
In some applications, such as OsmocomBB, a single UNIX socket can be used by multiple processes (i.e. a server and multiple clients). Previously this caused a segmentation fault. Let's modify both sock_ev_accept() and sock_ev_accept4() in order to handle such connections properly, by using both socket path and dissector from the parent.
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index f188205..e1b0d7d 100644
--- a/utils.c
+++ b/utils.c
@@ -85,6 +85,32 @@ void udtrace_add_fd(int fd)
ss->fd = fd;
}
+/* add a file descriptor from the list of to-be-traced ones */
+void udtrace_add_fd_child(int pfd, int cfd)
+{
+ struct sock_state *pss, *css;
+
+ /* Find the parent socket state first */
+ pss = udtrace_sstate_by_fd(pfd);
+ if (!pss) {
+ LOG("Couldn't find parent UNIX FD %d for %d\n", pfd, cfd);
+ return;
+ }
+
+ /* Find an unused state in unix_fds */
+ css = udtrace_sstate_by_fd(-1);
+ if (!css) {
+ LOG("Couldn't add UNIX FD %d (no space in unix_fds)\n", cfd);
+ return;
+ }
+
+ LOG("Adding FD %d as a child of %d\n", cfd, pfd);
+
+ css->dissector = pss->dissector;
+ css->path = strdup(pss->path);
+ css->fd = cfd;
+}
+
/* delete a file descriptor from the list of to-be-traced ones */
void udtrace_del_fd(int fd)
{
personal git repositories of Harald Welte. Your mileage may vary