# Libtmux_unix.with_private_daemon

- **Package:** libtmux-unix
- **Language:** OCaml
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-ocaml/blob/2d1ad87c94730daaa2569d4589fe53f9edc2962b/unix/libtmux_unix.mli#L948
- **Public owner:** Libtmux_unix
- **Page:** https://libtmux.org/en/ocaml/latest/reference/libtmux_unix-with_private_daemon/

```
val with_private_daemon :
  ?cleanup:Cleanup.t ->
  ?binary:string ->
  ?config_file:string ->
  ?root:string ->
  ?session:string ->
  ?timeout:float ->
  (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_unix-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_unix-workspace-submit_bootstrap/). Close every client made for `endpoint` before `f` returns.

On every exit of `f`, including an exception, 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`.

## Parameters

- `cleanup?` (`Cleanup.t`)
- `binary?` (`string`)
- `config_file?` (`string`)
- `root?` (`string`)
- `session?` (`string`)
- `timeout?` (`float`)
- `arg1` (`Libtmux.Endpoint.t -> 'a`)
