troglobit / pimd

PIM-SM/SSM multicast routing for UNIX and Linux
http://troglobit.com/projects/pimd/
BSD 3-Clause "New" or "Revised" License
197 stars 87 forks source link

pimd does not work in background under FreeBSD #33

Closed skif-kiev closed 9 years ago

skif-kiev commented 10 years ago

FreeBSD 9.2-RELEASE amd64 pimd 2.2.0-alpha1

Being started without --debug and --foreground options pimd cant determine bootstrap router so doesn't send RP advertises. The reason is that we call pid=getpid() in routesock.c and use that value later to determine the valid message from routing socket. But between those operations we do fork() in main.c to daemonize pimd, so it gets new process ID that is different from pid. After that rtm.rtm_pid != pid becomes always true and k_req_incoming() always returns FALSE.

The patch, probably not optimal, follows. It moves pid determinition from init_routesock() to k_req_incoming().

--- routesock.c 2014-04-13 12:56:38.000000000 +0300
+++ routesock.c 2014-04-14 23:19:34.000000000 +0300
@@ -97,8 +97,6 @@
     int on = 0;
 #endif

-    pid = getpid();
-
     routing_socket = socket(PF_ROUTE, SOCK_RAW, 0);
     if (routing_socket < 0) {
        logit(LOG_ERR, errno, "Failed creating routing socket");
@@ -213,6 +211,8 @@
        return FALSE;
     }

+    pid = getpid();
+
     while (1) {
        rlen = read(routing_socket, &m_rtmsg, sizeof(m_rtmsg));
        if (rlen < 0) {
troglobit commented 10 years ago

Hi, sorry for the late reply!

This looks great. Post a git pull request and I'll merge it immediately, or you can wait for my next round of manual merges.