From f2e537e663dff755ce8941fd93e4a83f6a39a26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Wed, 24 Jul 2024 08:27:38 +0300 Subject: [PATCH 1/7] Remove non-existing reference from README --- controller/Readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/controller/Readme.md b/controller/Readme.md index 82983d7c..63197b7f 100644 --- a/controller/Readme.md +++ b/controller/Readme.md @@ -10,7 +10,6 @@ PlayOS controller is an OCaml application that manages various system tasks for - `bindings/`: bindings to various things - `gui/`: static gui assets -- `nix/`: nix stuff - `server/`: main application code - `bin/`: binaries to start a dev server From 21d12012936c47e33e6878c44bc316ff4635e8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 25 Jul 2024 08:53:59 +0300 Subject: [PATCH 2/7] Disable unused var warnings on obus-generated interfaces --- controller/bindings/connman/dune | 2 ++ controller/bindings/disable-unused-warnings.dune | 4 ++++ controller/bindings/rauc/dune | 2 ++ controller/bindings/systemd/dune | 2 ++ controller/bindings/timedate/dune | 2 ++ 5 files changed, 12 insertions(+) create mode 100644 controller/bindings/disable-unused-warnings.dune diff --git a/controller/bindings/connman/dune b/controller/bindings/connman/dune index 77af8abe..9e4412ae 100644 --- a/controller/bindings/connman/dune +++ b/controller/bindings/connman/dune @@ -1,3 +1,5 @@ +(include ../disable-unused-warnings.dune) + (library (name connman) (modules connman connman_interfaces) diff --git a/controller/bindings/disable-unused-warnings.dune b/controller/bindings/disable-unused-warnings.dune new file mode 100644 index 00000000..1121352f --- /dev/null +++ b/controller/bindings/disable-unused-warnings.dune @@ -0,0 +1,4 @@ +; obus generates bindings that contains a lot of unused variables/bindings +; and dune treats these as errors, so we disable them here +(env (dev (flags :standard -w -27-32-33))) + diff --git a/controller/bindings/rauc/dune b/controller/bindings/rauc/dune index c7134592..416152b3 100644 --- a/controller/bindings/rauc/dune +++ b/controller/bindings/rauc/dune @@ -1,3 +1,5 @@ +(include ../disable-unused-warnings.dune) + (library (name rauc) (modules rauc rauc_interfaces) diff --git a/controller/bindings/systemd/dune b/controller/bindings/systemd/dune index f99c4bc4..799a339b 100644 --- a/controller/bindings/systemd/dune +++ b/controller/bindings/systemd/dune @@ -1,3 +1,5 @@ +(include ../disable-unused-warnings.dune) + (library (name systemd) (modules systemd systemd_interfaces) diff --git a/controller/bindings/timedate/dune b/controller/bindings/timedate/dune index 2a5b8a33..6ad3ef10 100644 --- a/controller/bindings/timedate/dune +++ b/controller/bindings/timedate/dune @@ -1,3 +1,5 @@ +(include ../disable-unused-warnings.dune) + (library (name timedate) (modules timedate timedate_interfaces) From c8673c6ee1fe522ff482aecc74da6c6ead40d179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 25 Jul 2024 22:41:20 +0300 Subject: [PATCH 3/7] Disable missing-record-field-pattern warnings in controller --- controller/dune | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/controller/dune b/controller/dune index 8f496cf2..e290626f 100644 --- a/controller/dune +++ b/controller/dune @@ -5,3 +5,7 @@ (gui/reset.css as static/reset.css) (gui/style.css as static/style.css) (gui/client.js as static/client.js))) + +; disable missing-record-field-pattern warnings (partial matching), +; because they are kind of useless +(env (dev (flags :standard -w -9))) From 7ce51d558040ca23b3f3de85832ebd96e6d68c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 25 Jul 2024 22:43:15 +0300 Subject: [PATCH 4/7] Remove unused argument from update_static_ip --- controller/server/gui.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/server/gui.ml b/controller/server/gui.ml index 17bc7934..540d65d8 100644 --- a/controller/server/gui.ml +++ b/controller/server/gui.ml @@ -315,7 +315,7 @@ module NetworkGui = struct fail_with "A host and port are required to configure a proxy server" (** Set static IP configuration on a service *) - let update_static_ip ~(connman: Connman.Manager.t) service form_data = + let update_static_ip service form_data = let get_prop s = form_data |> List.assoc s @@ -362,7 +362,7 @@ module NetworkGui = struct let%lwt service = with_service ~connman (param req "id") in (* Static IP *) - let%lwt () = update_static_ip ~connman service form_data in + let%lwt () = update_static_ip service form_data in (* Proxy *) let%lwt current_proxy = Manager.get_default_proxy connman in From 59b07126160acf6f8df634d5e6ad9456798ca247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 25 Jul 2024 22:44:28 +0300 Subject: [PATCH 5/7] Fix all unused variable/binding warnings Combined with the earlier commits, now `dune build` works without `--profile release` i.e. there are no more warnings raised by ocamlc. --- controller/bindings/curl/curl.ml | 4 ++-- controller/bindings/util/util.ml | 6 +++--- controller/server/gui.ml | 18 +++++++----------- controller/server/network.ml | 2 +- controller/server/server.ml | 1 - controller/server/update.ml | 1 - 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/controller/bindings/curl/curl.ml b/controller/bindings/curl/curl.ml index 14593565..bf400189 100644 --- a/controller/bindings/curl/curl.ml +++ b/controller/bindings/curl/curl.ml @@ -112,10 +112,10 @@ let request ?proxy ?(headers = []) ?data ?(options = []) url = | Ok (Unix.WEXITED n, _, stderr) -> Lwt.return (RequestFailure (ProcessExit (n, stderr))) - | Ok (Unix.WSIGNALED signal, _, stderr) -> + | Ok (Unix.WSIGNALED signal, _, _stderr) -> Lwt.return (RequestFailure (ProcessKill signal)) - | Ok (Unix.WSTOPPED signal, _, stderr) -> + | Ok (Unix.WSTOPPED signal, _, _stderr) -> Lwt.return (RequestFailure (ProcessStop signal)) | Error (Unix.Unix_error (err, _, _)) -> diff --git a/controller/bindings/util/util.ml b/controller/bindings/util/util.ml index 6dc07119..6db70a59 100644 --- a/controller/bindings/util/util.ml +++ b/controller/bindings/util/util.ml @@ -9,7 +9,7 @@ let read_from_file log_src path = let%lwt () = Lwt_io.close in_chan in return contents with - | (Unix.Unix_error (err, fn, _)) as exn -> + | (Unix.Unix_error (err, _fn, _)) as exn -> let%lwt () = Logs_lwt.err ~src:log_src (fun m -> m "failed to read from %s: %s" path (Unix.error_message err)) in @@ -27,12 +27,12 @@ let write_to_file log_src path str = let%lwt fd = Lwt_unix.openfile path [ O_WRONLY; O_CREAT; O_TRUNC ] 0o755 in - let%lwt bytes_written = + let%lwt _bytes_written = Lwt_unix.write_string fd str 0 (String.length str) in Lwt_unix.close fd with - | (Unix.Unix_error (err, fn, _)) as exn -> + | (Unix.Unix_error (err, _fn, _)) as exn -> let%lwt () = Logs_lwt.err ~src:log_src (fun m -> m "failed to write to %s: %s" path (Unix.error_message err)) in diff --git a/controller/server/gui.ml b/controller/server/gui.ml index 540d65d8..91f37d81 100644 --- a/controller/server/gui.ml +++ b/controller/server/gui.ml @@ -2,7 +2,6 @@ open Lwt open Sexplib.Std open Opium_kernel.Rock open Opium.App -open Sys let log_src = Logs.Src.create "gui" @@ -70,7 +69,7 @@ end (** Localization GUI *) module LocalizationGui = struct - let overview req = + let overview _req = let%lwt td_daemon = Timedate.daemon () in let%lwt current_timezone = Timedate.get_configured_timezone () in let%lwt all_timezones = Timedate.get_available_timezones td_daemon in @@ -140,7 +139,7 @@ module LocalizationGui = struct })) let set_timezone req = - let%lwt td_daemon = Timedate.daemon () in + let%lwt _td_daemon = Timedate.daemon () in let%lwt form_data = urlencoded_pairs_of_body req in @@ -207,9 +206,8 @@ end module NetworkGui = struct open Connman - open Network - let overview ~(connman:Manager.t) req = + let overview ~(connman:Manager.t) _req = let%lwt all_services = Manager.get_services connman in @@ -240,11 +238,11 @@ module NetworkGui = struct match%lwt Curl.request ?proxy:(Option.map (Service.Proxy.to_uri ~include_userinfo:true) proxy) (Uri.of_string "http://captive.dividat.com/") with | RequestSuccess (code, response) -> `String response - |> respond ?code:(Some (Cohttp.Code.(`Code code))) + |> respond ?code:(Some (`Code code)) |> Lwt.return | RequestFailure err -> `String (Format.sprintf "Error reaching captive portal: %s" (Curl.pretty_print_error err)) - |> respond ?code:(Some Cohttp.Code.(`Service_unavailable)) + |> respond ?code:(Some `Service_unavailable) |> Lwt.return (** Helper to find a service by id *) @@ -323,8 +321,6 @@ module NetworkGui = struct in match form_data |> List.assoc_opt "static_ip_enabled" with | None -> - let open Cohttp in - let open Cohttp_lwt_unix in let%lwt () = Logs_lwt.err ~src:log_src (fun m -> m "disabling static ip %s" (get_prop "static_ip_address")) in @@ -426,7 +422,7 @@ module LabelGui = struct ) } : Label_printer.label) - let overview req = + let overview _req = let%lwt label = make_label () in Lwt.return (page (Label_page.html label)) @@ -458,7 +454,7 @@ end module StatusGui = struct let build ~health_s ~update_s ~rauc app = app - |> get "/status" (fun req -> + |> get "/status" (fun _req -> let%lwt rauc = match update_s |> Lwt_react.S.value with (* RAUC status is not meaningful while installing diff --git a/controller/server/network.ml b/controller/server/network.ml index 5495162d..28f2960e 100644 --- a/controller/server/network.ml +++ b/controller/server/network.ml @@ -1,7 +1,7 @@ open Lwt open Sexplib.Std -let log_src = Logs.Src.create "network" +let _log_src = Logs.Src.create "network" let enable_and_scan_wifi_devices ~connman = Lwt_result.catch diff --git a/controller/server/server.ml b/controller/server/server.ml index 41a05f77..9f67b200 100644 --- a/controller/server/server.ml +++ b/controller/server/server.ml @@ -1,5 +1,4 @@ open Lwt -open Sexplib.Std let shutdown () = match%lwt diff --git a/controller/server/update.ml b/controller/server/update.ml index ac27f108..963e7599 100644 --- a/controller/server/update.ml +++ b/controller/server/update.ml @@ -1,5 +1,4 @@ open Lwt -open Sexplib.Std open Sexplib.Conv let log_src = Logs.Src.create "update" From 1775ef7948ce8643c0439fd09b89e383f217b44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 1 Aug 2024 12:19:14 +0300 Subject: [PATCH 6/7] Elaborate comments on disabled warnings --- controller/bindings/disable-unused-warnings.dune | 6 ++++-- controller/dune | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/controller/bindings/disable-unused-warnings.dune b/controller/bindings/disable-unused-warnings.dune index 1121352f..067c37ef 100644 --- a/controller/bindings/disable-unused-warnings.dune +++ b/controller/bindings/disable-unused-warnings.dune @@ -1,4 +1,6 @@ -; obus generates bindings that contains a lot of unused variables/bindings -; and dune treats these as errors, so we disable them here +; OBus generates bindings that contains a lot of unused variables/bindings +; and dune treats these as errors, so we disable them here. +; Refer to ocamlc man pages or `ocamlc -warn-help` for descriptions of +; the warning numbers. (env (dev (flags :standard -w -27-32-33))) diff --git a/controller/dune b/controller/dune index e290626f..5d996ef9 100644 --- a/controller/dune +++ b/controller/dune @@ -6,6 +6,7 @@ (gui/style.css as static/style.css) (gui/client.js as static/client.js))) -; disable missing-record-field-pattern warnings (partial matching), -; because they are kind of useless +; Disable missing-record-field-pattern warnings (partial matching), +; because they are kind of useless. +; See https://ocaml.org/manual/4.14/comp.html#ss:warn9 for details. (env (dev (flags :standard -w -9))) From 0dbdea9e262fb7d9eb84c3a1f948c6b15617a2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 1 Aug 2024 12:26:42 +0300 Subject: [PATCH 7/7] Use the defined log_src in the Network module --- controller/server/network.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/controller/server/network.ml b/controller/server/network.ml index 28f2960e..9780fc7b 100644 --- a/controller/server/network.ml +++ b/controller/server/network.ml @@ -1,7 +1,7 @@ open Lwt open Sexplib.Std -let _log_src = Logs.Src.create "network" +let log_src = Logs.Src.create "network" let enable_and_scan_wifi_devices ~connman = Lwt_result.catch @@ -36,7 +36,8 @@ let enable_and_scan_wifi_devices ~connman = let init ~connman = - let%lwt () = Logs_lwt.info (fun m -> m "initializing network connections") in + let%lwt () = Logs_lwt.info ~src:log_src + (fun m -> m "initializing network connections") in match%lwt enable_and_scan_wifi_devices ~connman with @@ -44,7 +45,7 @@ let init ~connman = Lwt_result.return () | Error exn -> - let%lwt () = Logs_lwt.warn + let%lwt () = Logs_lwt.warn ~src:log_src (fun m -> m "enabling and scanning wifi failed: %s, %s" (OBus_error.name exn) (Printexc.to_string exn))