Unix_syscalls provides an interface to many of the functions in OCaml's standard
Unix module. It uses a deferred in the return type of functions that would block.
The idea is that in an Async program one does not use the standard Unix module, since
in doing so one could accidentally block the whole program.
There are also a number of cosmetic changes (e.g. polymorphic variants) and other improvements (e.g. phantom types on sockets) over the standard Unix module.
module Syscall_result = Core.Unix.Syscall_resultmodule Exit : module type of Core.Unix.Exitmodule Exit_or_signal : module type of Core.Unix.Exit_or_signalmodule Exit_or_signal_or_stop : module type of Core.Unix.Exit_or_signal_or_stopval system : string ‑> Exit_or_signal.t Import.Deferred.tval system_exn : string ‑> unit Import.Deferred.tval getpid : unit ‑> Core.Pid.tval getppid : unit ‑> Core.Pid.t optionval getppid_exn : unit ‑> Core.Pid.tval this_process_became_child_of_init : ?poll_delay:Core.Time.Span.t ‑> unit ‑> unit Import.Deferred.tthis_process_became_child_of_init returns a deferred that becomes determined when
the current process becomes a child of init(8). This is useful to determine if one's
parent has died, because in that case init will becomes one's parent.
See Linux_ext.pr_set_pdeathsig : Signal.t -> unit for related way to get information
about parent death.
val openfile : ?perm:file_perm ‑> string ‑> mode:open_flag list ‑> Fd.t Import.Deferred.tval with_file : ?exclusive:[ `Read | `Write ] ‑> ?perm:file_perm ‑> string ‑> mode:open_flag list ‑> f:(Fd.t ‑> 'a Import.Deferred.t) ‑> 'a Import.Deferred.twith_file file ~mode ~perm ~f ?exclusive opens file, and applies f to the
resulting file descriptor. When the result of f becomes determined, it closes the
descriptor and returns the result of f. If exclusive is supplied, then the file
descriptor is locked before calling f and unlocked after calling f.
module Open_flags : module type of Core.Unix.Open_flagsval fcntl_getfl : Fd.t ‑> Open_flags.t Import.Deferred.tfcntl_getfl and fcntl_setf are deferred wrappers around the corresponding
functions in Core.Unix for accessing the open-file-descriptor table.
val fcntl_setfl : Fd.t ‑> Open_flags.t ‑> unit Import.Deferred.tinclude module type of Fd.CloseThe Close module exists to collect close and its associated types, so they
can be easily reused elsewhere, e.g. Unix_syscalls.
type file_descriptor_handling = | Close_file_descriptor of socket_handling |
| Do_not_close_file_descriptor |
val close : ?file_descriptor_handling:file_descriptor_handling ‑> Fd.t ‑> unit Import.Deferred.tclose t prevents further use of t, and makes shutdown() and close() system
calls on t's underlying file descriptor according to the
file_descriptor_handling argument and whether or not t is a socket, i.e. kind t
= Socket `Active:
| file_descriptor_handling | shutdown() | close() |
|----------------------------------------------+------------+---------|
| Do_not_close_file_descriptor | no | no |
| Close_file_descriptor Shutdown_socket | if socket | yes |
| Close_file_descriptor Do_not_shutdown_socket | no | yes |
The result of close becomes determined once the system calls complete. It is OK
to call close multiple times on the same t; calls subsequent to the initial call
will have no effect, but will return the same deferred as the original call.
val lseek : Fd.t ‑> int64 ‑> mode:[< `Set | `Cur | `End ] ‑> int64 Import.Deferred.tval truncate : string ‑> len:int64 ‑> unit Import.Deferred.tval ftruncate : Fd.t ‑> len:int64 ‑> unit Import.Deferred.tval fsync : Fd.t ‑> unit Import.Deferred.tval fdatasync : Fd.t ‑> unit Import.Deferred.tval sync : unit ‑> unit Import.Deferred.tval lockf : ?len:Core.Int64.t ‑> Fd.t ‑> [ `Read | `Write ] ‑> unit Import.Deferred.tlockf fd read_or_write ?len exclusively locks for reading/writing the section of the
open file fd specified by the current file position and len (see man lockf). It
returns when the lock has been acquired. It raises if fd is closed.
val try_lockf : ?len:Core.Int64.t ‑> Fd.t ‑> [ `Read | `Write ] ‑> booltry_lockf fd read_or_write ?len attempts to exclusively lock for reading/writing the
section of the open file fd specified by the current file position and len (see
man lockf). It returns true if it acquired the lock. It raises if fd is
closed.
val test_lockf : ?len:Core.Int64.t ‑> Fd.t ‑> boollockf_is_locked fd ?len checks the lock on section of the open file fd specified
by the current file position and len (see man lockf). If the section is unlocked or
locked by this process, it returns true, else it returns false. It raises if fd is
closed.
val unlockf : ?len:Core.Int64.t ‑> Fd.t ‑> unitunlockf fd ?len unlocks the section of the open file fd specified by the current
file position and len (see man lockf). It raises if fd is closed.
module File_kind : sig ... endmodule Stats : sig ... endval fstat : Fd.t ‑> Stats.t Import.Deferred.tval stat : string ‑> Stats.t Import.Deferred.tval lstat : string ‑> Stats.t Import.Deferred.tval isatty : Fd.t ‑> bool Import.Deferred.tval unlink : string ‑> unit Import.Deferred.tval remove : string ‑> unit Import.Deferred.tval rename : src:string ‑> dst:string ‑> unit Import.Deferred.tval link : ?force:bool ‑> target:string ‑> link_name:string ‑> unit ‑> unit Import.Deferred.tval chmod : string ‑> perm:file_perm ‑> unit Import.Deferred.tval fchmod : Fd.t ‑> perm:file_perm ‑> unit Import.Deferred.tval chown : string ‑> uid:int ‑> gid:int ‑> unit Import.Deferred.tval fchown : Fd.t ‑> uid:int ‑> gid:int ‑> unit Import.Deferred.tval access : string ‑> [ `Read | `Write | `Exec | `Exists ] list ‑> (unit, exn) Core.Result.t Import.Deferred.tval access_exn : string ‑> [ `Read | `Write | `Exec | `Exists ] list ‑> unit Import.Deferred.tval set_close_on_exec : Fd.t ‑> unitval clear_close_on_exec : Fd.t ‑> unitval mkdir : ?p:unit ‑> ?perm:file_perm ‑> string ‑> unit Import.Deferred.tval rmdir : string ‑> unit Import.Deferred.tval chdir : string ‑> unit Import.Deferred.tval getcwd : unit ‑> string Import.Deferred.tval chroot : string ‑> unit Import.Deferred.tval opendir : string ‑> dir_handle Import.Deferred.tval readdir_opt : dir_handle ‑> string option Import.Deferred.treaddir_opt dir_handle returns the next directory member, or None when there are
no more directory members to return.
val readdir : dir_handle ‑> string Import.Deferred.tval rewinddir : dir_handle ‑> unit Import.Deferred.tval closedir : dir_handle ‑> unit Import.Deferred.tval pipe : Core.Info.t ‑> ([ `Reader of Fd.t ] * [ `Writer of Fd.t ]) Import.Deferred.tThe info supplied to pipe is debugging information that will be included in the
returned Fds.
val mkfifo : ?perm:file_perm ‑> string ‑> unit Import.Deferred.tCreate a named pipe with the given permissions.
val symlink : src:string ‑> dst:string ‑> unit Import.Deferred.tval readlink : string ‑> string Import.Deferred.tval mkstemp : string ‑> (string * Fd.t) Import.Deferred.tmkstemp prefix creates and opens a unique temporary file with prefix,
automatically appending a suffix of six random characters to make the name unique.
Unlike C's mkstemp, prefix should not include six X's at the end.
val mkdtemp : string ‑> string Import.Deferred.tval getgrouplist : string ‑> int ‑> int array Import.Deferred.ttype process_times = Core.Unix.process_times = {}Time functions.
val times : unit ‑> process_timestype tm = Core.Unix.tm = {}val gmtime : float ‑> tmval localtime : float ‑> tmval utimes : string ‑> access:float ‑> modif:float ‑> unit Import.Deferred.tval fork_exec : prog:string ‑> argv:string list ‑> ?use_path:bool ‑> ?env:[ env | `Replace_raw of string list ] ‑> unit ‑> Core.Pid.t Import.Deferred.tfork_exec ~prog ~argv ?path ?env forks and execs prog with argv, and returns the
child pid. If use_path = true (the default) and prog doesn't contain a slash,
then fork_exec searches the PATH environment variable for prog. If env is
supplied, it specifies the environment when prog is executed.
If env contains multiple bindings for the same variable, the last takes precedence.
In the case of `Extend, bindings in env take precedence over the existing
environment. See Unix.exec.
include sig ... endval wait_on_of_sexp : Sexplib.Sexp.t ‑> wait_onval __wait_on_of_sexp__ : Sexplib.Sexp.t ‑> wait_onval sexp_of_wait_on : wait_on ‑> Sexplib.Sexp.tval wait : wait_on ‑> (Core.Pid.t * Exit_or_signal.t) Import.Deferred.tval wait_nohang : wait_on ‑> (Core.Pid.t * Exit_or_signal.t) optionval wait_untraced : wait_on ‑> (Core.Pid.t * Exit_or_signal_or_stop.t) Import.Deferred.tval wait_nohang_untraced : wait_on ‑> (Core.Pid.t * Exit_or_signal_or_stop.t) optionval waitpid : Core.Pid.t ‑> Exit_or_signal.t Import.Deferred.twaitpid pid returns a deferred that becomes determined with the child's exit
status, when the child process with process id pid exits. waitpid_exn is like
waitpid, except the result only becomes determined if the child exits with status
zero; it raises if the child terminates in any other way.
val waitpid_exn : Core.Pid.t ‑> unit Import.Deferred.tmodule Inet_addr : sig ... endmodule Cidr : module type of Core.Unix.Cidrmodule Protocol_family : sig ... endmodule Socket : sig ... endval bind_to_interface_exn : (Fd.t ‑> [ `Any | `Interface_name of string ] ‑> unit) Core.Or_error.tmodule Host : sig ... endinclude sig ... endval socket_domain_of_sexp : Sexplib.Sexp.t ‑> socket_domainval sexp_of_socket_domain : socket_domain ‑> Sexplib.Sexp.tval bin_socket_domain : socket_domain Bin_prot.Type_class.tval bin_read_socket_domain : socket_domain Bin_prot.Read.readerval __bin_read_socket_domain__ : (int ‑> socket_domain) Bin_prot.Read.readerval bin_reader_socket_domain : socket_domain Bin_prot.Type_class.readerval bin_size_socket_domain : socket_domain Bin_prot.Size.sizerval bin_write_socket_domain : socket_domain Bin_prot.Write.writerval bin_writer_socket_domain : socket_domain Bin_prot.Type_class.writerval bin_shape_socket_domain : Bin_prot.Shape.tinclude sig ... endval socket_type_of_sexp : Sexplib.Sexp.t ‑> socket_typeval sexp_of_socket_type : socket_type ‑> Sexplib.Sexp.tval bin_socket_type : socket_type Bin_prot.Type_class.tval bin_read_socket_type : socket_type Bin_prot.Read.readerval __bin_read_socket_type__ : (int ‑> socket_type) Bin_prot.Read.readerval bin_reader_socket_type : socket_type Bin_prot.Type_class.readerval bin_size_socket_type : socket_type Bin_prot.Size.sizerval bin_write_socket_type : socket_type Bin_prot.Write.writerval bin_writer_socket_type : socket_type Bin_prot.Type_class.writerval bin_shape_socket_type : Bin_prot.Shape.tinclude sig ... endval sexp_of_sockaddr : sockaddr ‑> Sexplib.Sexp.tval bin_sockaddr : sockaddr Bin_prot.Type_class.tval bin_read_sockaddr : sockaddr Bin_prot.Read.readerval __bin_read_sockaddr__ : (int ‑> sockaddr) Bin_prot.Read.readerval bin_reader_sockaddr : sockaddr Bin_prot.Type_class.readerval bin_size_sockaddr : sockaddr Bin_prot.Size.sizerval bin_write_sockaddr : sockaddr Bin_prot.Write.writerval bin_writer_sockaddr : sockaddr Bin_prot.Type_class.writerval bin_shape_sockaddr : Bin_prot.Shape.tval sockaddr_of_sexp : Core.Sexp.t ‑> sockaddrsockaddr_blocking_sexp is like sockaddr, with of_sexp that performs DNS lookup
to resolve Inet_addr.t.
include sig ... endval sockaddr_blocking_sexp_of_sexp : Sexplib.Sexp.t ‑> sockaddr_blocking_sexpval sexp_of_sockaddr_blocking_sexp : sockaddr_blocking_sexp ‑> Sexplib.Sexp.tval bin_sockaddr_blocking_sexp : sockaddr_blocking_sexp Bin_prot.Type_class.tval bin_read_sockaddr_blocking_sexp : sockaddr_blocking_sexp Bin_prot.Read.readerval __bin_read_sockaddr_blocking_sexp__ : (int ‑> sockaddr_blocking_sexp) Bin_prot.Read.readerval bin_reader_sockaddr_blocking_sexp : sockaddr_blocking_sexp Bin_prot.Type_class.readerval bin_size_sockaddr_blocking_sexp : sockaddr_blocking_sexp Bin_prot.Size.sizerval bin_write_sockaddr_blocking_sexp : sockaddr_blocking_sexp Bin_prot.Write.writerval bin_writer_sockaddr_blocking_sexp : sockaddr_blocking_sexp Bin_prot.Type_class.writerval bin_shape_sockaddr_blocking_sexp : Bin_prot.Shape.tmodule Addr_info : sig ... endmodule Name_info : sig ... endmodule Error = Core.Unix.Errortype error = Core.Unix.Error.t = val sexp_of_error : Error.t ‑> Core.Sexp.tval error_of_sexp : Core.Sexp.t ‑> Error.texception Unix_error of Error.t * string * stringmodule Terminal_io : sig ... endmodule Ifaddr = Core.Unix.Ifaddrval getifaddrs : unit ‑> Ifaddr.t list Import.Deferred.tgetifaddrs gets the information using the socket-based netlink interface, which
can block, see: https://www.infradead.org/~tgr/libnl/doc/core.html.
val getlogin : unit ‑> string Import.Deferred.tReturn the login name of the user executing the process.
This returns a deferred because the username may need to be looked up in what is essentially a database elsewhere on the network (winbound user, or NIS).
val wordexp : (?flags:[ `No_cmd | `Show_err | `Undef ] list ‑> string ‑> string array Import.Deferred.t) Core.Or_error.t