monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone: d23dbf2ce78cd11fc1a1dc85cd7


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone: d23dbf2ce78cd11fc1a1dc85cd78cc28ab2df8ca
Date: Mon, 11 Mar 2013 21:49:10 +0100 (CET)

revision:            d23dbf2ce78cd11fc1a1dc85cd78cc28ab2df8ca
date:                2013-03-11T11:36:57
author:              address@hidden
branch:              net.venge.monotone
changelog:
Move the getcwd / MAXPATHLEN work-around from netxx/serverbase.cc
to unix/fs.cc. Meaning we a) don't rely on a hard-coded buffer
size of 4096 bytes anymore in that code path and b) get more test
coverage for the work-around.

manifest:
format_version "1"

new_manifest [19d36c30752a75790f4683a0793a40f69110193f]

old_revision [7b87eec0dc2298a18531b95c1cd2d1b72986e71c]

patch "src/netxx/serverbase.cxx"
 from [156f2090341d2a36bdb718e7c69df58f9251983e]
   to [efaec5b590ba58147d17d7d17adf9a41b9d305d2]

patch "src/unix/fs.cc"
 from [f51cae4dbc5589b0add4f7b9b649fde3c83d1220]
   to [532f2f3738853ad53cbb58cb6bcaea98f3871c8f]
============================================================
--- src/netxx/serverbase.cxx	156f2090341d2a36bdb718e7c69df58f9251983e
+++ src/netxx/serverbase.cxx	efaec5b590ba58147d17d7d17adf9a41b9d305d2
@@ -46,6 +46,9 @@
 
 #include <cerrno>
 
+// Monotone specific, for get_current_working_dir()
+#include <src/platform.hh>
+
 // standard includes
 #include <map>
 #include <vector>
@@ -169,27 +172,16 @@ void Netxx::ServerBase::bind_to(const Ad
 		if (saun->sun_path[0] == '/') {
 		    files_.push_back(saun->sun_path);
 		} else {
-		    // BIG FAT WARNING: THIS CODE HAS NOT BEEN TESTED!
-		    // The original code is non-dynamic, depending on
-		    // the value of MAXPATHLEN.  Since that macro isn't
-		    // guaranteed to exist, a more dynamic use if getcwd()
-		    // was written.  However, since monotone doesn't use
-		    // AF_LOCAL sockets, this code will not be reached.
-		    int e = ERANGE;
-		    int n = 4096;
-
-		    while (e == ERANGE) {
-			char buffer[n];
-			e = 0;
-			n += 4096;
-
-			if (getcwd(buffer, n)) {
-			    std::string fullpath = buffer; fullpath += '/'; fullpath += saun->sun_path;
-			    files_.push_back(fullpath);
-			} else if ((e = errno) != ERANGE) {
-			    files_.push_back(saun->sun_path);
-			}
-		    }
+		    /*
+		     * the original (netxx) code here relied on MAXPATHLEN,
+		     * which isn't defined on hurd. As netxx seems to only
+		     * live on within monotone, we can as well make it
+		     * inter-dependent. And the unix/fs.cc variant certainly
+		     * gets more test mileage than anything special here.
+		     */
+		    std::string fullpath = get_current_working_dir();
+		    fullpath += '/'; fullpath += saun->sun_path;
+		    files_.push_back(fullpath);
 		}
 	    }
 #	endif
============================================================
--- src/unix/fs.cc	f51cae4dbc5589b0add4f7b9b649fde3c83d1220
+++ src/unix/fs.cc	532f2f3738853ad53cbb58cb6bcaea98f3871c8f
@@ -44,14 +44,26 @@ get_current_working_dir()
 string
 get_current_working_dir()
 {
-  char buffer[4096];
-  if (!getcwd(buffer, 4096))
+  std::vector<char> cwd_buf;
+  size_t cwd_sz = 4096;
+
+  // This funny loop prevents having to specify a MAXPATHLEN or similar, but
+  // uses a dynamic approach, repeatedly calling getcwd() until our buffer
+  // is big enough for the current path to fit. Think of it as a portable
+  // replacement for get_current_dir_name(), which is GNU-only.
+  do
     {
-      const int err = errno;
-      E(false, origin::system,
-        F("cannot get working directory: %s") % os_strerror(err));
+      cwd_buf.resize(cwd_sz);
+      cwd_sz += 4096;
+
+      if (getcwd(&cwd_buf[0], cwd_sz))
+        return string(&cwd_buf[0]);
     }
-  return string(buffer);
+  while (errno == ERANGE);
+
+  const int err = errno;
+  E(false, origin::system,
+    F("cannot get working directory: %s") % os_strerror(err));
 }
 
 void

reply via email to

[Prev in Thread] Current Thread [Next in Thread]