aboutsummaryrefslogtreecommitdiffstats
path: root/admin/notes/exit-value
blob: 96337e4c8ddd990a9f684574d242bd842b65063b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
ttn 2004-05-09

The exit value of a program returning to the shell on unixoid systems
is typically 0 for success, and non-0 (such as 1) for failure. This is
not always the case on other systems.

From the point of view of the program stdlib.h provides macros
`EXIT_SUCCESS' and `EXIT_FAILURE' that should DTRT.  N.B. The
numerical values of these macros DO NOT need to fulfill the exit value
requirements outlined in the first paragraph!  That is the job of the
`exit' function.  Thus, this kind of construct shows misunderstanding:

   #ifdef WEIRD_OS
      exit (1);
   #else
      exit (0);
   #endif

Values aside from EXIT_SUCCESS and EXIT_FAILURE are tricky, but can be
used to indicate finer gradations of failure.  If this is the only
information available to the caller, clamping such values to
EXIT_FAILURE loses information.  If there are other ways to indicate
the problem to the caller (such as a message to stderr) it may be ok
to clamp.  In all cases, it is the relationship between the program
and its caller that must be examined.

[Insert ZAMM quote here.] <-- I presume this refers to ``Zen and the
Art of Motorcycle Maintenance'' - Reuben Thomas <rrt@sc3d.org>.