|
From: <sv...@va...> - 2008-05-27 12:33:26
|
Author: bart Date: 2008-05-27 13:33:29 +0100 (Tue, 27 May 2008) New Revision: 8133 Log: Make the fdleak regression tests less system dependent. Added: trunk/none/tests/fdleak.h Modified: trunk/none/tests/fdleak_cmsg.c trunk/none/tests/fdleak_creat.c trunk/none/tests/fdleak_dup.c trunk/none/tests/fdleak_dup2.c trunk/none/tests/fdleak_fcntl.c trunk/none/tests/fdleak_ipv4.c trunk/none/tests/fdleak_open.c trunk/none/tests/fdleak_pipe.c trunk/none/tests/fdleak_socketpair.c Added: trunk/none/tests/fdleak.h =================================================================== --- trunk/none/tests/fdleak.h (rev 0) +++ trunk/none/tests/fdleak.h 2008-05-27 12:33:29 UTC (rev 8133) @@ -0,0 +1,15 @@ +#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_ */ Modified: trunk/none/tests/fdleak_cmsg.c =================================================================== --- trunk/none/tests/fdleak_cmsg.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_cmsg.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -27,8 +27,8 @@ #include <unistd.h> #include <stdlib.h> #include <errno.h> +#include "fdleak.h" - char filea[24]; char fileb[24]; char sock[24]; @@ -179,13 +179,13 @@ { 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); sprintf(fileb, "/tmp/data2.%d", pid); Modified: trunk/none/tests/fdleak_creat.c =================================================================== --- trunk/none/tests/fdleak_creat.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_creat.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,19 +1,19 @@ #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); unlink(filename); Modified: trunk/none/tests/fdleak_dup.c =================================================================== --- trunk/none/tests/fdleak_dup.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_dup.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,18 +1,18 @@ #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); return 0; Modified: trunk/none/tests/fdleak_dup2.c =================================================================== --- trunk/none/tests/fdleak_dup2.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_dup2.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,19 +1,19 @@ #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); Modified: trunk/none/tests/fdleak_fcntl.c =================================================================== --- trunk/none/tests/fdleak_fcntl.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_fcntl.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,19 +1,19 @@ #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"); return 0; Modified: trunk/none/tests/fdleak_ipv4.c =================================================================== --- trunk/none/tests/fdleak_ipv4.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_ipv4.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -8,7 +8,7 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> - +#include "fdleak.h" void server () { @@ -89,13 +89,13 @@ { 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(); return 0; Modified: trunk/none/tests/fdleak_open.c =================================================================== --- trunk/none/tests/fdleak_open.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_open.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,15 +1,15 @@ #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; } Modified: trunk/none/tests/fdleak_pipe.c =================================================================== --- trunk/none/tests/fdleak_pipe.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_pipe.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,17 +1,17 @@ #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; } Modified: trunk/none/tests/fdleak_socketpair.c =================================================================== --- trunk/none/tests/fdleak_socketpair.c 2008-05-26 17:16:08 UTC (rev 8132) +++ trunk/none/tests/fdleak_socketpair.c 2008-05-27 12:33:29 UTC (rev 8133) @@ -1,17 +1,17 @@ #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; } |