#endif
#include <ctype.h>
#include <errno.h>
-#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#endif
/* Close our fd's */
-void close_fds (void)
+int close_fds (void)
{
int fd;
if ((fd = open ("/dev/null", O_RDWR)) == -1) {
logger (LOG_ERR, "open `/dev/null': %s", strerror (errno));
- return;
+ return (-1);
}
dup2 (fd, fileno (stdin));
dup2 (fd, fileno (stderr));
if (fd > 2)
close (fd);
+ return (0);
+}
+
+int close_on_exec (int fd)
+{
+ int flags;
+
+ if ((flags = fcntl (fd, F_GETFD, 0)) == -1
+ || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ {
+ logger (LOG_ERR, "fcntl: %s", strerror (errno));
+ return (-1);
+ }
+ return (0);
}
/* Handy function to get the time.
void srandomdev (void);
#endif
-void close_fds (void);
+int close_fds (void);
+int close_on_exec (int fd);
char *get_line (FILE *fp);
int get_time (struct timeval *tp);
time_t uptime (void);
static route_t *decode_CSR(const unsigned char *p, int len)
{
const unsigned char *q = p;
- int cidr;
- int ocets;
+ unsigned int cidr;
+ unsigned int ocets;
route_t *first;
route_t *route;
#include <sys/socket.h>
#include <sys/select.h>
#include <errno.h>
-#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
+#include "common.h"
#include "logger.h"
#include "signal.h"
* and installs the signal handler */
int signal_init (void)
{
- unsigned int i;
- int flags;
struct sigaction sa;
if (pipe (signal_pipe) == -1) {
}
/* Stop any scripts from inheriting us */
- for (i = 0; i < 2; i++)
- if ((flags = fcntl (signal_pipe[i], F_GETFD, 0)) == -1 ||
- fcntl (signal_pipe[i], F_SETFD, flags | FD_CLOEXEC) == -1)
- logger (LOG_ERR ,"fcntl: %s", strerror (errno));
+ close_on_exec (signal_pipe[0]);
+ close_on_exec (signal_pipe[1]);
/* Ignore child signals and don't make zombies.
* Because we do this, we don't need to be in signal_setup */
#include <netinet/udp.h>
#include <arpa/inet.h>
#include <errno.h>
-#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return -1;
}
- if ((flags = fcntl (fd, F_GETFD, 0)) == -1
- || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
- {
- logger (LOG_ERR, "fcntl: %s", strerror (errno));
- close (fd);
- return -1;
- }
+ close_on_exec (fd);
memset (&ifr, 0, sizeof (ifr));
strlcpy (ifr.ifr_name, iface->name, sizeof (ifr.ifr_name));
int open_socket (interface_t *iface, int protocol)
{
int fd;
- int flags;
union sockunion {
struct sockaddr sa;
struct sockaddr_ll sll;
return (-1);
}
- if ((flags = fcntl (fd, F_GETFD, 0)) == -1
- || fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
- {
- logger (LOG_ERR, "fcntl: %s", strerror (errno));
- close (fd);
- return (-1);
- }
+ close_on_exec (fd);
memset (&su, 0, sizeof (su));
su.sll.sll_family = PF_PACKET;