# Libtmux_eio.with_private_daemon

- **Package:** libtmux-eio
- **Language:** OCaml
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-ocaml/blob/2d1ad87c94730daaa2569d4589fe53f9edc2962b/eio/libtmux_eio.mli#L669
- **Public owner:** Libtmux_eio
- **Page:** https://libtmux.org/en/ocaml/latest/reference/libtmux_eio-with_private_daemon/

```
val with_private_daemon :
  ?cleanup:Cleanup.t ->
  ?binary:string ->
  ?config_file:string ->
  ?root:string ->
  ?session:string ->
  ?timeout:float ->
  process_mgr:[> [> `Generic ] Eio.Process.mgr_ty ] Eio.Process.mgr ->
  mono_clock:[> Eio.Time.Mono.ty ] Eio.Time.Mono.t ->
  (Libtmux.Endpoint.t -> 'a) -> ('a, Libtmux.Error.t) result
```

Run `f` against a tmux daemon this call starts and owns, then stop it. The daemon listens on a socket in a fresh directory, created mode `0700` under `root` (default: the system temporary directory) and named with the prefix `libtmux-ocaml-`. It reads `config_file`, or nothing when none is given, instead of any default configuration. Neither `TMUX` nor `TMUX_PANE` reaches it. A `root` whose socket path would exceed the 107 bytes of a Unix socket address returns [`Libtmux.Error.Invalid_input`](/en/ocaml/latest/reference/libtmux-error-t-invalid_input/) before anything is created.

`f` receives the [`Libtmux.Endpoint.t`](/en/ocaml/latest/reference/libtmux-endpoint-t/) once the socket answers, within `timeout` seconds (default 5). The daemon stays alive until it is stopped, even with no session. [`Client.connect`](/en/ocaml/latest/reference/libtmux_eio-client-connect/) needs a session to attach to, so pass `session` to start the daemon with one detached session of that name, with a single window named `main` running `/bin/cat -u`, or create the first session with [`Workspace.submit_bootstrap`](/en/ocaml/latest/workspace/reference/libtmux_eio-workspace-submit_bootstrap/). Close every client made for `endpoint` before `f` returns.

On every exit of `f`, including an exception or Eio cancellation, the daemon is terminated and reaped, the call checks that nothing answers the socket, and the directory is removed. An exception from `f` propagates after cleanup, and a cleanup failure never replaces it; failures are retained in `cleanup`. When `f` returns, a cleanup failure is the result. A daemon that still answers, or one that cannot be reaped, leaves the directory in place and returns [`Libtmux.Error.Filesystem`](/en/ocaml/latest/reference/libtmux-error-t-filesystem/) or the cleanup error with its path. Normal return gives `Ok` of the value of `f`. The helper runs `f` in its own switch. The daemon's child process and cleanup are not cancellable: cancellation of the calling fiber waits for the daemon's termination before it propagates.

## Parameters

- `cleanup?` (`Cleanup.t`)
- `binary?` (`string`)
- `config_file?` (`string`)
- `root?` (`string`)
- `session?` (`string`)
- `timeout?` (`float`)
- `process_mgr` (``[> [> `Generic ] Eio.Process.mgr_ty ] Eio.Process.mgr``)
- `mono_clock` (`[> Eio.Time.Mono.ty ] Eio.Time.Mono.t`)
- `arg1` (`Libtmux.Endpoint.t -> 'a`)

## Guides

Pages that discuss `with_private_daemon`.

- [Recover an operation after cancelling its waiter](/en/ocaml/latest/guides/recovery/)
