From ed55982085d3b812823215ca25309621eb958d22 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Wed, 5 Sep 2007 14:13:50 +0000 Subject: [PATCH] Fixed remote issues --- src/libexpr/primops.cc | 2 +- src/libstore/db.cc | 2 -- src/libstore/globals.cc | 4 ++- src/libstore/globals.hh | 4 ++- src/libstore/local-store.cc | 5 +-- src/libstore/store-state.cc | 2 +- src/libutil/util.cc | 11 +++--- src/libutil/util.hh | 2 +- src/nix-env/nix-env.cc | 7 ++-- src/nix-state/nix-state.cc | 5 --- src/nix-worker/nix-worker.cc | 69 ++++++++++++++++++++---------------- 11 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 607baf3d0..fbe6f1d94 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -509,7 +509,7 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) } } - else if(key == "solidStateDependency"){ externalState = coerceToString(state, value, context, true); } + else if(key == "solidStateDependency"){ externalState = coerceToString(state, value, context, true); } else if(key == "shareType") { shareType = coerceToString(state, value, context, true); } else if(key == "synchronization") { syncState = coerceToString(state, value, context, true); } else if(key == "disableState") { disableState = evalBool(state, value); } diff --git a/src/libstore/db.cc b/src/libstore/db.cc index 09cfafcc9..bb5eecf6e 100644 --- a/src/libstore/db.cc +++ b/src/libstore/db.cc @@ -383,14 +383,12 @@ void Database::setString(const Transaction & txn, TableId table, const string & key, const string & data) { checkInterrupt(); - printMsg(lvlError, format("SS: '%1%'") % data); try { Db * db = getDb(table); Dbt kt((void *) key.c_str(), key.length()); Dbt dt((void *) data.c_str(), data.length()); db->put(txn.txn, &kt, &dt, 0); } catch (DbException e) { rethrow(e); } - printMsg(lvlError, format("SETTEDS")); } diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 3f1b5a993..3070e8637 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -29,7 +29,9 @@ string thisSystem = "unset"; unsigned int maxSilentTime = 0; static bool settingsRead = false; uid_t callingUID = 0; //A root user will not set this value, so the default uid is 0 -bool debugWorker = false; //TODO Still experimental ! this gives an store already open at the second call + +bool singleThreaded = false; //TODO Gives an error: cannot start worker (environment already open) / waiting for process 7487: No child processes +bool sendOutput = true; static std::map settings; diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index cf72f3621..3e1f70916 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -96,7 +96,9 @@ string queryCallingUsername(); /* get the username based on the UID of the user currently runs the process */ string queryCurrentUsername(); -extern bool debugWorker; +extern bool singleThreaded; +extern bool sendOutput; + } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 1a8496054..77583d130 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -694,7 +694,7 @@ void setDeriver(const Transaction & txn, const Path & storePath, const Path & de * into account. This function is used to update derivations that have only changed in their sub state * paths that need to be versioned for example. We assume newdrv is the newest. */ -PathSet mergeNewDerivationIntoListTxn(const Transaction txn, const Path & storepath, const Path & newdrv, const PathSet drvs, bool deleteDrvs) +PathSet mergeNewDerivationIntoListTxn(const Transaction & txn, const Path & storepath, const Path & newdrv, const PathSet drvs, bool deleteDrvs) { PathSet newdrvs; @@ -744,11 +744,8 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path for (PathSet::iterator i = updatedDerivers.begin(); i != updatedDerivers.end(); ++i) //Convert Paths to Strings data.push_back(*i); - for (Strings::iterator i = data.begin(); i != data.end(); ++i) - printMsg(lvlError, format("AA: %1%") % *i); nixDB.setStrings(txn, dbDerivers, storePath, data); //update the derivers db. - printMsg(lvlError, format("%BB")); nixDB.setString(txn, dbStateInfo, storePath, ""); //update the dbinfo db. (maybe TODO) } diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index e913fc370..3be10e54e 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -40,7 +40,7 @@ void createSubStateDirsTxn(const Transaction & txn, const DerivationStateOutputD //TODO /* - if( ! DirectoryExist( ....... ) ){ + if( ! DirectoryExists( ....... ) ){ } else printMsg(lvlTalkative, format("Statedir %1% already exists, so dont ........ ???? ") % ...); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index e5e94beb6..5579b338d 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1177,16 +1177,14 @@ bool DirectoryExist(const string FileName) } //TODO Does this work on windows? - bool IsSymlink(const string FileName) { const char* FileName_C = FileName.c_str(); - struct stat my_stat; - if (lstat(FileName_C, &my_stat) != 0) return false; - return (S_ISLNK(my_stat.st_mode) != 0); + struct stat my_stat; + if (lstat(FileName_C, &my_stat) != 0) return false; + return (S_ISLNK(my_stat.st_mode) != 0); } - /* string getCallingUserName() { @@ -1292,6 +1290,7 @@ void symlinkPath(const Path & fromExisting, const Path & toNew) p_args.push_back(fromExisting); p_args.push_back(toNew); runProgram_AndPrintOutput("ln", true, p_args, "ln"); + //printMsg(lvlError, format("ln -sf %1% %2%") % fromExisting % toNew); } @@ -1299,7 +1298,7 @@ void copyContents(const Path & from, const Path & to) { Strings p_args; p_args.push_back("-R"); - p_args.push_back(from + "/"); //the / makes sure it copys the contents of the dir, not just the symlink + p_args.push_back(from + "/"); //the / makes sure it copys the contents of the dir, not just the symlink p_args.push_back(to); runProgram_AndPrintOutput("cp", true, p_args, "cp"); } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 767f5544a..63cd37b5d 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -42,7 +42,7 @@ bool pathExists(const Path & path); /* Return true if the given file exists. */ bool FileExist(const string FileName); -/* Return true if the given dir exists. */ +/* Return true if the given filename is a dir. */ bool DirectoryExist(const string FileName); /* Return true if the given filename is a symlink. */ diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 905b656be..4ad2f74e9 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -628,7 +628,6 @@ static void installDerivations(Globals & globals, //1. If dir externalState exists, we move its data into the statePath //2. We ensure that the parent dir of externalState exists so we can create a symlink if(DirectoryExist(externalState)){ - //We cannot copy into itself so we have to test that if(IsSymlink(externalState)){ Path read_statePath = readLink(externalState); @@ -641,15 +640,15 @@ static void installDerivations(Globals & globals, } else copyContents(externalState, statePath); - + deletePath(externalState); } else{ //Ensure parent dir string externalState_p = externalState; if(externalState_p[externalState_p.length() - 1] == '/') - externalState_p.erase(externalState_p.length(),1); - externalState_p = externalState_p.substr(0,externalState_p.find_last_of('/')); + externalState_p.erase(externalState_p.length(),1); + externalState_p = externalState_p.substr(0,externalState_p.find_last_of('/')); ensureDirExists(externalState_p); } diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index 99492224d..5ed6444f6 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -486,11 +486,6 @@ void run(Strings args) RevisionClosureTS timestamps; bool b = store->queryStateRevisions("/nix/state/aacs4qpi9jzg4vmhj09d0ichframh22x-hellohardcodedstateworld-1.0-test", revisions, timestamps, 0); - */ - - store = openStore(); - - /* PathSet sharedWith = getSharedWithPathSetRecTxn(noTxn, "/nix/state/1kjxymaxf0i6qp5k8ggacc06bzbi4b82-hellohardcodedstateworld-1.0-test"); for (PathSet::const_iterator j = sharedWith.begin(); j != sharedWith.end(); ++j) printMsg(lvlError, format("RootSP SW '%1%'") % *j); diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index 8eaa74a82..7e88c871f 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -28,6 +28,7 @@ using namespace nix; static FdSource from(STDIN_FILENO); static FdSink to(STDOUT_FILENO); +bool storeOpen = false; bool canSendStderr; pid_t myPid; @@ -43,7 +44,7 @@ static void tunnelStderr(const unsigned char * buf, size_t count) process handling the connection. Otherwise we could screw up the protocol. It's up to the parent to redirect stderr and send it to the client somehow (e.g., as in build.cc). */ - if (canSendStderr && myPid == getpid() && (!debugWorker)) { //TODO debugWorker commit + if ((canSendStderr && myPid == getpid()) && (sendOutput)) { try { writeInt(STDERR_NEXT, to); writeString(string((char *) buf, count), to); @@ -54,7 +55,6 @@ static void tunnelStderr(const unsigned char * buf, size_t count) throw; } } else{ - //printMsg(lvlInfo, format("nix-worker: debug mode")); writeFull(STDERR_FILENO, buf, count); } } @@ -232,7 +232,9 @@ static void performOp(Source & from, Sink & to, unsigned int op) #if 0 case wopQuit: { /* Close the database. */ - store.reset((StoreAPI *) 0); + if(!singleThreaded){ + store.reset((StoreAPI *) 0); + } writeInt(1, to); break; } @@ -636,7 +638,16 @@ static void processConnection() throw Error("if you run `nix-worker' as root, then you MUST set `build-users-group'!"); /* Open the store. */ - store = boost::shared_ptr(new LocalStore(true)); + if(singleThreaded){ //only open once + if(!storeOpen){ + printMsg(lvlError, format("Opening store")); + storeOpen = true; + store = boost::shared_ptr(new LocalStore(true)); + } + } + else{ + store = boost::shared_ptr(new LocalStore(true)); + } stopWork(); @@ -745,8 +756,8 @@ static void daemonLoop() /* Important: the server process *cannot* open the Berkeley DB environment, because it doesn't like forks very much. */ - if(!debugWorker) - assert(!store); + if(!singleThreaded) + assert(!store); /* Accept a connection. */ struct sockaddr_un remoteAddr; @@ -766,9 +777,29 @@ static void daemonLoop() printMsg(lvlInfo, format("accepted connection '%1%'") % remote); - if(!debugWorker) - { + if(singleThreaded) + { + printMsg(lvlInfo, format("Nix-worker: debug mode: we can only process 1 job at the time")); + + /* We RESET the user id of the caller cause we have no fork */ + setCallingUID(caller_uid, true); + printMsg(lvlInfo, format("Debug connection '%1%' created for userid: '%2%' with username: '%3%'") + % remote % queryCallingUID() % queryCallingUsername()); + + /* Background the worker. */ + //if (setsid() == -1) + // throw SysError(format("creating a new session")); + /* Restore normal handling of SIGCHLD. */ + //setSigChldAction(false); + + /* Handle the connection. */ + from.fd = remote; + to.fd = remote; + processConnection(); + } + else + { /* Fork a child to handle the connection. */ pid_t child; child = fork(); @@ -804,28 +835,6 @@ static void daemonLoop() exit(0); } } - else - { - printMsg(lvlInfo, format("Nix-worker: debug mode: we can only process 1 job at the time")); - - /* We RESET the user id of the caller cause we have no fork */ - setCallingUID(caller_uid, true); - printMsg(lvlInfo, format("Debug connection '%1%' created for userid: '%2%' with username: '%3%'") - % remote % queryCallingUID() % queryCallingUsername()); - - /* Background the worker. */ - //if (setsid() == -1) - // throw SysError(format("creating a new session")); - - /* Restore normal handling of SIGCHLD. */ - //setSigChldAction(false); - - /* Handle the connection. */ - from.fd = remote; - to.fd = remote; - processConnection(); - - } } catch (Interrupted & e) { throw;