Re: How to tell when execv has succeeded



On Jan 9, 3:27 am, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
On Jan 8, 5:37 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:

An operation either succeeds or fails. It cannot half-succeed and half-
fail.
He was wondering if it could be implemented as follows:

1. Close all close-on-exec descriptors
2. Load new program into address space
3. Start new program running
If step 2 fails, it returns with an error code, but the descriptors
would still have been closed in step 1, so the parent process would see
EOF from the pipe.  The spec says "upon execution", not "upon successful
execution", so this seems like a possible interpretation.

If the 'exec' function is able to make any detectable changes, then it
has not failed and cannot return an error code.

What should it do then? Leave the calling process in uninterruptable
state?

This is the same
reason a 'write' cannot return -1 if it successfully wrote any data.
No function is permitted to leave you in an ambiguous state about what
detectable operations were performed when it returns a failure.

Although this makes perfect sense, where is that guaranteed?

[]

The standard does not specifically have to say that functions may fail
in normal, expected ways without have side-effects one cannot code
around. A typical 'exec' failure is no different than opening a non-
existent file -- the system must be left in a consistent state so
further forward progress can be made.

The are two sides:
* The kernel must be left in a consistent state.
* The user process may be left in an inconsistent state (as
demonstrated by the notorious close() documented behaviour), however,
_exit() must still work as expected, so that the process can terminate
with an observable error and be recycled by the kernel.

--
Max
.



Relevant Pages

  • Re: New DTrace source snapshot
    ... A number of things were missing from the dtrace kernel ... This is a snapshot of current which contains lock order ... will fail to build when hosted on RELENG_6. ... *** Error code 1 ...
    (freebsd-current)
  • Re: ../../../dev/ath/if_ath.c:3414: error: const struct ath_rx_status has no member named rs_flags
    ... The open-source Atheros HAL has been merged from HEAD ... The kernel compile-time option AH_SUPPORT_AR5416 has been ... *** Error code 1 ... passing well and than "make" state fail, ...
    (freebsd-questions)
  • Re: make installkernel NDIS disaster
    ... installing a kernel and for some reason I got some NDIS errors. ... but of a make installkernel KERNCONF=KAYVE_KERN ... I am running this disk now so I can mount the othere data. ... *** Error code 1 ...
    (freebsd-questions)
  • freebsd4.7 compile kernel error
    ... *** Error code 1 ... the kernel config file: ... pseudo-device splash ... # Enable this and PCVT_FREEBSD for pcvt vt220 compatible console driver ...
    (comp.unix.bsd.freebsd.misc)
  • Unassociated shell command when building kernel
    ... kernel build, I get what appear to be make errors with the error ... echo ln gzip gunzip>>rescue.conf ... *** Error code 1 ...
    (freebsd-questions)