--- /dev/null
+/*
+ * Copyright (c) 2003-2007 Erez Zadok
+ * Copyright (c) 2003-2007 Stony Brook University
+ * Copyright (c) 2003-2007 The Research Foundation of SUNY
+ *
+ * For specific licensing information, see the COPYING file distributed with
+ * this package.
+ *
+ * This Copyright notice must be kept intact and distributed with all sources.
+ */
+
+#include <unistd.h>
+#include <linux/types.h>
+#include <linux/dirent.h>
+#include <linux/unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+//#include <asm-generic/fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#define O_LARGEFILE 00100000
+#define O_DIRECTORY 0200000
+
+/* open a open dir chdir'd into */
+int main(int argc, char *argv[])
+{
+ char *dir = argv[1];
+ char *what2open = argv[2];
+ int fd, ret = 0;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s dir what2open\n", argv[0]);
+ exit(1);
+ }
+
+#if 1
+ // NO OOPS if I skip the chdir and open(dir) directly
+ /* chdir into the dir */
+ ret = chdir(dir);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", dir, "chdir", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 1
+ /* open the dir */
+ // NO OOPS if I skip the chdir and open(dir) directly
+// fd = open(dir, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+// fd = open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+ // NO OOPS if I open(dir), but oops if I open(".") -- WTF
+ fd = open(what2open, O_RDONLY|O_DIRECTORY);
+ if (fd < 0) {
+ fprintf(stderr, "%s(%s): %s\n", ".", "open", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 1
+ /* close the dir */
+ ret = close(fd);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", ".", "close", strerror(errno));
+ exit(1);
+ }
+#endif
+ /* all's well */
+ exit(0);
+}
--- /dev/null
+/*
+ * Copyright (c) 2003-2007 Erez Zadok
+ * Copyright (c) 2003-2007 Stony Brook University
+ * Copyright (c) 2003-2007 The Research Foundation of SUNY
+ *
+ * For specific licensing information, see the COPYING file distributed with
+ * this package.
+ *
+ * This Copyright notice must be kept intact and distributed with all sources.
+ */
+
+#include <unistd.h>
+#include <linux/types.h>
+#include <linux/dirent.h>
+#include <linux/unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+//#include <asm-generic/fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#define O_LARGEFILE 00100000
+#define O_DIRECTORY 0200000
+
+/* rmdir an open dir, which we're chdir'd into */
+int main(int argc, char *argv[])
+{
+ char *dir = argv[1];
+ struct stat sbuf;
+ struct dirent dent;
+ int fd, ret = 0;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s dir2remove\n", argv[0]);
+ exit(1);
+ }
+
+#if 0
+ // NO DIFFERENCE -- STILL PANIC
+ /* try to unlink first -- should fail */
+ ret = unlink(dir);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", dir, "unlink", strerror(errno));
+ // exit(1); /* don't exit */
+ }
+#endif
+#if 0
+ // NO DIFFERENCE -- STILL PANIC
+ /* stat the dir */
+ ret = lstat(dir, &sbuf);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", dir, "lstat1", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 1
+ // NO OOPS if I skip the chdir and open(dir) directly
+ /* chdir into the dir */
+ ret = chdir(dir);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", dir, "chdir", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 0
+ // NO DIFFERENCE -- STILL PANIC
+ /* stat the cwd dir */
+ ret = lstat(".", &sbuf);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", ".", "lstat2", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 1
+ /* open the dir */
+ // NO OOPS if I skip the chdir and open(dir) directly
+// fd = open(dir, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+// fd = open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+ fd = open(".", O_RDONLY|O_DIRECTORY);
+ if (fd < 0) {
+ fprintf(stderr, "%s(%s): %s\n", ".", "open", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 0
+ // NO DIFFERENCE -- STILL PANIC EVEN IF I DONT READ THE DIR
+ /* read the dir */
+ do {
+ ret = syscall(__NR_getdents, fd, &dent, 32768);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", ".", "getdent", strerror(errno));
+ exit(1);
+ }
+ } while (ret == 0);
+#endif
+#if 1
+ /* close the dir */
+ ret = close(fd);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", ".", "close", strerror(errno));
+ exit(1);
+ }
+#endif
+#if 0
+ // NO DIFFERENCE -- STILL PANIC
+ /* rmdir the dir */
+ ret = rmdir(dir);
+ if (ret < 0) {
+ fprintf(stderr, "%s(%s): %s\n", dir, "rmdir", strerror(errno));
+ exit(1);
+ }
+#endif
+ /* all's well */
+ fprintf(stderr, "%s: removed successfully\n", dir);
+ exit(0);
+}