From: Eric Blake <eblake@redhat.com>
Date: Tue, 26 Apr 2011 21:07:07 +0000 (-0600)
Subject: save-cwd: reduce default dependency
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c631b51b5f5908decfb7c0da1f94715d6b66c33;p=pspp

save-cwd: reduce default dependency

save-cwd generally needs only a working fchdir or a working
getcwd(NULL,0).  If you are not worried about directories whose
absolute name is longer than PATH_MAX, then reducing the default
dependencies reduces the bulk for this module.

However, there are cases where neither function works on Linux
(an unreadable but searchable directory can be opened by O_SEARCH,
except that Linux doesn't implement that yet; and Linux getcwd()
has issues with long absolute names which glibc does not work
around but which the full-blown getcwd module does).  So someone
desiring a truly robust solution needs to import the 'getcwd'
module at the same time as 'save-cwd'.

* modules/save-cwd (Depends-on): Use getcwd-lgpl.
* lib/save-cwd.c: Update comments.
* NEWS: Document the semantic change.

Signed-off-by: Eric Blake <eblake@redhat.com>
---

diff --git a/ChangeLog b/ChangeLog
index 8cef5ecf43..2b6b0639cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2011-04-26  Eric Blake  <eblake@redhat.com>
+2011-04-27  Eric Blake  <eblake@redhat.com>
+
+	save-cwd: reduce default dependency
+	* modules/save-cwd (Depends-on): Use getcwd-lgpl.
+	* lib/save-cwd.c: Update comments.
+	* NEWS: Document the semantic change.
 
 	getcwd: enhance tests
 	* tests/test-getcwd-lgpl.c: New file, taken from...
@@ -9,8 +14,6 @@
 	* m4/getcwd-abort-bug.m4: Update comment.
 	* m4/getcwd-path-max.m4: Likewise.
 
-2011-04-27  Eric Blake  <eblake@redhat.com>
-
 	getcwd-lgpl: new module
 	* modules/getcwd-lgpl: New module.
 	* lib/getcwd-lgpl.c: New file.
diff --git a/NEWS b/NEWS
index 7dd126dac6..5081dbaa82 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,11 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2011-04-27  save-cwd        This module pulls in fewer dependencies by
+                            default; to retain robust handling of directories
+                            with an absolute name longer than PATH_MAX, you
+                            must now explicitly include the 'getcwd' module.
+
 2011-04-19  close-hook      This module has been renamed to 'fd-hook' and
                             generalized.
 
diff --git a/lib/save-cwd.c b/lib/save-cwd.c
index 16ffa2c490..5f8eb7ca53 100644
--- a/lib/save-cwd.c
+++ b/lib/save-cwd.c
@@ -50,7 +50,8 @@
    The `raison d'etre' for this interface is that the working directory
    is sometimes inaccessible, and getcwd is not robust or as efficient.
    So, we prefer to use the open/fchdir approach, but fall back on
-   getcwd if necessary.
+   getcwd if necessary.  This module works for most cases with just
+   the getcwd-lgpl module, but to be truly robust, use the getcwd module.
 
    Some systems lack fchdir altogether: e.g., OS/2, pre-2001 Cygwin,
    SCO Xenix.  Also, SunOS 4 and Irix 5.3 provide the function, yet it
diff --git a/modules/save-cwd b/modules/save-cwd
index 02a0723391..974b5962c1 100644
--- a/modules/save-cwd
+++ b/modules/save-cwd
@@ -9,7 +9,7 @@ m4/save-cwd.m4
 Depends-on:
 chdir-long
 cloexec
-getcwd
+getcwd-lgpl
 fchdir
 stdbool
 unistd-safer