Skip to content

Commit a4103ba

Browse files
committed
Merge branch 'js/daemon-log'
* js/daemon-log: receive-pack: do not send error details to the client upload-pack: squelch progress indicator if client cannot see it daemon: send stderr of service programs to the syslog
2 parents 59773c7 + 2ff4d1a commit a4103ba

File tree

3 files changed

+76
-40
lines changed

3 files changed

+76
-40
lines changed

builtin-receive-pack.c

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,27 @@ static struct command *commands;
123123
static const char pre_receive_hook[] = "hooks/pre-receive";
124124
static const char post_receive_hook[] = "hooks/post-receive";
125125

126-
static int hook_status(int code, const char *hook_name)
126+
static int run_status(int code, const char *cmd_name)
127127
{
128128
switch (code) {
129129
case 0:
130130
return 0;
131131
case -ERR_RUN_COMMAND_FORK:
132-
return error("hook fork failed");
132+
return error("fork of %s failed", cmd_name);
133133
case -ERR_RUN_COMMAND_EXEC:
134-
return error("hook execute failed");
134+
return error("execute of %s failed", cmd_name);
135135
case -ERR_RUN_COMMAND_PIPE:
136-
return error("hook pipe failed");
136+
return error("pipe failed");
137137
case -ERR_RUN_COMMAND_WAITPID:
138138
return error("waitpid failed");
139139
case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
140140
return error("waitpid is confused");
141141
case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
142-
return error("%s died of signal", hook_name);
142+
return error("%s died of signal", cmd_name);
143143
case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
144-
return error("%s died strangely", hook_name);
144+
return error("%s died strangely", cmd_name);
145145
default:
146-
error("%s exited with error code %d", hook_name, -code);
146+
error("%s exited with error code %d", cmd_name, -code);
147147
return -code;
148148
}
149149
}
@@ -174,7 +174,7 @@ static int run_receive_hook(const char *hook_name)
174174

175175
code = start_command(&proc);
176176
if (code)
177-
return hook_status(code, hook_name);
177+
return run_status(code, hook_name);
178178
for (cmd = commands; cmd; cmd = cmd->next) {
179179
if (!cmd->error_string) {
180180
size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n",
@@ -186,7 +186,7 @@ static int run_receive_hook(const char *hook_name)
186186
}
187187
}
188188
close(proc.in);
189-
return hook_status(finish_command(&proc), hook_name);
189+
return run_status(finish_command(&proc), hook_name);
190190
}
191191

192192
static int run_update_hook(struct command *cmd)
@@ -203,7 +203,7 @@ static int run_update_hook(struct command *cmd)
203203
argv[3] = sha1_to_hex(cmd->new_sha1);
204204
argv[4] = NULL;
205205

206-
return hook_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
206+
return run_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
207207
RUN_COMMAND_STDOUT_TO_STDERR),
208208
update_hook);
209209
}
@@ -394,7 +394,7 @@ static char update_post_hook[] = "hooks/post-update";
394394
static void run_update_post_hook(struct command *cmd)
395395
{
396396
struct command *cmd_p;
397-
int argc;
397+
int argc, status;
398398
const char **argv;
399399

400400
for (argc = 0, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) {
@@ -417,8 +417,9 @@ static void run_update_post_hook(struct command *cmd)
417417
argc++;
418418
}
419419
argv[argc] = NULL;
420-
run_command_v_opt(argv, RUN_COMMAND_NO_STDIN
421-
| RUN_COMMAND_STDOUT_TO_STDERR);
420+
status = run_command_v_opt(argv, RUN_COMMAND_NO_STDIN
421+
| RUN_COMMAND_STDOUT_TO_STDERR);
422+
run_status(status, update_post_hook);
422423
}
423424

424425
static void execute_commands(const char *unpacker_error)
@@ -534,24 +535,10 @@ static const char *unpack(void)
534535
unpacker[i++] = hdr_arg;
535536
unpacker[i++] = NULL;
536537
code = run_command_v_opt(unpacker, RUN_GIT_CMD);
537-
switch (code) {
538-
case 0:
538+
if (!code)
539539
return NULL;
540-
case -ERR_RUN_COMMAND_FORK:
541-
return "unpack fork failed";
542-
case -ERR_RUN_COMMAND_EXEC:
543-
return "unpack execute failed";
544-
case -ERR_RUN_COMMAND_WAITPID:
545-
return "waitpid failed";
546-
case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
547-
return "waitpid is confused";
548-
case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
549-
return "unpacker died of signal";
550-
case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
551-
return "unpacker died strangely";
552-
default:
553-
return "unpacker exited with error code";
554-
}
540+
run_status(code, unpacker[0]);
541+
return "unpack-objects abnormal exit";
555542
} else {
556543
const char *keeper[7];
557544
int s, status, i = 0;
@@ -574,15 +561,19 @@ static const char *unpack(void)
574561
ip.argv = keeper;
575562
ip.out = -1;
576563
ip.git_cmd = 1;
577-
if (start_command(&ip))
564+
status = start_command(&ip);
565+
if (status) {
566+
run_status(status, keeper[0]);
578567
return "index-pack fork failed";
568+
}
579569
pack_lockfile = index_pack_lockfile(ip.out);
580570
close(ip.out);
581571
status = finish_command(&ip);
582572
if (!status) {
583573
reprepare_packed_git();
584574
return NULL;
585575
}
576+
run_status(status, keeper[0]);
586577
return "index-pack abnormal exit";
587578
}
588579
}

daemon.c

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "cache.h"
22
#include "pkt-line.h"
33
#include "exec_cmd.h"
4+
#include "run-command.h"
5+
#include "strbuf.h"
46

57
#include <syslog.h>
68

@@ -343,28 +345,66 @@ static int run_service(char *dir, struct daemon_service *service)
343345
return service->fn();
344346
}
345347

348+
static void copy_to_log(int fd)
349+
{
350+
struct strbuf line = STRBUF_INIT;
351+
FILE *fp;
352+
353+
fp = fdopen(fd, "r");
354+
if (fp == NULL) {
355+
logerror("fdopen of error channel failed");
356+
close(fd);
357+
return;
358+
}
359+
360+
while (strbuf_getline(&line, fp, '\n') != EOF) {
361+
logerror("%s", line.buf);
362+
strbuf_setlen(&line, 0);
363+
}
364+
365+
strbuf_release(&line);
366+
fclose(fp);
367+
}
368+
369+
static int run_service_command(const char **argv)
370+
{
371+
struct child_process cld;
372+
373+
memset(&cld, 0, sizeof(cld));
374+
cld.argv = argv;
375+
cld.git_cmd = 1;
376+
cld.err = -1;
377+
if (start_command(&cld))
378+
return -1;
379+
380+
close(0);
381+
close(1);
382+
383+
copy_to_log(cld.err);
384+
385+
return finish_command(&cld);
386+
}
387+
346388
static int upload_pack(void)
347389
{
348390
/* Timeout as string */
349391
char timeout_buf[64];
392+
const char *argv[] = { "upload-pack", "--strict", timeout_buf, ".", NULL };
350393

351394
snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout);
352-
353-
/* git-upload-pack only ever reads stuff, so this is safe */
354-
execl_git_cmd("upload-pack", "--strict", timeout_buf, ".", NULL);
355-
return -1;
395+
return run_service_command(argv);
356396
}
357397

358398
static int upload_archive(void)
359399
{
360-
execl_git_cmd("upload-archive", ".", NULL);
361-
return -1;
400+
static const char *argv[] = { "upload-archive", ".", NULL };
401+
return run_service_command(argv);
362402
}
363403

364404
static int receive_pack(void)
365405
{
366-
execl_git_cmd("receive-pack", ".", NULL);
367-
return -1;
406+
static const char *argv[] = { "receive-pack", ".", NULL };
407+
return run_service_command(argv);
368408
}
369409

370410
static struct daemon_service daemon_service[] = {

upload-pack.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static unsigned long oldest_have;
2828

2929
static int multi_ack, nr_our_refs;
3030
static int use_thin_pack, use_ofs_delta, use_include_tag;
31-
static int no_progress;
31+
static int no_progress, daemon_mode;
3232
static struct object_array have_obj;
3333
static struct object_array want_obj;
3434
static unsigned int timeout;
@@ -521,6 +521,10 @@ static void receive_needs(void)
521521
}
522522
if (debug_fd)
523523
write_in_full(debug_fd, "#E\n", 3);
524+
525+
if (!use_sideband && daemon_mode)
526+
no_progress = 1;
527+
524528
if (depth == 0 && shallows.nr == 0)
525529
return;
526530
if (depth > 0) {
@@ -630,6 +634,7 @@ int main(int argc, char **argv)
630634
}
631635
if (!prefixcmp(arg, "--timeout=")) {
632636
timeout = atoi(arg+10);
637+
daemon_mode = 1;
633638
continue;
634639
}
635640
if (!strcmp(arg, "--")) {

0 commit comments

Comments
 (0)