Commit 4ebca0f0 authored by Fardale's avatar Fardale

add limit to stdout and stderr

parent ed527f71
open Lwt.Infix
open Serialization_t
let max_std = 5120000 (* 5Mo *)
let process_status_to_ret_code = function
| Unix.WEXITED c -> `WEXITED c
| Unix.WSIGNALED s -> `WSIGNALED s
......@@ -25,8 +27,14 @@ let run_computation (computation : computation) =
and stderr = Lwt_io.read (Lwt_io.of_fd ~mode:Lwt_io.input read_stderr) in
Lwt.return
{ id= computation.id
; stdout
; stderr
; stdout=
( if String.length stdout > max_std then
CCString.drop (String.length stdout - max_std) stdout
else stdout )
; stderr=
( if String.length stderr > max_std then
CCString.drop (String.length stderr - max_std) stderr
else stderr )
; ret_code= process_status_to_ret_code ret_code
; pass= computation.pass } )
......@@ -61,8 +69,7 @@ let server_handler pass sockaddr (ic, oc) =
{computation with env= []; script= "<script>"}) )
>|= fun () -> Lwt.async (handle_computation sockaddr computation)
else Logs_lwt.warn (fun m -> m "Wrong password: %s" computation.pass)
| `STAT ->
stat oc <&> Logs_lwt.debug (fun m -> m "Receive a stat command")
| `STAT -> stat oc <&> Logs_lwt.debug (fun m -> m "Receive a stat command")
| _ -> Logs_lwt.warn (fun m -> m "Receive a unwanted command") )
| Result.Error e ->
Logs_lwt.err (fun m ->
......@@ -77,8 +84,7 @@ let cmd config () =
Serialization_j.node_conf_of_string (CCIO.with_in config CCIO.read_all)
in
let promise, resolver = Lwt.task () in
Logs_lwt.info (fun m ->
m "Node at port %i with pass %s" conf.port conf.pass )
Logs_lwt.info (fun m -> m "Node at port %i with pass %s" conf.port conf.pass)
>>= fun () ->
Lwt_io.flush Lwt_io.stderr
>>= fun () ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment