|
1 | 1 | #include "cache.h"
|
2 | 2 | #include "pkt-line.h"
|
3 | 3 | #include "exec_cmd.h"
|
| 4 | +#include "run-command.h" |
| 5 | +#include "strbuf.h" |
4 | 6 |
|
5 | 7 | #include <syslog.h>
|
6 | 8 |
|
@@ -343,28 +345,66 @@ static int run_service(char *dir, struct daemon_service *service)
|
343 | 345 | return service->fn();
|
344 | 346 | }
|
345 | 347 |
|
| 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 | + |
346 | 388 | static int upload_pack(void)
|
347 | 389 | {
|
348 | 390 | /* Timeout as string */
|
349 | 391 | char timeout_buf[64];
|
| 392 | + const char *argv[] = { "upload-pack", "--strict", timeout_buf, ".", NULL }; |
350 | 393 |
|
351 | 394 | 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); |
356 | 396 | }
|
357 | 397 |
|
358 | 398 | static int upload_archive(void)
|
359 | 399 | {
|
360 |
| - execl_git_cmd("upload-archive", ".", NULL); |
361 |
| - return -1; |
| 400 | + static const char *argv[] = { "upload-archive", ".", NULL }; |
| 401 | + return run_service_command(argv); |
362 | 402 | }
|
363 | 403 |
|
364 | 404 | static int receive_pack(void)
|
365 | 405 | {
|
366 |
| - execl_git_cmd("receive-pack", ".", NULL); |
367 |
| - return -1; |
| 406 | + static const char *argv[] = { "receive-pack", ".", NULL }; |
| 407 | + return run_service_command(argv); |
368 | 408 | }
|
369 | 409 |
|
370 | 410 | static struct daemon_service daemon_service[] = {
|
|
0 commit comments