return 0;
}
+int
+set_cloexec(int fd)
+{
+ int flags;
+ flags = fcntl(fd, F_GETFD, 0);
+ if (flags == -1)
+ return -1;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return -1;
+ return 0;
+}
+
float
htonf (float host)
{
-1 on error. */
extern int set_nonblocking(int fd);
+extern int set_cloexec(int fd);
+
/* Does the I/O error indicate that the operation should be retried later? */
#define ERRNO_IO_RETRY(EN) \
(((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
#include <fcntl.h>
#include <log.h>
#include "version.h"
+#include "network.h"
#define PIDFILE_MASK 0644
#ifndef HAVE_FCNTL
umask(oldumask);
memset (&lock, 0, sizeof(lock));
+ set_cloexec(fd);
+
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
return -1;
}
set_nonblocking(vty_sock);
+ set_cloexec(vty_sock);
sockunion2hostprefix (&su, &p);
sockopt_v6only (ainfo->ai_family, sock);
sockopt_reuseaddr (sock);
sockopt_reuseport (sock);
+ set_cloexec (sock);
ret = bind (sock, ainfo->ai_addr, ainfo->ai_addrlen);
if (ret < 0)
/* This is server, so reuse address. */
sockopt_reuseaddr (accept_sock);
sockopt_reuseport (accept_sock);
+ set_cloexec (accept_sock);
/* Bind socket to universal address and given port. */
ret = sockunion_bind (accept_sock, &su, port, naddr);
len = sizeof (serv.sun_family) + strlen (serv.sun_path);
#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
+ set_cloexec (sock);
+
ret = bind (sock, (struct sockaddr *) &serv, len);
if (ret < 0)
{
close (sock);
return -1;
}
-
+ set_cloexec(sock);
+
#ifdef VTYSH_DEBUG
printf ("VTY shell accept\n");
#endif /* VTYSH_DEBUG */