diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-09-28 21:39:30 -0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-09-28 21:39:30 -0400 |
commit | e666e1156fba936dce93ccfa2486f67369a97129 (patch) | |
tree | 78bb14c66b321796e598cba4d7def419fa04379d | |
parent | f406288cc7cf648001a40b0a96cb97c31347cc5a (diff) | |
download | guix-e666e1156fba936dce93ccfa2486f67369a97129.tar.gz |
Handle octal escapes in /proc/self/mountinfo
-rw-r--r-- | src/libstore/build.cc | 5 | ||||
-rw-r--r-- | src/libutil/util.cc | 15 | ||||
-rw-r--r-- | src/libutil/util.hh | 6 |
3 files changed, 24 insertions, 2 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index ca66be3b41..fecee04d54 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1914,8 +1914,9 @@ void DerivationGoal::initChild() Strings mounts = tokenizeString<Strings>(readFile("/proc/self/mountinfo", true), "\n"); foreach (Strings::iterator, i, mounts) { vector<string> fields = tokenizeString<vector<string> >(*i, " "); - if (mount(0, fields.at(4).c_str(), 0, MS_PRIVATE, 0) == -1) - throw SysError(format("unable to make filesystem `%1%' private") % fields.at(4)); + string fs = decodeOctalEscaped(fields.at(4)); + if (mount(0, fs.c_str(), 0, MS_PRIVATE, 0) == -1) + throw SysError(format("unable to make filesystem `%1%' private") % fs); } /* Bind-mount all the directories from the "host" diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 7f95d39814..afb0dc0b2c 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1101,6 +1101,21 @@ bool endOfList(std::istream & str) } +string decodeOctalEscaped(const string & s) +{ + string r; + for (string::const_iterator i = s.begin(); i != s.end(); ) { + if (*i != '\\') { r += *i++; continue; } + unsigned char c = 0; + ++i; + while (i != s.end() && *i >= '0' && *i < '8') + c = c * 8 + (*i++ - '0'); + r += c; + } + return r; +} + + void ignoreException() { try { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 408d99a96e..d3861f730b 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -332,6 +332,12 @@ string parseString(std::istream & str); bool endOfList(std::istream & str); +/* Escape a string that contains octal-encoded escape codes such as + used in /etc/fstab and /proc/mounts (e.g. "foo\040bar" decodes to + "foo bar"). */ +string decodeOctalEscaped(const string & s); + + /* Exception handling in destructors: print an error message, then ignore the exception. */ void ignoreException(); |