rb_f_exec

Function rb_f_exec 

Source
pub unsafe extern "C" fn rb_f_exec(
    argc: c_int,
    argv: *const VALUE,
) -> !
Expand description

Replaces the current process by running the given external command. This is the implementation of Kernel#exec.

@param[in] argc Number of objects in argv. @param[in] argv Command and its options to execute. @exception rb_eTypeError Invalid options e.g. non-String argv. @exception rb_eArgError Invalid options e.g. redirection cycle. @exception rb_eNotImpError Not implemented e.g. no setuid(2). @exception rb_eRuntimeError Process::UID.switch in operation. @exception rb_eSystemCallError execve(2) failed. @warning This function doesn’t return. @warning On failure it raises. On success the process is replaced.

@internal

@shyouhei have to say that the rdoc for Kernel#exec is fairly incomplete. AFAIK this function ultimately takes the following signature:

type boolx  = bool | nil                # !=  `boolish`

type rlim_t = Integer                   # rlim_cur
            | [ Integer, Integer ]      # rlim_cur, rlim_max

type uid_t  = String                    # e.g. "root"
            | Integer                   # e.g. 0

type gid_t  = String                    # e.g. "wheel"
            | Integer                   # e.g. 0

type fmode  = String                    # e.g. "rb"
            | Integer                   # e.g. O_RDONLY | O_BINARY

type mode_t = Integer                   # e.g. 0644

type pgrp   = true                      # Creates a dedicated pgroup
            | 0                         # ditto
            | nil                       # Uses the current one
            | Integer                   # Uses this specific pgroup

type fd     = :in                       # STDIN
            | :out                      # STDOUT
            | :err                      # STDERR
            | IO                        # This specific IO
            | Integer                   # A file descriptor of this #

type src    = fd | [ fd ]
type dst    = :close                    # Intuitive
            | fd                        # Intuitive
            | String                    # Open a file at this path
            | [ String ]                # ... using O_RDONLY
            | [ String, fmode ]         # ... using this mode
            | [ String, fmode, mode_t ] # ... with a permission
            | [ :child, fd ]            # fd of child side

type redir  = Hash[ src, dst ]

# ----

# Key-value pair of environment variables
type envp  = Hash[ String, String ]

# Actual name (and the name passed to the subprocess if any)
type arg0  = String | [ String, String ]

# Arbitrary string parameters
type argv  = String

# Exec options:
type argh  = redir | {
  chdir:             String, # Working directory
  close_others:      boolx,  # O_CLOEXEC like behaviour
  gid:               gid_t,  # setegid(2)
  pgrooup:           pgrp,   # setpgrp(2)
  rlimit_as:         rlim_t, # setrlimit(2)
  rlimit_core:       rlim_t, # ditto
  rlimit_cpu:        rlim_t, # ditto
  rlimit_data:       rlim_t, # ditto
  rlimit_fsize:      rlim_t, # ditto
  rlimit_memlock:    rlim_t, # ditto
  rlimit_msgqueue:   rlim_t, # ditto
  rlimit_nice:       rlim_t, # ditto
  rlimit_nofile:     rlim_t, # ditto
  rlimit_nproc:      rlim_t, # ditto
  rlimit_rss:        rlim_t, # ditto
  rlimit_rtprio:     rlim_t, # ditto
  rlimit_rttime:     rlim_t, # ditto
  rlimit_sbsize:     rlim_t, # ditto
  rlimit_sigpending: rlim_t, # ditto
  rlimit_stack:      rlim_t, # ditto
  uid:               uid_t,  # seteuid(2)
  umask:             mode_t, # umask(2)
  unsetenv_others:   boolx   # Unset everything except the passed envp
}

# ====

class Kernel
  def self?.exec
    : (          arg0 cmd, *argv args           ) -> void
    | (          arg0 cmd, *argv args, argh opts) -> void
    | (envp env, arg0 cmd, *argv args           ) -> void
    | (envp env, arg0 cmd, *argv args, argh opts) -> void
end

Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.2.3