572af84fc753e0423b632dafb3921f76ba7f002a
1 /* Misc util functions */
3 char const *cvs_id_util
= "$Id: util.c,v 1.4 2004-11-02 04:35:04 bodea Exp $";
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
19 char *inet_toa(unsigned long addr
)
22 memcpy(&in
, &addr
, sizeof(unsigned long));
26 void *shared_malloc(unsigned int size
)
29 p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
| MAP_ANONYMOUS
, 0, 0);
37 extern int udpfd
, tunfd
, snoopfd
, ifrfd
, cluster_sockfd
;
40 pid_t
fork_and_close()
48 if (config
->scheduler_fifo
)
50 struct sched_param params
= {0};
51 params
.sched_priority
= 0;
52 if (sched_setscheduler(0, SCHED_OTHER
, ¶ms
))
54 log(0, 0, 0, 0, "Error setting scheduler to OTHER after fork: %s\n", strerror(errno
));
55 log(0, 0, 0, 0, "This is probably really really bad.\n");
59 signal(SIGPIPE
, SIG_DFL
);
60 signal(SIGCHLD
, SIG_DFL
);
61 signal(SIGHUP
, SIG_DFL
);
62 signal(SIGUSR1
, SIG_DFL
);
63 signal(SIGQUIT
, SIG_DFL
);
64 signal(SIGKILL
, SIG_DFL
);
65 signal(SIGALRM
, SIG_DFL
);
66 signal(SIGTERM
, SIG_DFL
);
69 if (udpfd
) close(udpfd
); udpfd
= 0;
70 if (tunfd
) close(tunfd
); tunfd
= 0;
71 if (snoopfd
) close(snoopfd
); snoopfd
= 0;
72 for (i
= 0; i
< config
->num_radfds
; i
++)
73 if (radfds
[i
]) close(radfds
[i
]);
74 if (ifrfd
) close(ifrfd
); ifrfd
= 0;
75 if (cluster_sockfd
) close(cluster_sockfd
); cluster_sockfd
= 0;
76 if (clifd
) close(clifd
); clifd
= 0;
78 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
79 if (bgp_peers
[i
].sock
!= -1)
80 close(bgp_peers
[i
].sock
);