package oxbow

  1. Overview
  2. Docs
Dynamic window manager for the river Wayland compositor

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.0.tar.gz
md5=a637acaa0e19046cd65fff733874eb97
sha512=76230cbecd7510de7a05b5d1f335915ef7b6c4aa557d8dbfd23591606618d2cfa25082d17b93f2f4b53a118d1cbf6a80e4ad51cf0f099b4921fb83d6df0c9801

doc/src/oxbow.state/init_script.ml.html

Source file init_script.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
open! Oxbow_core

type t = { pid : int }

let init_path path =
  try
    Unix.access path [ Unix.X_OK ];
    Some path
  with
  | Unix.Unix_error (e, _, _) ->
    (Log.err @@ fun m -> m "invalid init path %S: %s" path (Unix.error_message e));
    None
;;

let resolve ?override_path () =
  match override_path with
  | Some path -> init_path path
  | None ->
    let config_dir =
      match Sys.getenv_opt "XDG_CONFIG_HOME" with
      | Some d -> Some (d ^ "/oxbow/init")
      | None ->
        (match Sys.getenv_opt "HOME" with
         | Some d -> Some (d ^ "/.config/oxbow/init")
         | None -> None)
    in
    (match config_dir with
     | None ->
       (Log.err
        @@ fun m ->
        m "unable to locate $XDG_CONFIG_HOME or $HOME. Please check your environment");
       None
     | Some path -> init_path path)
;;

let fork ~cmd =
  let argv = [| "/bin/sh"; "-c"; cmd |] in
  match Unix.fork () with
  | 0 ->
    (try Unix.setsid () |> ignore with
     | Unix.Unix_error _ ->
       Printf.eprintf "oxbow: [ERROR] Failed setsid during init script fork: %S\n" cmd);
    (try Unix.execv argv.(0) argv with
     | _ -> Printf.eprintf "oxbow: [ERROR] Failed to exec init script: %S\n" cmd);
    Stdlib.exit Exit.unavailable
  | pid -> { pid }
;;

let shutdown { pid } =
  try Unix.kill pid Sys.sigterm with
  | Unix.Unix_error (Unix.ESRCH, _, _) -> ()
  | Unix.Unix_error (e, _, _) ->
    Log.warn
    @@ fun m -> m "init_script.shutdown: kill -%d failed: %s" pid (Unix.error_message e)
;;