credential-cache--daemon: refactor check_socket_directory
This function does an early return, and therefore has to repeat its cleanup. We can stick the later bit of the function into an "else" and avoid duplicating the shared part (which will get bigger in a future patch). Let's also rename the function to init_socket_directory. It not only checks the directory but also creates it. Saying "init" is more accurate. Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									326e5bc91e
								
							
						
					
					
						commit
						a6e5e2864f
					
				|  | @ -215,7 +215,7 @@ static const char permissions_advice[] = | ||||||
| "users may be able to read your cached credentials. Consider running:\n" | "users may be able to read your cached credentials. Consider running:\n" | ||||||
| "\n" | "\n" | ||||||
| "	chmod 0700 %s"; | "	chmod 0700 %s"; | ||||||
| static void check_socket_directory(const char *path) | static void init_socket_directory(const char *path) | ||||||
| { | { | ||||||
| 	struct stat st; | 	struct stat st; | ||||||
| 	char *path_copy = xstrdup(path); | 	char *path_copy = xstrdup(path); | ||||||
|  | @ -224,10 +224,7 @@ static void check_socket_directory(const char *path) | ||||||
| 	if (!stat(dir, &st)) { | 	if (!stat(dir, &st)) { | ||||||
| 		if (st.st_mode & 077) | 		if (st.st_mode & 077) | ||||||
| 			die(permissions_advice, dir); | 			die(permissions_advice, dir); | ||||||
| 		free(path_copy); | 	} else { | ||||||
| 		return; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 		/* | 		/* | ||||||
| 		 * We must be sure to create the directory with the correct mode, | 		 * We must be sure to create the directory with the correct mode, | ||||||
| 		 * not just chmod it after the fact; otherwise, there is a race | 		 * not just chmod it after the fact; otherwise, there is a race | ||||||
|  | @ -238,6 +235,7 @@ static void check_socket_directory(const char *path) | ||||||
| 			die_errno("unable to create directories for '%s'", dir); | 			die_errno("unable to create directories for '%s'", dir); | ||||||
| 		if (mkdir(dir, 0700) < 0) | 		if (mkdir(dir, 0700) < 0) | ||||||
| 			die_errno("unable to mkdir '%s'", dir); | 			die_errno("unable to mkdir '%s'", dir); | ||||||
|  | 	} | ||||||
| 	free(path_copy); | 	free(path_copy); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -264,7 +262,7 @@ int main(int argc, const char **argv) | ||||||
| 	if (!socket_path) | 	if (!socket_path) | ||||||
| 		usage_with_options(usage, options); | 		usage_with_options(usage, options); | ||||||
|  |  | ||||||
| 	check_socket_directory(socket_path); | 	init_socket_directory(socket_path); | ||||||
| 	register_tempfile(&socket_file, socket_path); | 	register_tempfile(&socket_file, socket_path); | ||||||
|  |  | ||||||
| 	if (ignore_sighup) | 	if (ignore_sighup) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Jon Griffiths
						Jon Griffiths