/* status.c: functions for printing fancy status messages in rc */
/* status == the wait() value of the last command in the pipeline, or the last command */
static int statuses
[512];
static int pipelength
= 1;
Test to see if rc's status is true. According to td, status is true
if and only if every pipe-member has an exit status of zero.
for (i
= 0; i
< pipelength
; i
++)
Return the status as an integer. A status which has low-bits set is
a signal number, whereas a status with high bits set is a value set
from exit(). The presence of a signal just sets status to 1. Also,
a pipeline with nonzero exit statuses in it just sets status to 1.
return (s
&0xff) ? 1 : (s
>> 8) & 0xff;
extern void set(bool code
) {
setstatus(-1, (!code
) << 8); /* exit status 1 == 0x100 */
/* take a pipeline and store the exit statuses. Check to see whether any of the children dumped core */
extern void setpipestatus(int stats
[], int num
) {
for (i
= 0; i
< (pipelength
= num
); i
++) {
/* set a simple status, as opposed to a pipeline */
extern void setstatus(int pid
, int i
) {
/* print a message if termination was with a signal, and if the child dumped core. exit on error if -e is set */
extern void statprint(int pid
, int i
) {
char *msg
= ((i
& 0x7f) < NUMOFSIGNALS
? signals
[i
& 0x7f].msg
: "");
fprint(2, "core dumped\n");
fprint(2, "%s--core dumped\n", msg
);
if (i
!= 0 && dashee
&& !cond
)
/* prepare a list to be passed back. Used whenever $status is dereferenced */
extern List
*sgetstatus() {
for (r
= NULL
, i
= 0; i
< pipelength
; i
++) {
if ((t
= s
& 0x7f) != 0) {
const char *core
= (s
& 0x80) ? "+core" : "";
if (t
< NUMOFSIGNALS
&& *signals
[t
].name
!= '\0')
r
->w
= nprint("%s%s", signals
[t
].name
, core
);
r
->w
= nprint("-%d%s", t
, core
); /* unknown signals are negated */
r
->w
= nprint("%d", (s
>> 8) & 0xff);
extern void ssetstatus(char **av
) {
for (l
= 0; av
[l
] != NULL
; l
++)
; /* count up array length */
for (i
= 0; av
[i
] != NULL
; i
++) {
statuses
[l
- i
] = j
<< 8;
for (k
= 0; k
< NUMOFSIGNALS
; k
++) {
if (streq(signals
[k
].name
, av
[i
])) {
size_t len
= strlen(signals
[k
].name
);
if (strncmp(signals
[k
].name
, av
[i
], len
) == 0 && streq(av
[i
] + len
, "+core")) {
statuses
[l
- i
] = k
+ 0x80;
fprint(2, "bad status\n");