* sockaddr_un doesn't allow path names of more than 108 characters.
This isn't usually a problem, except that it causes tests to fail when performed in a directory with a very long path name. So chdir to the socket directory and use a relative path name.
This commit is contained in:
		
							parent
							
								
									f8985d195e
								
							
						
					
					
						commit
						72034ab35d
					
				
					 2 changed files with 26 additions and 6 deletions
				
			
		|  | @ -542,11 +542,17 @@ static void daemonLoop() | |||
| 
 | ||||
|     createDirs(dirOf(socketPath)); | ||||
| 
 | ||||
|     /* Urgh, sockaddr_un allows path names of only 108 characters.  So
 | ||||
|        chdir to the socket directory so that we can pass a relative | ||||
|        path name. */ | ||||
|     chdir(dirOf(socketPath).c_str()); | ||||
|     Path socketPathRel = "./" + baseNameOf(socketPath); | ||||
|      | ||||
|     struct sockaddr_un addr; | ||||
|     addr.sun_family = AF_UNIX; | ||||
|     if (socketPath.size() >= sizeof(addr.sun_path)) | ||||
|         throw Error(format("socket path `%1%' is too long") % socketPath); | ||||
|     strcpy(addr.sun_path, socketPath.c_str()); | ||||
|     if (socketPathRel.size() >= sizeof(addr.sun_path)) | ||||
|         throw Error(format("socket path `%1%' is too long") % socketPathRel); | ||||
|     strcpy(addr.sun_path, socketPathRel.c_str()); | ||||
| 
 | ||||
|     unlink(socketPath.c_str()); | ||||
| 
 | ||||
|  | @ -559,6 +565,8 @@ static void daemonLoop() | |||
|     if (res == -1) | ||||
|         throw SysError(format("cannot bind to socket `%1%'") % socketPath); | ||||
| 
 | ||||
|     chdir("/"); /* back to the root */ | ||||
| 
 | ||||
|     if (listen(fdSocket, 5) == -1) | ||||
|         throw SysError(format("cannot listen on socket `%1%'") % socketPath); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue