diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-07 15:15:29 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-07 15:15:29 +0800 |
commit | f401f0be89cf5ca29278cc836cdb50faca4613aa (patch) | |
tree | 8a605eb51bc77e4addf38cde3be1bd68b54d5522 /git_hooks_client | |
parent | sql: Add "federated" as a user state and a contrib requirement option (diff) | |
download | forge-f401f0be89cf5ca29278cc836cdb50faca4613aa.tar.gz forge-f401f0be89cf5ca29278cc836cdb50faca4613aa.tar.zst forge-f401f0be89cf5ca29278cc836cdb50faca4613aa.zip |
hooks: Send/process environment variables starting with GIT_
Diffstat (limited to 'git_hooks_client')
-rw-r--r-- | git_hooks_client/git_hooks_client.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/git_hooks_client/git_hooks_client.c b/git_hooks_client/git_hooks_client.c index fc49d91..bdc6dc2 100644 --- a/git_hooks_client/git_hooks_client.c +++ b/git_hooks_client/git_hooks_client.c @@ -154,6 +154,38 @@ int main(int argc, char *argv[]) { } /* + * Then send all environment variables that begin with "GIT_" + */ + extern char **environ; + for (char **env = environ; *env != NULL; env++) { + if (strncmp(*env, "GIT_", 4) == 0) { + unsigned long len = strlen(*env) + 1; + bytes_sent = send(sock, *env, len, 0); + if (bytes_sent == -1) { + perror("send env"); + close(sock); + exit(EXIT_FAILURE); + } else if ((unsigned long)bytes_sent == len) { + } else { + dprintf(STDERR_FILENO, "send returned unexpected value on internal socket\n"); + close(sock); + exit(EXIT_FAILURE); + } + } + } + bytes_sent = send(sock, "", 1, 0); + if (bytes_sent == -1) { + perror("send env terminator"); + close(sock); + exit(EXIT_FAILURE); + } else if (bytes_sent == 1) { + } else { + dprintf(STDERR_FILENO, "send returned unexpected value on internal socket\n"); + close(sock); + exit(EXIT_FAILURE); + } + + /* * Now we can start splicing data from stdin to the UNIX domain socket. * The format is irrelevant and depends on the hook being called. All we * do is pass it to the socket for it to handle. |