Skip to content

Commit b330008

Browse files
committed
Merge branch 'jk/close-stderr-of-credential-cache-deamon'
Plug fd leaks. * jk/close-stderr-of-credential-cache-deamon: credential-cache: close stderr in daemon process
2 parents bdab1bc + f5e3c0b commit b330008

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Documentation/git-credential-cache--daemon.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-credential-cache--daemon - Temporarily store user credentials in memory
88
SYNOPSIS
99
--------
1010
[verse]
11-
git credential-cache--daemon <socket>
11+
git credential-cache--daemon [--debug] <socket>
1212

1313
DESCRIPTION
1414
-----------
@@ -21,6 +21,10 @@ for `git-credential-cache` clients. Clients may store and retrieve
2121
credentials. Each credential is held for a timeout specified by the
2222
client; once no credentials are held, the daemon exits.
2323

24+
If the `--debug` option is specified, the daemon does not close its
25+
stderr stream, and may output extra diagnostics to it even after it has
26+
begun listening for clients.
27+
2428
GIT
2529
---
2630
Part of the linkgit:git[1] suite

credential-cache--daemon.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "credential.h"
33
#include "unix-socket.h"
44
#include "sigchain.h"
5+
#include "parse-options.h"
56

67
static const char *socket_path;
78

@@ -201,7 +202,7 @@ static int serve_cache_loop(int fd)
201202
return 1;
202203
}
203204

204-
static void serve_cache(const char *socket_path)
205+
static void serve_cache(const char *socket_path, int debug)
205206
{
206207
int fd;
207208

@@ -211,6 +212,10 @@ static void serve_cache(const char *socket_path)
211212

212213
printf("ok\n");
213214
fclose(stdout);
215+
if (!debug) {
216+
if (!freopen("/dev/null", "w", stderr))
217+
die_errno("unable to point stderr to /dev/null");
218+
}
214219

215220
while (serve_cache_loop(fd))
216221
; /* nothing */
@@ -252,16 +257,28 @@ static void check_socket_directory(const char *path)
252257

253258
int main(int argc, const char **argv)
254259
{
255-
socket_path = argv[1];
260+
static const char *usage[] = {
261+
"git-credential-cache--daemon [opts] <socket_path>",
262+
NULL
263+
};
264+
int debug = 0;
265+
const struct option options[] = {
266+
OPT_BOOL(0, "debug", &debug,
267+
N_("print debugging messages to stderr")),
268+
OPT_END()
269+
};
270+
271+
argc = parse_options(argc, argv, NULL, options, usage, 0);
272+
socket_path = argv[0];
256273

257274
if (!socket_path)
258-
die("usage: git-credential-cache--daemon <socket_path>");
275+
usage_with_options(usage, options);
259276
check_socket_directory(socket_path);
260277

261278
atexit(cleanup_socket);
262279
sigchain_push_common(cleanup_socket_on_signal);
263280

264-
serve_cache(socket_path);
281+
serve_cache(socket_path, debug);
265282

266283
return 0;
267284
}

0 commit comments

Comments
 (0)