diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-17 00:40:15 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-17 00:40:15 +0800 |
commit | 54125fb6438e492e2bc1cf4b1c49f4ac94138ed6 (patch) | |
tree | d7b6d01cb82192d7af819c033ee7cabd63fa0d85 /git_hooks_client | |
parent | TODO: Add accessibility notes (diff) | |
download | forge-54125fb6438e492e2bc1cf4b1c49f4ac94138ed6.tar.gz forge-54125fb6438e492e2bc1cf4b1c49f4ac94138ed6.tar.zst forge-54125fb6438e492e2bc1cf4b1c49f4ac94138ed6.zip |
git_hooks{.go,_client}: Add stub for git hook clients
Diffstat (limited to 'git_hooks_client')
-rw-r--r-- | git_hooks_client/.gitignore | 1 | ||||
-rw-r--r-- | git_hooks_client/Makefile | 1 | ||||
-rw-r--r-- | git_hooks_client/git_hooks_client.c | 43 |
3 files changed, 45 insertions, 0 deletions
diff --git a/git_hooks_client/.gitignore b/git_hooks_client/.gitignore new file mode 100644 index 0000000..129c0b4 --- /dev/null +++ b/git_hooks_client/.gitignore @@ -0,0 +1 @@ +/git_hooks_client diff --git a/git_hooks_client/Makefile b/git_hooks_client/Makefile new file mode 100644 index 0000000..0dd283e --- /dev/null +++ b/git_hooks_client/Makefile @@ -0,0 +1 @@ +git_hooks_client: diff --git a/git_hooks_client/git_hooks_client.c b/git_hooks_client/git_hooks_client.c new file mode 100644 index 0000000..b274e03 --- /dev/null +++ b/git_hooks_client/git_hooks_client.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <string.h> + +int main() { + int sock; + struct sockaddr_un addr; + const char *message = "hi"; + const char *socket_path = getenv("LINDENII_FORGE_HOOKS_SOCKET_PATH"); + + if (socket_path == NULL) { + exit(EXIT_FAILURE); + } + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock == -1) { + perror("socket"); + exit(EXIT_FAILURE); + } + + memset(&addr, 0, sizeof(struct sockaddr_un)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1); + + if (connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) == -1) { + perror("connect"); + close(sock); + exit(EXIT_FAILURE); + } + + if (send(sock, message, strlen(message), 0) == -1) { + perror("send"); + close(sock); + exit(EXIT_FAILURE); + } + + close(sock); + + return 0; +} |