1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
commit 162f2692c399b93311652201a940fdaf9c9e6924
Author: Peter Seebach <peter.seebach@windriver.com>
Date: Thu Feb 2 11:45:42 2012 -0600
Make opendir/closedir stash and forget directory names.
The dirfd(DIR *) interface allows you to get the fd for a DIR *,
meaning you can use it with openat(), meaning you can need its
path. This causes a segfault. Also gonna fix the base_path
code not to segfault in that case, but first fix the underlying
problem.
Upstream-Status: Backport
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 4de488c..9625b38 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,7 @@
+2012-02-02:
+ * (seebs) stash dir name for DIR * from opendir using dirfd.
+ * (seebs) add closedir.
+
2011-11-02:
* (seebs) Call this 1.2 because the UNLOAD change is moderately
significant, and so's the clone change.
diff --git a/ports/unix/guts/closedir.c b/ports/unix/guts/closedir.c
new file mode 100644
index 0000000..1085361
--- /dev/null
+++ b/ports/unix/guts/closedir.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012 Wind River Systems; see
+ * guts/COPYRIGHT for information.
+ *
+ * static int
+ * wrap_closedir(DIR *dirp) {
+ * int rc = -1;
+ */
+ if (!dirp) {
+ errno = EFAULT;
+ return -1;
+ }
+
+ int fd = dirfd(dirp);
+ pseudo_client_op(OP_CLOSE, 0, fd, -1, 0, 0);
+ rc = real_closedir(dirp);
+
+/* return rc;
+ * }
+ */
diff --git a/ports/unix/guts/opendir.c b/ports/unix/guts/opendir.c
index 8eaa71f..e69717e 100644
--- a/ports/unix/guts/opendir.c
+++ b/ports/unix/guts/opendir.c
@@ -6,8 +6,25 @@
* wrap_opendir(const char *path) {
* DIR * rc = NULL;
*/
+ struct stat buf;
+ int save_errno;
rc = real_opendir(path);
+ if (rc) {
+ int fd;
+ save_errno = errno;
+ fd = dirfd(rc);
+ if (real_fstat(fd, &buf) == -1) {
+ pseudo_debug(1, "diropen (fd %d) succeeded, but fstat failed (%s).\n",
+ fd, strerror(errno));
+ pseudo_client_op_plain(OP_OPEN, PSA_READ, fd, -1, path, 0);
+ } else {
+ pseudo_client_op_plain(OP_OPEN, PSA_READ, fd, -1, path, &buf);
+ }
+
+
+ errno = save_errno;
+ }
/* return rc;
* }
diff --git a/ports/unix/wrapfuncs.in b/ports/unix/wrapfuncs.in
index e06e404..32250c4 100644
--- a/ports/unix/wrapfuncs.in
+++ b/ports/unix/wrapfuncs.in
@@ -21,6 +21,7 @@ long pathconf(const char *path, int name);
char *realpath(const char *name, char *resolved_name); /* version="GLIBC_2.3" */
int remove(const char *path); /* flags=AT_SYMLINK_NOFOLLOW */
DIR *opendir(const char *path);
+int closedir(DIR *dirp);
char *tempnam(const char *template, const char *pfx);
char *tmpnam(char *s);
int truncate(const char *path, off_t length);
|