about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/serialise.cc7
-rw-r--r--src/libutil/types.hh2
-rw-r--r--src/libutil/util.cc17
-rw-r--r--src/libutil/util.hh17
4 files changed, 24 insertions, 19 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 969f638ef408..c0e1c17af066 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -85,10 +85,11 @@ unsigned int readInt(Source & source)
 string readString(Source & source)
 {
     unsigned int len = readInt(source);
-    char buf[len];
-    source((unsigned char *) buf, len);
+    unsigned char * buf = new unsigned char[len];
+    AutoDeleteArray<unsigned char> d(buf);
+    source(buf, len);
     readPadding(len, source);
-    return string(buf, len);
+    return string((char *) buf, len);
 }
 
  
diff --git a/src/libutil/types.hh b/src/libutil/types.hh
index 1de378961e46..257871a82b35 100644
--- a/src/libutil/types.hh
+++ b/src/libutil/types.hh
@@ -44,8 +44,6 @@ public:
         newClass(const format & f) : superClass(f) { }; \
     };
 
-MakeError(UsageError, Error)
-
 
 typedef list<string> Strings;
 typedef set<string> StringSet;
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 7c1138720cd3..08385e5d96e0 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -191,18 +191,6 @@ Strings readDirectory(const Path & path)
 }
 
 
-template <class T>
-struct AutoDeleteArray
-{
-    T * p;
-    AutoDeleteArray(T * p) : p(p) { }
-    ~AutoDeleteArray() 
-    {
-        delete [] p;
-    }
-};
-
-
 string readFile(int fd)
 {
     struct stat st;
@@ -468,7 +456,7 @@ void readFull(int fd, unsigned char * buf, size_t count)
             if (errno == EINTR) continue;
             throw SysError("reading from file");
         }
-        if (res == 0) throw Error("unexpected end-of-file");
+        if (res == 0) throw EndOfFile("unexpected end-of-file");
         count -= res;
         buf += res;
     }
@@ -707,6 +695,7 @@ int Pid::wait(bool block)
         if (res == 0 && !block) return -1;
         if (errno != EINTR)
             throw SysError("cannot get child exit status");
+        checkInterrupt();
     }
 }
 
@@ -793,7 +782,7 @@ void _interrupted()
        kills the program! */
     if (!std::uncaught_exception()) {
         _isInterrupted = 0;
-        throw Error("interrupted by the user");
+        throw Interrupted("interrupted by the user");
     }
 }
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 0d39ffee9eae..b88508dec30d 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -139,6 +139,8 @@ extern void (*writeToStderr) (const unsigned char * buf, size_t count);
 void readFull(int fd, unsigned char * buf, size_t count);
 void writeFull(int fd, const unsigned char * buf, size_t count);
 
+MakeError(EndOfFile, Error)
+
 
 /* Read a file descriptor until EOF occurs. */
 string drainFD(int fd);
@@ -147,6 +149,19 @@ string drainFD(int fd);
 
 /* Automatic cleanup of resources. */
 
+
+template <class T>
+struct AutoDeleteArray
+{
+    T * p;
+    AutoDeleteArray(T * p) : p(p) { }
+    ~AutoDeleteArray() 
+    {
+        delete [] p;
+    }
+};
+
+
 class AutoDelete
 {
     string path;
@@ -229,6 +244,8 @@ void inline checkInterrupt()
     if (_isInterrupted) _interrupted();
 }
 
+MakeError(Interrupted, Error)
+
 
 /* String packing / unpacking. */
 string packStrings(const Strings & strings);