--- /dev/null
+#ifndef _FDLEAK_H_
+#define _FDLEAK_H_
+
+/*
+ * The macro below closes file descriptors inherited from the process
+ * that forked the current process. Close these file descriptors right
+ * after the start of main() in order to get consistent results across
+ * different releases. Known behavior:
+ * - Fedora Core 1's Perl opens /dev/pts/2 as fd 10.
+ * - For Ubuntu 8.04, see also
+ * https://bugs.launchpad.net/ubuntu/+source/seahorse/+bug/235184
+ */
+#define CLOSE_INHERITED_FDS { int i; for (i = 3; i < 64; i++) close(i); }
+
+#endif /* _FDLEAK_H_ */
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
-
+#include "fdleak.h"
char filea[24];
char fileb[24];
{
int pid, status;
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+
+
+ CLOSE_INHERITED_FDS;
pid = getpid();
sprintf(filea, "/tmp/data1.%d", pid);
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
-
+#include "fdleak.h"
int
main (int argc, char **argv)
{
char filename[24];
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+
+
+ CLOSE_INHERITED_FDS;
sprintf(filename, "/tmp/file.%d\n", getpid());
creat(filename, 0);
#include <unistd.h>
#include <fcntl.h>
-
+#include "fdleak.h"
int
main (int argc, char **argv)
{
int s;
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+
+
+ CLOSE_INHERITED_FDS;
s = open("/dev/null", O_RDONLY);
dup(s);
#include <unistd.h>
#include <fcntl.h>
-
+#include "fdleak.h"
int
main (int argc, char **argv)
{
int s1;
int s2;
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+
+
+ CLOSE_INHERITED_FDS;
s1 = open("/dev/null", O_RDONLY);
s2 = open("/dev/null", O_RDONLY);
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
-
+#include "fdleak.h"
int
main (int argc, char **argv)
{
int s1;
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+
+
+ CLOSE_INHERITED_FDS;
s1 = open("/dev/null", O_RDONLY);
if(fcntl(s1, F_DUPFD, s1) == -1) perror("fcntl");
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-
+#include "fdleak.h"
void
server ()
{
{
int pid, status;
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+
+
+ CLOSE_INHERITED_FDS;
if((pid = fork()) == 0) {
server();
#include <fcntl.h>
#include <unistd.h>
+#include "fdleak.h"
+
int
main (int argc, char **argv)
{
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+ CLOSE_INHERITED_FDS;
open("/dev/null", O_RDONLY);
return 0;
#include <unistd.h>
-
+#include "fdleak.h"
int
main (int argc, char **argv)
{
int fds[2];
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10);
+
+
+
+
+ CLOSE_INHERITED_FDS;
pipe(fds);
return 0;
#include <sys/socket.h>
#include <unistd.h>
+#include "fdleak.h"
+
int
main (int argc, char **argv)
{
int fds[2];
- /*
- * Fedora Core 1's Perl opens /dev/pts/2 as fd 10. Let's close it
- * now to get consistent results across different releases.
- */
- close(10); close(4);
+
+
+ CLOSE_INHERITED_FDS;
socketpair(AF_UNIX, SOCK_STREAM, PF_UNIX, fds);
return 0;