Whitespace

This commit is contained in:
Eelco Dolstra 2012-07-30 17:13:25 -04:00
parent 9cd63d2244
commit d50d7a2874
4 changed files with 61 additions and 61 deletions

View file

@ -46,7 +46,7 @@ Path makeRootName(const Path & gcRoot, int & counter)
void printGCWarning() void printGCWarning()
{ {
static bool haveWarned = false; static bool haveWarned = false;
warnOnce(haveWarned, warnOnce(haveWarned,
"you did not specify `--add-root'; " "you did not specify `--add-root'; "
"the result might be removed by the garbage collector"); "the result might be removed by the garbage collector");
} }
@ -98,7 +98,7 @@ static bool showTrace = false;
static void initAndRun(int argc, char * * argv) static void initAndRun(int argc, char * * argv)
{ {
setDefaultsFromEnvironment(); setDefaultsFromEnvironment();
/* Catch SIGINT. */ /* Catch SIGINT. */
struct sigaction act; struct sigaction act;
act.sa_handler = sigintHandler; act.sa_handler = sigintHandler;
@ -137,7 +137,7 @@ static void initAndRun(int argc, char * * argv)
Strings args, remaining; Strings args, remaining;
while (argc--) args.push_back(*argv++); while (argc--) args.push_back(*argv++);
args.erase(args.begin()); args.erase(args.begin());
/* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and /* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and
ignore options for the ATerm library. */ ignore options for the ATerm library. */
for (Strings::iterator i = args.begin(); i != args.end(); ++i) { for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
@ -210,7 +210,7 @@ static void initAndRun(int argc, char * * argv)
verbosityDelta += queryIntSetting("verbosity", lvlInfo); verbosityDelta += queryIntSetting("verbosity", lvlInfo);
verbosity = (Verbosity) (verbosityDelta < 0 ? 0 : verbosityDelta); verbosity = (Verbosity) (verbosityDelta < 0 ? 0 : verbosityDelta);
run(remaining); run(remaining);
/* Close the Nix database. */ /* Close the Nix database. */
@ -228,7 +228,7 @@ static void setuidInit()
uid_t nixUid = geteuid(); uid_t nixUid = geteuid();
gid_t nixGid = getegid(); gid_t nixGid = getegid();
setuidCleanup(); setuidCleanup();
/* Don't trust the current directory. */ /* Don't trust the current directory. */
@ -294,7 +294,7 @@ int main(int argc, char * * argv)
right away. */ right away. */
if (argc == 0) abort(); if (argc == 0) abort();
setuidInit(); setuidInit();
/* Turn on buffering for cerr. */ /* Turn on buffering for cerr. */
#if HAVE_PUBSETBUF #if HAVE_PUBSETBUF
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf)); std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
@ -323,7 +323,7 @@ int main(int argc, char * * argv)
throw; throw;
} }
} catch (UsageError & e) { } catch (UsageError & e) {
printMsg(lvlError, printMsg(lvlError,
format( format(
"error: %1%\n" "error: %1%\n"
"Try `%2% --help' for more information.") "Try `%2% --help' for more information.")

View file

@ -60,7 +60,7 @@ void RemoteStore::openConnection(bool reserveSpace)
else else
throw Error(format("invalid setting for NIX_REMOTE, `%1%'") throw Error(format("invalid setting for NIX_REMOTE, `%1%'")
% remoteMode); % remoteMode);
from.fd = fdSocket; from.fd = fdSocket;
to.fd = fdSocket; to.fd = fdSocket;
@ -103,15 +103,15 @@ void RemoteStore::forkSlave()
worker = nixBinDir + "/nix-worker"; worker = nixBinDir + "/nix-worker";
child = fork(); child = fork();
switch (child) { switch (child) {
case -1: case -1:
throw SysError("unable to fork"); throw SysError("unable to fork");
case 0: case 0:
try { /* child */ try { /* child */
if (dup2(fdChild, STDOUT_FILENO) == -1) if (dup2(fdChild, STDOUT_FILENO) == -1)
throw SysError("dupping write side"); throw SysError("dupping write side");
@ -124,7 +124,7 @@ void RemoteStore::forkSlave()
execlp(worker.c_str(), worker.c_str(), "--slave", NULL); execlp(worker.c_str(), worker.c_str(), "--slave", NULL);
throw SysError(format("executing `%1%'") % worker); throw SysError(format("executing `%1%'") % worker);
} catch (std::exception & e) { } catch (std::exception & e) {
std::cerr << format("child error: %1%\n") % e.what(); std::cerr << format("child error: %1%\n") % e.what();
} }
@ -150,16 +150,16 @@ void RemoteStore::connectToDaemon()
applications... */ applications... */
AutoCloseFD fdPrevDir = open(".", O_RDONLY); AutoCloseFD fdPrevDir = open(".", O_RDONLY);
if (fdPrevDir == -1) throw SysError("couldn't open current directory"); if (fdPrevDir == -1) throw SysError("couldn't open current directory");
chdir(dirOf(socketPath).c_str()); chdir(dirOf(socketPath).c_str());
Path socketPathRel = "./" + baseNameOf(socketPath); Path socketPathRel = "./" + baseNameOf(socketPath);
struct sockaddr_un addr; struct sockaddr_un addr;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
if (socketPathRel.size() >= sizeof(addr.sun_path)) if (socketPathRel.size() >= sizeof(addr.sun_path))
throw Error(format("socket path `%1%' is too long") % socketPathRel); throw Error(format("socket path `%1%' is too long") % socketPathRel);
using namespace std; using namespace std;
strcpy(addr.sun_path, socketPathRel.c_str()); strcpy(addr.sun_path, socketPathRel.c_str());
if (connect(fdSocket, (struct sockaddr *) &addr, sizeof(addr)) == -1) if (connect(fdSocket, (struct sockaddr *) &addr, sizeof(addr)) == -1)
throw SysError(format("cannot connect to daemon at `%1%'") % socketPath); throw SysError(format("cannot connect to daemon at `%1%'") % socketPath);
@ -199,9 +199,9 @@ void RemoteStore::setOptions()
} }
if (GET_PROTOCOL_MINOR(daemonVersion) >= 6) if (GET_PROTOCOL_MINOR(daemonVersion) >= 6)
writeInt(buildCores, to); writeInt(buildCores, to);
if (GET_PROTOCOL_MINOR(daemonVersion) >= 10) if (GET_PROTOCOL_MINOR(daemonVersion) >= 10)
writeInt(queryBoolSetting("build-use-substitutes", true), to); writeInt(queryBoolSetting("build-use-substitutes", true), to);
processStderr(); processStderr();
} }
@ -270,11 +270,11 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
if (paths.empty()) return; if (paths.empty()) return;
openConnection(); openConnection();
if (GET_PROTOCOL_MINOR(daemonVersion) < 3) return; if (GET_PROTOCOL_MINOR(daemonVersion) < 3) return;
if (GET_PROTOCOL_MINOR(daemonVersion) < 12) { if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
foreach (PathSet::const_iterator, i, paths) { foreach (PathSet::const_iterator, i, paths) {
SubstitutablePathInfo info; SubstitutablePathInfo info;
writeInt(wopQuerySubstitutablePathInfo, to); writeInt(wopQuerySubstitutablePathInfo, to);
@ -289,9 +289,9 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
info.narSize = GET_PROTOCOL_MINOR(daemonVersion) >= 7 ? readLongLong(from) : 0; info.narSize = GET_PROTOCOL_MINOR(daemonVersion) >= 7 ? readLongLong(from) : 0;
infos[*i] = info; infos[*i] = info;
} }
} else { } else {
writeInt(wopQuerySubstitutablePathInfos, to); writeInt(wopQuerySubstitutablePathInfos, to);
writeStrings(paths, to); writeStrings(paths, to);
processStderr(); processStderr();
@ -305,7 +305,7 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
info.downloadSize = readLongLong(from); info.downloadSize = readLongLong(from);
info.narSize = readLongLong(from); info.narSize = readLongLong(from);
} }
} }
} }
@ -411,7 +411,7 @@ Path RemoteStore::addToStore(const Path & _srcPath,
bool recursive, HashType hashAlgo, PathFilter & filter) bool recursive, HashType hashAlgo, PathFilter & filter)
{ {
openConnection(); openConnection();
Path srcPath(absPath(_srcPath)); Path srcPath(absPath(_srcPath));
writeInt(wopAddToStore, to); writeInt(wopAddToStore, to);
@ -434,7 +434,7 @@ Path RemoteStore::addTextToStore(const string & name, const string & s,
writeString(name, to); writeString(name, to);
writeString(s, to); writeString(s, to);
writeStrings(references, to); writeStrings(references, to);
processStderr(); processStderr();
return readStorePath(from); return readStorePath(from);
} }
@ -531,7 +531,7 @@ Roots RemoteStore::findRoots()
void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results) void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
{ {
openConnection(false); openConnection(false);
writeInt(wopCollectGarbage, to); writeInt(wopCollectGarbage, to);
writeInt(options.action, to); writeInt(options.action, to);
writeStrings(options.pathsToDelete, to); writeStrings(options.pathsToDelete, to);
@ -543,9 +543,9 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
writeInt(0, to); writeInt(0, to);
writeInt(0, to); writeInt(0, to);
} }
processStderr(); processStderr();
results.paths = readStrings<PathSet>(from); results.paths = readStrings<PathSet>(from);
results.bytesFreed = readLongLong(from); results.bytesFreed = readLongLong(from);
results.blocksFreed = readLongLong(from); results.blocksFreed = readLongLong(from);

View file

@ -63,5 +63,5 @@ typedef enum {
Path readStorePath(Source & from); Path readStorePath(Source & from);
template<class T> T readStorePaths(Source & from); template<class T> T readStorePaths(Source & from);
} }

View file

@ -95,7 +95,7 @@ static bool isFarSideClosed(int socket)
throw Error("EOF expected (protocol error?)"); throw Error("EOF expected (protocol error?)");
else if (rd == -1 && errno != ECONNRESET) else if (rd == -1 && errno != ECONNRESET)
throw SysError("expected connection reset or EOF"); throw SysError("expected connection reset or EOF");
return true; return true;
} }
@ -185,7 +185,7 @@ static void stopWork(bool success = true, const string & msg = "", unsigned int
we're either sending or receiving from the client, so we'll be we're either sending or receiving from the client, so we'll be
notified of client death anyway. */ notified of client death anyway. */
setSigPollAction(false); setSigPollAction(false);
canSendStderr = false; canSendStderr = false;
if (success) if (success)
@ -220,7 +220,7 @@ struct TunnelSource : BufferedSource
so we have to disable the SIGPOLL handler. */ so we have to disable the SIGPOLL handler. */
setSigPollAction(false); setSigPollAction(false);
canSendStderr = false; canSendStderr = false;
writeInt(STDERR_READ, to); writeInt(STDERR_READ, to);
writeInt(len, to); writeInt(len, to);
to.flush(); to.flush();
@ -279,7 +279,7 @@ static void performOp(unsigned int clientVersion,
{ {
switch (op) { switch (op) {
#if 0 #if 0
case wopQuit: { case wopQuit: {
/* Close the database. */ /* Close the database. */
store.reset((StoreAPI *) 0); store.reset((StoreAPI *) 0);
@ -323,7 +323,7 @@ static void performOp(unsigned int clientVersion,
writeStrings(res, to); writeStrings(res, to);
break; break;
} }
case wopQueryPathHash: { case wopQueryPathHash: {
Path path = readStorePath(from); Path path = readStorePath(from);
startWork(); startWork();
@ -391,7 +391,7 @@ static void performOp(unsigned int clientVersion,
SavingSourceAdapter savedNAR(from); SavingSourceAdapter savedNAR(from);
RetrieveRegularNARSink savedRegular; RetrieveRegularNARSink savedRegular;
if (recursive) { if (recursive) {
/* Get the entire NAR dump from the client and save it to /* Get the entire NAR dump from the client and save it to
a string so that we can pass it to a string so that we can pass it to
@ -400,13 +400,13 @@ static void performOp(unsigned int clientVersion,
parseDump(sink, savedNAR); parseDump(sink, savedNAR);
} else } else
parseDump(savedRegular, from); parseDump(savedRegular, from);
startWork(); startWork();
if (!savedRegular.regular) throw Error("regular file expected"); if (!savedRegular.regular) throw Error("regular file expected");
Path path = dynamic_cast<LocalStore *>(store.get()) Path path = dynamic_cast<LocalStore *>(store.get())
->addToStoreFromDump(recursive ? savedNAR.s : savedRegular.s, baseName, recursive, hashAlgo); ->addToStoreFromDump(recursive ? savedNAR.s : savedRegular.s, baseName, recursive, hashAlgo);
stopWork(); stopWork();
writeString(path, to); writeString(path, to);
break; break;
} }
@ -512,17 +512,17 @@ static void performOp(unsigned int clientVersion,
} }
GCResults results; GCResults results;
startWork(); startWork();
if (options.ignoreLiveness) if (options.ignoreLiveness)
throw Error("you are not allowed to ignore liveness"); throw Error("you are not allowed to ignore liveness");
store->collectGarbage(options, results); store->collectGarbage(options, results);
stopWork(); stopWork();
writeStrings(results.paths, to); writeStrings(results.paths, to);
writeLongLong(results.bytesFreed, to); writeLongLong(results.bytesFreed, to);
writeLongLong(results.blocksFreed, to); writeLongLong(results.blocksFreed, to);
break; break;
} }
@ -572,7 +572,7 @@ static void performOp(unsigned int clientVersion,
} }
break; break;
} }
case wopQuerySubstitutablePathInfos: { case wopQuerySubstitutablePathInfos: {
PathSet paths = readStorePaths<PathSet>(from); PathSet paths = readStorePaths<PathSet>(from);
startWork(); startWork();
@ -589,7 +589,7 @@ static void performOp(unsigned int clientVersion,
} }
break; break;
} }
case wopQueryAllValidPaths: { case wopQueryAllValidPaths: {
startWork(); startWork();
PathSet paths = store->queryAllValidPaths(); PathSet paths = store->queryAllValidPaths();
@ -637,7 +637,7 @@ static void performOp(unsigned int clientVersion,
static void processConnection() static void processConnection()
{ {
canSendStderr = false; canSendStderr = false;
myPid = getpid(); myPid = getpid();
writeToStderr = tunnelStderr; writeToStderr = tunnelStderr;
#ifdef HAVE_HUP_NOTIFICATION #ifdef HAVE_HUP_NOTIFICATION
@ -681,7 +681,7 @@ static void processConnection()
stopWork(); stopWork();
to.flush(); to.flush();
} catch (Error & e) { } catch (Error & e) {
stopWork(false, e.msg()); stopWork(false, e.msg());
to.flush(); to.flush();
@ -690,7 +690,7 @@ static void processConnection()
/* Process client requests. */ /* Process client requests. */
unsigned int opCount = 0; unsigned int opCount = 0;
while (true) { while (true) {
WorkerOp op; WorkerOp op;
try { try {
@ -762,7 +762,7 @@ static void daemonLoop()
/* Otherwise, create and bind to a Unix domain socket. */ /* Otherwise, create and bind to a Unix domain socket. */
else { else {
/* Create and bind to a Unix domain socket. */ /* Create and bind to a Unix domain socket. */
fdSocket = socket(PF_UNIX, SOCK_STREAM, 0); fdSocket = socket(PF_UNIX, SOCK_STREAM, 0);
if (fdSocket == -1) if (fdSocket == -1)
@ -777,7 +777,7 @@ static void daemonLoop()
relative path name. */ relative path name. */
chdir(dirOf(socketPath).c_str()); chdir(dirOf(socketPath).c_str());
Path socketPathRel = "./" + baseNameOf(socketPath); Path socketPathRel = "./" + baseNameOf(socketPath);
struct sockaddr_un addr; struct sockaddr_un addr;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
if (socketPathRel.size() >= sizeof(addr.sun_path)) if (socketPathRel.size() >= sizeof(addr.sun_path))
@ -802,7 +802,7 @@ static void daemonLoop()
} }
closeOnExec(fdSocket); closeOnExec(fdSocket);
/* Loop accepting connections. */ /* Loop accepting connections. */
while (1) { while (1) {
@ -810,7 +810,7 @@ static void daemonLoop()
/* Important: the server process *cannot* open the SQLite /* Important: the server process *cannot* open the SQLite
database, because it doesn't like forks very much. */ database, because it doesn't like forks very much. */
assert(!store); assert(!store);
/* Accept a connection. */ /* Accept a connection. */
struct sockaddr_un remoteAddr; struct sockaddr_un remoteAddr;
socklen_t remoteAddrLen = sizeof(remoteAddr); socklen_t remoteAddrLen = sizeof(remoteAddr);
@ -819,14 +819,14 @@ static void daemonLoop()
(struct sockaddr *) &remoteAddr, &remoteAddrLen); (struct sockaddr *) &remoteAddr, &remoteAddrLen);
checkInterrupt(); checkInterrupt();
if (remote == -1) { if (remote == -1) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
else else
throw SysError("accepting connection"); throw SysError("accepting connection");
} }
closeOnExec(remote); closeOnExec(remote);
/* Get the identity of the caller, if possible. */ /* Get the identity of the caller, if possible. */
uid_t clientUid = -1; uid_t clientUid = -1;
pid_t clientPid = -1; pid_t clientPid = -1;
@ -841,13 +841,13 @@ static void daemonLoop()
#endif #endif
printMsg(lvlInfo, format("accepted connection from pid %1%, uid %2%") % clientPid % clientUid); printMsg(lvlInfo, format("accepted connection from pid %1%, uid %2%") % clientPid % clientUid);
/* Fork a child to handle the connection. */ /* Fork a child to handle the connection. */
pid_t child; pid_t child;
child = fork(); child = fork();
switch (child) { switch (child) {
case -1: case -1:
throw SysError("unable to fork"); throw SysError("unable to fork");
@ -866,16 +866,16 @@ static void daemonLoop()
string processName = int2String(clientPid); string processName = int2String(clientPid);
strncpy(argvSaved[1], processName.c_str(), strlen(argvSaved[1])); strncpy(argvSaved[1], processName.c_str(), strlen(argvSaved[1]));
} }
/* Since the daemon can be long-running, the /* Since the daemon can be long-running, the
settings may have changed. So force a reload. */ settings may have changed. So force a reload. */
reloadSettings(); reloadSettings();
/* Handle the connection. */ /* Handle the connection. */
from.fd = remote; from.fd = remote;
to.fd = remote; to.fd = remote;
processConnection(); processConnection();
} catch (std::exception & e) { } catch (std::exception & e) {
std::cerr << format("child error: %1%\n") % e.what(); std::cerr << format("child error: %1%\n") % e.what();
} }
@ -895,7 +895,7 @@ void run(Strings args)
{ {
bool slave = false; bool slave = false;
bool daemon = false; bool daemon = false;
for (Strings::iterator i = args.begin(); i != args.end(); ) { for (Strings::iterator i = args.begin(); i != args.end(); ) {
string arg = *i++; string arg = *i++;
if (arg == "--slave") slave = true; if (arg == "--slave") slave = true;