2929#include "../../dprint.h"
3030#include "../../timer.h"
3131
32+ #include "../rtpproxy/rtpproxy.h"
33+ #include "../rtpproxy/notification_process.h"
3234#include "rtp_io.h"
3335#include "rtp_io_util.h"
3436#include "rtp_io_params.h"
@@ -40,7 +42,7 @@ static void mod_destroy(void);
4042
4143static const dep_export_t deps = {
4244 { /* OpenSIPS module dependencies */
43- { MOD_TYPE_DEFAULT , "rtpproxy" , DEP_SILENT |DEP_REVERSE },
45+ { MOD_TYPE_DEFAULT , "rtpproxy" , ( DEP_SILENT |DEP_REVERSE ) & (~ DEP_REVERSE_CINIT ) },
4446 { MOD_TYPE_NULL , NULL , 0 },
4547 },
4648 { /* modparam dependencies */
@@ -49,12 +51,14 @@ static const dep_export_t deps = {
4951};
5052
5153static int rtp_io_getchildsock (int );
54+ static int rtp_io_getrnsock (struct rtpp_notify_cfg * );
5255
5356/*
5457 * Exported functions
5558 */
5659static const cmd_export_t cmds [] = {
5760 {"rtp_io_getchildsock" , (cmd_function )rtp_io_getchildsock , {0 }, 0 },
61+ {"rtp_io_getrnsock" , (cmd_function )rtp_io_getrnsock , {0 }, 0 },
5862 {0 }
5963};
6064
@@ -162,17 +166,29 @@ static int mod_init(void)
162166 ENV_ADD (argv_stat [i ], e1 );
163167 }
164168
169+ struct rtpp_n_sock * n_sock = & rpi_descp -> n_sock ;
170+ int * fdp = n_sock -> _fds ;
171+ if (socketpair (AF_UNIX , SOCK_STREAM , 0 , fdp ) < 0 )
172+ goto e1 ;
173+ snprintf (n_sock -> _name , sizeof (n_sock -> _name ), "fd:%d" , n_sock -> fds .rtpp );
174+ n_sock -> name .s = n_sock -> _name ;
175+ n_sock -> name .len = strlen (n_sock -> _name );
176+ ENV_ADD ("-n" , e2 );
177+ ENV_ADD ("%s" , e2 , n_sock -> name .s );
165178 for (int i = 0 ; i < nsocks ; i ++ ) {
166179 int * fdp = & rpi_descp -> socks -> holder [i * 2 ];
167180 if (socketpair (AF_UNIX , SOCK_STREAM , 0 , fdp ) < 0 )
168- goto e1 ;
169- ENV_ADD ("-s" , e1 );
170- ENV_ADD ("fd:%d" , e1 , fdp [0 ]);
181+ goto e2 ;
182+ ENV_ADD ("-s" , e2 );
183+ ENV_ADD ("fd:%d" , e2 , fdp [0 ]);
171184 }
172185
173186 rpi_descp -> socks -> n = nsocks ;
174187
175188 return 0 ;
189+ e2 :
190+ close (n_sock -> _fds [0 ]);
191+ close (n_sock -> _fds [1 ]);
176192e1 :
177193 free (rpi_descp -> socks );
178194e0 :
@@ -198,6 +214,7 @@ void mod_destroy(void)
198214 }
199215 rtp_io_close_serv_socks ();
200216 rtp_io_close_cnlt_socks ();
217+ rtp_io_close_cnlt_nsock ();
201218 free (rpi_descp -> socks );
202219}
203220
@@ -206,11 +223,25 @@ void mod_destroy(void)
206223static int
207224child_init (int rank )
208225{
226+ rtpproxy_is_nproc_t is_nproc_f ;
227+
228+ is_nproc_f = (rtpproxy_is_nproc_t )find_export ("rtpproxy_is_nproc" , 0 );
229+ if (is_nproc_f == NULL ) {
230+ LM_ERR ("rtpproxy_is_nproc() not found in the rtpproxy module\n" );
231+ return -1 ;
232+ }
233+ int is_nproc = is_nproc_f (NPROC_CHECK );
234+ LM_DBG ("rtp.io: child_init(%d), notifier: %d\n" , rank , is_nproc );
209235 if (rank > rpi_descp -> socks -> n ) {
210236 LM_ERR ("BUG: rank is higher than the number of sockets!\n" );
211237 return -1 ;
212238 }
213239
240+ if (!is_nproc && rtp_io_close_cnlt_nsock () != 0 ) {
241+ LM_ERR ("rtp_io_close_cnlt_nsock() failed\n" );
242+ return -1 ;
243+ }
244+
214245 if (rank <= 0 ) {
215246 if (rtp_io_close_cnlt_socks () != 0 ) {
216247 LM_ERR ("rtp_io_close_cnlt_socks() failed\n" );
@@ -240,3 +271,12 @@ static int rtp_io_getchildsock(int rank)
240271 int * fdp = & rpi_descp -> socks -> holder [(rank - 1 ) * 2 ];
241272 return (fdp [1 ]);
242273}
274+
275+ static int rtp_io_getrnsock (struct rtpp_notify_cfg * rn_cfg )
276+ {
277+
278+ rn_cfg -> name = rpi_descp -> n_sock .name ;
279+ rn_cfg -> sock .rn_umode = CM_RTPIO ;
280+ rn_cfg -> sock .fd = rpi_descp -> n_sock .fds .osips ;
281+ return (0 );
282+ };
0 commit comments