MCPcopy Create free account
hub / github.com/git/git / unix_sockaddr_init

Function unix_sockaddr_init

unix-socket.c:35–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
36 struct unix_sockaddr_context *ctx,
37 int disallow_chdir)
38{
39 int size = strlen(path) + 1;
40
41 ctx->orig_dir = NULL;
42 if (size > sizeof(sa->sun_path)) {
43 const char *slash;
44 const char *dir;
45 struct strbuf cwd = STRBUF_INIT;
46
47 if (disallow_chdir) {
48 errno = ENAMETOOLONG;
49 return -1;
50 }
51
52 slash = find_last_dir_sep(path);
53 if (!slash) {
54 errno = ENAMETOOLONG;
55 return -1;
56 }
57
58 dir = path;
59 path = slash + 1;
60 size = strlen(path) + 1;
61 if (size > sizeof(sa->sun_path)) {
62 errno = ENAMETOOLONG;
63 return -1;
64 }
65 if (strbuf_getcwd(&cwd))
66 return -1;
67 ctx->orig_dir = strbuf_detach(&cwd, NULL);
68 if (chdir_len(dir, slash - dir) < 0) {
69 FREE_AND_NULL(ctx->orig_dir);
70 return -1;
71 }
72 }
73
74 memset(sa, 0, sizeof(*sa));
75 sa->sun_family = AF_UNIX;
76 memcpy(sa->sun_path, path, size);
77 return 0;
78}
79
80int unix_stream_connect(const char *path, int disallow_chdir)
81{

Callers 2

unix_stream_connectFunction · 0.85
unix_stream_listenFunction · 0.85

Calls 3

strbuf_getcwdFunction · 0.85
strbuf_detachFunction · 0.85
chdir_lenFunction · 0.85

Tested by

no test coverage detected