* Daemon mode (`nix-worker --daemon'). Clients connect to the server
via the Unix domain socket in /nix/var/nix/daemon.socket. The server forks a worker process per connection. * readString(): use the heap, not the stack. * Some protocol fixes.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ public:
|
||||
newClass(const format & f) : superClass(f) { }; \
|
||||
};
|
||||
|
||||
MakeError(UsageError, Error)
|
||||
|
||||
|
||||
typedef list<string> Strings;
|
||||
typedef set<string> StringSet;
|
||||
|
||||
+3
-14
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user