diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-12-19 16:05:16 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-12-19 16:05:16 -0800 |
commit | 367d20ec6b9e8e297537f665fb528346bd0aff27 (patch) | |
tree | bce97747bf55c8b3adffa0a058984aba5ea3225f /unix-socket.c | |
parent | d16520499d2652b5b59dfb25f9cf2d56a4c6913a (diff) | |
parent | 861444f6d702b15713d0875ce9dc5aff64885fba (diff) | |
download | git-367d20ec6b9e8e297537f665fb528346bd0aff27.tar.gz |
Merge branch 'jk/credentials'
* jk/credentials:
t: add test harness for external credential helpers
credentials: add "store" helper
strbuf: add strbuf_add*_urlencode
Makefile: unix sockets may not available on some platforms
credentials: add "cache" helper
docs: end-user documentation for the credential subsystem
credential: make relevance of http path configurable
credential: add credential.*.username
credential: apply helper config
http: use credential API to get passwords
credential: add function for parsing url components
introduce credentials API
t5550: fix typo
test-lib: add test_config_global variant
Conflicts:
strbuf.c
Diffstat (limited to 'unix-socket.c')
-rw-r--r-- | unix-socket.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/unix-socket.c b/unix-socket.c new file mode 100644 index 0000000000..84b15099f2 --- /dev/null +++ b/unix-socket.c @@ -0,0 +1,56 @@ +#include "cache.h" +#include "unix-socket.h" + +static int unix_stream_socket(void) +{ + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + die_errno("unable to create socket"); + return fd; +} + +static void unix_sockaddr_init(struct sockaddr_un *sa, const char *path) +{ + int size = strlen(path) + 1; + if (size > sizeof(sa->sun_path)) + die("socket path is too long to fit in sockaddr"); + memset(sa, 0, sizeof(*sa)); + sa->sun_family = AF_UNIX; + memcpy(sa->sun_path, path, size); +} + +int unix_stream_connect(const char *path) +{ + int fd; + struct sockaddr_un sa; + + unix_sockaddr_init(&sa, path); + fd = unix_stream_socket(); + if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { + close(fd); + return -1; + } + return fd; +} + +int unix_stream_listen(const char *path) +{ + int fd; + struct sockaddr_un sa; + + unix_sockaddr_init(&sa, path); + fd = unix_stream_socket(); + + unlink(path); + if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { + close(fd); + return -1; + } + + if (listen(fd, 5) < 0) { + close(fd); + return -1; + } + + return fd; +} |