use a variant for uname result, not strings

This commit is contained in:
Hannes Mehnert 2019-10-27 19:42:52 +01:00
parent e1239366e1
commit 1d33c17b53
2 changed files with 30 additions and 15 deletions

View file

@ -355,7 +355,23 @@ let should_restart config name = function
126 (bash, unused) command invoked cannot execute
127 (bash, unused) command not found
128+n (bash, unused) fatal error signal n
255 solo5-abort -> OCaml 4.10: fatal error (instead of 2) -> restart *)
255 solo5-abort -> OCaml 4.10: fatal error (instead of 2) -> restart
opam exit codes:
1 False. Returned when a boolean return value is expected, e.g. when running with --check, or for queries like opam lint.
2 Bad command-line arguments, or command-line arguments pointing to an invalid context (e.g. file not following the expected format).
5 Not found. You requested something (package, version, repository, etc.) that couldn't be found.
10 Aborted. The operation required confirmation, which wasn't given.
15 Could not acquire the locks required for the operation.
20 There is no solution to the user request. This can be caused by asking to install two incompatible packages, for example.
30 Error in package definition, or other metadata files. Using --strict raises this error more often.
31 Package script error. Some package operations were unsuccessful. This may be an error in the packages or an incompatibility with your system. This can be a partial error.
40 Sync error. Could not fetch some remotes from the network. This can be a partial error.
50 Configuration error. Opam or system configuration doesn't allow operation, and needs fixing.
60 Solver failure. The solver failed to return a sound answer. It can be due to a broken external solver, or an error in solver configuration.
99 Internal error. Something went wrong, likely due to a bug in opam itself.
130 User interrupt. SIGINT was received, generally due to the user pressing Ctrl-C.
*)
let opt_mem i =
match config.Unikernel.fail_behaviour with
| `Quit -> assert false

View file

@ -89,20 +89,24 @@ let rec fifo_exists file =
| Unix.Unix_error (e, _, _) ->
R.error_msgf "file %a exists: %s" Fpath.pp file (Unix.error_message e)
type supported = FreeBSD | Linux
let uname =
let cmd = Bos.Cmd.(v "uname" % "-s") in
lazy (match Bos.OS.Cmd.(run_out cmd |> out_string) with
| Ok (s, _) -> s
| Ok (s, _) when s = "FreeBSD" -> FreeBSD
| Ok (s, _) when s = "Linux" -> Linux
| Ok (s, _) -> invalid_arg (Printf.sprintf "OS %s not supported" s)
| Error (`Msg m) -> invalid_arg m)
let create_tap bridge =
match Lazy.force uname with
| x when x = "FreeBSD" ->
| FreeBSD ->
let cmd = Bos.Cmd.(v "ifconfig" % "tap" % "create") in
Bos.OS.Cmd.run_out cmd |> Bos.OS.Cmd.out_string >>= fun (name, _) ->
Bos.OS.Cmd.run Bos.Cmd.(v "ifconfig" % bridge % "addm" % name) >>= fun () ->
Ok name
| x when x = "Linux" ->
| Linux ->
let prefix = "vmmtap" in
let rec find_n x =
let nam = prefix ^ string_of_int x in
@ -114,15 +118,13 @@ let create_tap bridge =
Bos.OS.Cmd.run Bos.Cmd.(v "ip" % "tuntap" % "add" % "mode" % "tap" % tap) >>= fun () ->
Bos.OS.Cmd.run Bos.Cmd.(v "brctl" % "addif" % bridge % tap) >>= fun () ->
Ok tap
| x -> Error (`Msg ("unsupported operating system " ^ x))
let destroy_tap tapname =
match Lazy.force uname with
| x when x = "FreeBSD" ->
| FreeBSD ->
Bos.OS.Cmd.run Bos.Cmd.(v "ifconfig" % tapname % "destroy")
| x when x = "Linux" ->
| Linux ->
Bos.OS.Cmd.run Bos.Cmd.(v "ip" % "tuntap" % "del" % "dev" % tapname % "mode" % "tap")
| x -> Error (`Msg ("unsupported operating system " ^ x))
let prepare name vm =
(match vm.Unikernel.typ with
@ -153,8 +155,8 @@ let prepare name vm =
let vm_device vm =
match Lazy.force uname with
| x when x = "FreeBSD" -> Ok ("solo5-" ^ string_of_int vm.Unikernel.pid)
| _ -> Error (`Msg "don't know what you mean, sorry")
| FreeBSD -> Ok ("solo5-" ^ string_of_int vm.Unikernel.pid)
| _ -> Error (`Msg "don't know what you mean (trying to find vm device)")
let free_system_resources name taps =
(* same order as prepare! *)
@ -165,11 +167,8 @@ let free_system_resources name taps =
let cpuset cpu =
let cpustring = string_of_int cpu in
match Lazy.force uname with
| x when x = "FreeBSD" ->
Ok ([ "cpuset" ; "-l" ; cpustring ])
| x when x = "Linux" ->
Ok ([ "taskset" ; "-c" ; cpustring ])
| x -> Error (`Msg ("unsupported operating system " ^ x))
| FreeBSD -> Ok ([ "cpuset" ; "-l" ; cpustring ])
| Linux -> Ok ([ "taskset" ; "-c" ; cpustring ])
let exec name config bridge_taps blocks =
let net, macs =