1 /* Misc util functions */
3 char const *cvs_id_util
= "$Id: util.c,v 1.9 2004-12-20 07:23:53 bodea Exp $";
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
19 // format ipv4 addr as a dotted-quad; n chooses one of 4 static buffers
21 char *fmtaddr(in_addr_t addr
, int n
)
23 static char addrs
[4][16];
26 if (n
< 0 || n
>= 4) return "";
28 return strcpy(addrs
[n
], inet_ntoa(in
));
31 void *shared_malloc(unsigned int size
)
34 p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
| MAP_ANONYMOUS
, 0, 0);
43 extern int udpfd
, controlfd
, tunfd
, snoopfd
, ifrfd
, cluster_sockfd
;
46 pid_t
fork_and_close()
55 if (config
->scheduler_fifo
)
57 struct sched_param params
= {0};
58 params
.sched_priority
= 0;
59 if (sched_setscheduler(0, SCHED_OTHER
, ¶ms
))
61 LOG(0, 0, 0, "Error setting scheduler to OTHER after fork: %s\n", strerror(errno
));
62 LOG(0, 0, 0, "This is probably really really bad.\n");
66 signal(SIGPIPE
, SIG_DFL
);
67 signal(SIGCHLD
, SIG_DFL
);
68 signal(SIGHUP
, SIG_DFL
);
69 signal(SIGUSR1
, SIG_DFL
);
70 signal(SIGQUIT
, SIG_DFL
);
71 signal(SIGKILL
, SIG_DFL
);
72 signal(SIGALRM
, SIG_DFL
);
73 signal(SIGTERM
, SIG_DFL
);
76 if (tunfd
!= -1) close(tunfd
);
77 if (udpfd
!= -1) close(udpfd
);
78 if (controlfd
!= -1) close(controlfd
);
79 if (snoopfd
!= -1) close(snoopfd
);
80 if (ifrfd
!= -1) close(ifrfd
);
81 if (cluster_sockfd
!= -1) close(cluster_sockfd
);
82 if (clifd
!= -1) close(clifd
);
84 for (i
= 0; radfds
&& i
< config
->num_radfds
; i
++)
87 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
88 if (bgp_peers
[i
].sock
!= -1)
89 close(bgp_peers
[i
].sock
);