| 1509 | } |
| 1510 | |
| 1511 | static int try_to_start_background_daemon(void) |
| 1512 | { |
| 1513 | struct child_process cp = CHILD_PROCESS_INIT; |
| 1514 | enum start_bg_result sbgr; |
| 1515 | |
| 1516 | /* |
| 1517 | * Before we try to create a background daemon process, see |
| 1518 | * if a daemon process is already listening. This makes it |
| 1519 | * easier for us to report an already-listening error to the |
| 1520 | * console, since our spawn/daemon can only report the success |
| 1521 | * of creating the background process (and not whether it |
| 1522 | * immediately exited). |
| 1523 | */ |
| 1524 | if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING) |
| 1525 | die(_("fsmonitor--daemon is already running '%s'"), |
| 1526 | the_repository->worktree); |
| 1527 | |
| 1528 | if (fsmonitor__announce_startup) { |
| 1529 | fprintf(stderr, _("starting fsmonitor-daemon in '%s'\n"), |
| 1530 | the_repository->worktree); |
| 1531 | fflush(stderr); |
| 1532 | } |
| 1533 | |
| 1534 | cp.git_cmd = 1; |
| 1535 | |
| 1536 | strvec_push(&cp.args, "fsmonitor--daemon"); |
| 1537 | strvec_push(&cp.args, "run"); |
| 1538 | strvec_push(&cp.args, "--detach"); |
| 1539 | strvec_pushf(&cp.args, "--ipc-threads=%d", fsmonitor__ipc_threads); |
| 1540 | |
| 1541 | cp.no_stdin = 1; |
| 1542 | cp.no_stdout = 1; |
| 1543 | cp.no_stderr = 1; |
| 1544 | cp.close_fd_above_stderr = 1; |
| 1545 | |
| 1546 | sbgr = start_bg_command(&cp, bg_wait_cb, NULL, |
| 1547 | fsmonitor__start_timeout_sec); |
| 1548 | |
| 1549 | switch (sbgr) { |
| 1550 | case SBGR_READY: |
| 1551 | return 0; |
| 1552 | |
| 1553 | default: |
| 1554 | case SBGR_ERROR: |
| 1555 | case SBGR_CB_ERROR: |
| 1556 | return error(_("daemon failed to start")); |
| 1557 | |
| 1558 | case SBGR_TIMEOUT: |
| 1559 | return error(_("daemon not online yet")); |
| 1560 | |
| 1561 | case SBGR_DIED: |
| 1562 | return error(_("daemon terminated")); |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | int cmd_fsmonitor__daemon(int argc, |
| 1567 | const char **argv, |
no test coverage detected