Fix "tinc start" on Windows when the path contains spaces.
When invoking "tinc start" with spaces in the path, the following
happens:
    > "c:\Program Files (x86)\tinc\tinc.exe" start
    c:\Program: unrecognized argument 'Files'
    Try `c:\Program --help' for more information.
This is caused by inconsistent handling of command line strings between
execvp() and the spawned process' CRT, as documented on MSDN:
http://msdn.microsoft.com/library/431x4c1w.aspx
			
			
This commit is contained in:
		
							parent
							
								
									5ffdff685a
								
							
						
					
					
						commit
						b22499668a
					
				
					 1 changed files with 13 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -810,7 +810,19 @@ static int cmd_start(int argc, char *argv[]) {
 | 
			
		|||
	int nargc = 0;
 | 
			
		||||
	char **nargv = xzalloc((optind + argc) * sizeof *nargv);
 | 
			
		||||
 | 
			
		||||
	nargv[nargc++] = c;
 | 
			
		||||
	char *arg0 = c;
 | 
			
		||||
#ifdef HAVE_MINGW
 | 
			
		||||
	/*
 | 
			
		||||
	   Windows has no real concept of an "argv array". A command line is just one string.
 | 
			
		||||
	   The CRT of the new process will decode the command line string to generate argv before calling main(), and (by convention)
 | 
			
		||||
	   it uses quotes to handle spaces in arguments.
 | 
			
		||||
	   Therefore we need to quote all arguments that might contain spaces. No, execvp() won't do that for us (see MSDN).
 | 
			
		||||
	   If we don't do that, then execvp() will run fine but any spaces in the filename contained in arg0 will bleed
 | 
			
		||||
	   into the next arguments when the spawned process' CRT parses its command line, resulting in chaos.
 | 
			
		||||
	*/
 | 
			
		||||
	xasprintf(&arg0, "\"%s\"", arg0);
 | 
			
		||||
#endif
 | 
			
		||||
	nargv[nargc++] = arg0;
 | 
			
		||||
	for(int i = 1; i < optind; i++)
 | 
			
		||||
		nargv[nargc++] = orig_argv[i];
 | 
			
		||||
	for(int i = 1; i < argc; i++)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue