* Pass various options to the worker so that flags like -K or -j work
in multi-user Nix (NIX-72). * Client/worker: exchange a protocol version number for future compatibility.
This commit is contained in:
		
							parent
							
								
									26f981c2e5
								
							
						
					
					
						commit
						f3441e6122
					
				
					 5 changed files with 49 additions and 7 deletions
				
			
		|  | @ -773,7 +773,6 @@ static Expr prim_listToAttrs(EvalState & state, const ATermVector & args) | ||||||
|       if (matchAttrs(evaledExpr, attrs)){ |       if (matchAttrs(evaledExpr, attrs)){ | ||||||
|         Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("attr"))); |         Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("attr"))); | ||||||
|         string attr = evalStringNoCtx(state,e); |         string attr = evalStringNoCtx(state,e); | ||||||
|         ATerm value; |  | ||||||
|         Expr r = makeSelect(evaledExpr, toATerm("value")); |         Expr r = makeSelect(evaledExpr, toATerm("value")); | ||||||
|         res.set(toATerm(attr), makeAttrRHS(r, makeNoPos())); |         res.set(toATerm(attr), makeAttrRHS(r, makeNoPos())); | ||||||
|       } |       } | ||||||
|  | @ -783,7 +782,7 @@ static Expr prim_listToAttrs(EvalState & state, const ATermVector & args) | ||||||
|     } // for
 |     } // for
 | ||||||
|     return makeAttrs(res); |     return makeAttrs(res); | ||||||
|   } catch (Error & e) { |   } catch (Error & e) { | ||||||
|     e.addPrefix(format("while calling listToAttrs ")); |     e.addPrefix(format("in `listToAttrs':\n")); | ||||||
|     throw; |     throw; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -53,18 +53,24 @@ RemoteStore::RemoteStore() | ||||||
|     from.fd = fdSocket; |     from.fd = fdSocket; | ||||||
|     to.fd = fdSocket; |     to.fd = fdSocket; | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /* Send the magic greeting, check for the reply. */ |     /* Send the magic greeting, check for the reply. */ | ||||||
|     try { |     try { | ||||||
|         writeInt(WORKER_MAGIC_1, to); |         writeInt(WORKER_MAGIC_1, to); | ||||||
|         writeInt(verbosity, to); |  | ||||||
|         unsigned int magic = readInt(from); |         unsigned int magic = readInt(from); | ||||||
|         if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch"); |         if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch"); | ||||||
|  | 
 | ||||||
|  |         unsigned int daemonVersion = readInt(from); | ||||||
|  |         if (GET_PROTOCOL_MAJOR(daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION)) | ||||||
|  |             throw Error("Nix daemon protocol version not supported"); | ||||||
|  |         writeInt(PROTOCOL_VERSION, to); | ||||||
|         processStderr(); |         processStderr(); | ||||||
|  | 
 | ||||||
|     } catch (Error & e) { |     } catch (Error & e) { | ||||||
|         throw Error(format("cannot start worker (%1%)") |         throw Error(format("cannot start worker (%1%)") | ||||||
|             % e.msg()); |             % e.msg()); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     setOptions(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -154,6 +160,19 @@ RemoteStore::~RemoteStore() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | void RemoteStore::setOptions() | ||||||
|  | { | ||||||
|  |     writeInt(wopSetOptions, to); | ||||||
|  |     writeInt(keepFailed, to); | ||||||
|  |     writeInt(keepGoing, to); | ||||||
|  |     writeInt(tryFallback, to); | ||||||
|  |     writeInt(verbosity, to); | ||||||
|  |     writeInt(maxBuildJobs, to); | ||||||
|  |     writeInt(maxSilentTime, to); | ||||||
|  |     processStderr(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| bool RemoteStore::isValidPath(const Path & path) | bool RemoteStore::isValidPath(const Path & path) | ||||||
| { | { | ||||||
|     writeInt(wopIsValidPath, to); |     writeInt(wopIsValidPath, to); | ||||||
|  |  | ||||||
|  | @ -77,6 +77,8 @@ private: | ||||||
|     void forkSlave(); |     void forkSlave(); | ||||||
|      |      | ||||||
|     void connectToDaemon(); |     void connectToDaemon(); | ||||||
|  | 
 | ||||||
|  |     void setOptions(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,8 +5,11 @@ | ||||||
| namespace nix { | namespace nix { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| #define WORKER_MAGIC_1 0x6e697864 | #define WORKER_MAGIC_1 0x6e697863 | ||||||
| #define WORKER_MAGIC_2 0x6478696e | #define WORKER_MAGIC_2 0x6478696f | ||||||
|  | 
 | ||||||
|  | #define PROTOCOL_VERSION 0x101 | ||||||
|  | #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
|  | @ -28,6 +31,7 @@ typedef enum { | ||||||
|     wopExportPath, |     wopExportPath, | ||||||
|     wopImportPath, |     wopImportPath, | ||||||
|     wopQueryDeriver, |     wopQueryDeriver, | ||||||
|  |     wopSetOptions, | ||||||
| } WorkerOp; | } WorkerOp; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -414,6 +414,19 @@ static void performOp(Source & from, Sink & to, unsigned int op) | ||||||
|          |          | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     case wopSetOptions: { | ||||||
|  |         keepFailed = readInt(from) != 0; | ||||||
|  |         keepGoing = readInt(from) != 0; | ||||||
|  |         tryFallback = readInt(from) != 0; | ||||||
|  |         verbosity = (Verbosity) readInt(from); | ||||||
|  |         maxBuildJobs = readInt(from); | ||||||
|  |         maxSilentTime = readInt(from); | ||||||
|  |         startWork(); | ||||||
|  |         stopWork(); | ||||||
|  |         break; | ||||||
|  |     } | ||||||
|  |              | ||||||
|              |              | ||||||
|     default: |     default: | ||||||
|         throw Error(format("invalid operation %1%") % op); |         throw Error(format("invalid operation %1%") % op); | ||||||
|  | @ -437,14 +450,19 @@ static void processConnection() | ||||||
|     /* Exchange the greeting. */ |     /* Exchange the greeting. */ | ||||||
|     unsigned int magic = readInt(from); |     unsigned int magic = readInt(from); | ||||||
|     if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch"); |     if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch"); | ||||||
|     verbosity = (Verbosity) readInt(from); |  | ||||||
|     writeInt(WORKER_MAGIC_2, to); |     writeInt(WORKER_MAGIC_2, to); | ||||||
| 
 | 
 | ||||||
|  |     writeInt(PROTOCOL_VERSION, to); | ||||||
|  |     unsigned int clientVersion = readInt(from); | ||||||
|  | 
 | ||||||
|     /* Send startup error messages to the client. */ |     /* Send startup error messages to the client. */ | ||||||
|     startWork(); |     startWork(); | ||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
| 
 | 
 | ||||||
|  |         /* If we can't accept clientVersion, then throw an error
 | ||||||
|  |            *here* (not above). */ | ||||||
|  | 
 | ||||||
|         /* Prevent users from doing something very dangerous. */ |         /* Prevent users from doing something very dangerous. */ | ||||||
|         if (geteuid() == 0 && |         if (geteuid() == 0 && | ||||||
|             querySetting("build-users-group", "") == "") |             querySetting("build-users-group", "") == "") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue