Use std::vector::data()
This commit is contained in:
		
							parent
							
								
									f2b67fbf2a
								
							
						
					
					
						commit
						7c4501886d
					
				
					 3 changed files with 8 additions and 12 deletions
				
			
		|  | @ -2305,7 +2305,6 @@ void DerivationGoal::runChild() | ||||||
|         Strings envStrs; |         Strings envStrs; | ||||||
|         foreach (Environment::const_iterator, i, env) |         foreach (Environment::const_iterator, i, env) | ||||||
|             envStrs.push_back(rewriteHashes(i->first + "=" + i->second, rewritesToTmp)); |             envStrs.push_back(rewriteHashes(i->first + "=" + i->second, rewritesToTmp)); | ||||||
|         auto envArr = stringsToCharPtrs(envStrs); |  | ||||||
| 
 | 
 | ||||||
|         /* If we are running in `build-users' mode, then switch to the
 |         /* If we are running in `build-users' mode, then switch to the
 | ||||||
|            user we allocated above.  Make sure that we drop all root |            user we allocated above.  Make sure that we drop all root | ||||||
|  | @ -2452,7 +2451,6 @@ void DerivationGoal::runChild() | ||||||
| 
 | 
 | ||||||
|         foreach (Strings::iterator, i, drv.args) |         foreach (Strings::iterator, i, drv.args) | ||||||
|             args.push_back(rewriteHashes(*i, rewritesToTmp)); |             args.push_back(rewriteHashes(*i, rewritesToTmp)); | ||||||
|         auto argArr = stringsToCharPtrs(args); |  | ||||||
| 
 | 
 | ||||||
|         restoreSIGPIPE(); |         restoreSIGPIPE(); | ||||||
| 
 | 
 | ||||||
|  | @ -2466,7 +2464,7 @@ void DerivationGoal::runChild() | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /* Execute the program.  This should not return. */ |         /* Execute the program.  This should not return. */ | ||||||
|         execve(builder, (char * *) &argArr[0], (char * *) &envArr[0]); |         execve(builder, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data()); | ||||||
| 
 | 
 | ||||||
|         throw SysError(format("executing ‘%1%’") % drv.builder); |         throw SysError(format("executing ‘%1%’") % drv.builder); | ||||||
| 
 | 
 | ||||||
|  | @ -3094,7 +3092,6 @@ void SubstitutionGoal::tryToRun() | ||||||
|     args.push_back("--substitute"); |     args.push_back("--substitute"); | ||||||
|     args.push_back(storePath); |     args.push_back(storePath); | ||||||
|     args.push_back(destPath); |     args.push_back(destPath); | ||||||
|     auto argArr = stringsToCharPtrs(args); |  | ||||||
| 
 | 
 | ||||||
|     /* Fork the substitute program. */ |     /* Fork the substitute program. */ | ||||||
|     pid = startProcess([&]() { |     pid = startProcess([&]() { | ||||||
|  | @ -3104,7 +3101,7 @@ void SubstitutionGoal::tryToRun() | ||||||
|         if (dup2(outPipe.writeSide, STDOUT_FILENO) == -1) |         if (dup2(outPipe.writeSide, STDOUT_FILENO) == -1) | ||||||
|             throw SysError("cannot dup output pipe into stdout"); |             throw SysError("cannot dup output pipe into stdout"); | ||||||
| 
 | 
 | ||||||
|         execv(sub.c_str(), (char * *) &argArr[0]); |         execv(sub.c_str(), stringsToCharPtrs(args).data()); | ||||||
| 
 | 
 | ||||||
|         throw SysError(format("executing ‘%1%’") % sub); |         throw SysError(format("executing ‘%1%’") % sub); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  | @ -927,10 +927,10 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| std::vector<const char *> stringsToCharPtrs(const Strings & ss) | std::vector<char *> stringsToCharPtrs(const Strings & ss) | ||||||
| { | { | ||||||
|     std::vector<const char *> res; |     std::vector<char *> res; | ||||||
|     for (auto & s : ss) res.push_back(s.c_str()); |     for (auto & s : ss) res.push_back((char *) s.c_str()); | ||||||
|     res.push_back(0); |     res.push_back(0); | ||||||
|     return res; |     return res; | ||||||
| } | } | ||||||
|  | @ -957,12 +957,11 @@ string runProgram(Path program, bool searchPath, const Strings & args, | ||||||
| 
 | 
 | ||||||
|         Strings args_(args); |         Strings args_(args); | ||||||
|         args_.push_front(program); |         args_.push_front(program); | ||||||
|         auto cargs = stringsToCharPtrs(args_); |  | ||||||
| 
 | 
 | ||||||
|         if (searchPath) |         if (searchPath) | ||||||
|             execvp(program.c_str(), (char * *) &cargs[0]); |             execvp(program.c_str(), stringsToCharPtrs(args_).data()); | ||||||
|         else |         else | ||||||
|             execv(program.c_str(), (char * *) &cargs[0]); |             execv(program.c_str(), stringsToCharPtrs(args_).data()); | ||||||
| 
 | 
 | ||||||
|         throw SysError(format("executing ‘%1%’") % program); |         throw SysError(format("executing ‘%1%’") % program); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  | @ -295,7 +295,7 @@ MakeError(ExecError, Error) | ||||||
| /* Convert a list of strings to a null-terminated vector of char
 | /* Convert a list of strings to a null-terminated vector of char
 | ||||||
|    *'s. The result must not be accessed beyond the lifetime of the |    *'s. The result must not be accessed beyond the lifetime of the | ||||||
|    list of strings. */ |    list of strings. */ | ||||||
| std::vector<const char *> stringsToCharPtrs(const Strings & ss); | std::vector<char *> stringsToCharPtrs(const Strings & ss); | ||||||
| 
 | 
 | ||||||
| /* Close all file descriptors except stdin, stdout, stderr, and those
 | /* Close all file descriptors except stdin, stdout, stderr, and those
 | ||||||
|    listed in the given set.  Good practice in child processes. */ |    listed in the given set.  Good practice in child processes. */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue