NAME
kjb_system_2 - A helper for kjb_system(), wrapper for system()
SYNOPSIS
#include "l/l_sys_lib.h"
Example compile flags (system dependent):
-DLINUX_X86_64 -DLINUX_X86_64_OPTERON -DGNU_COMPILER
-I/home/kobus/include
-L/home/kobus/misc/load/linux_x86_64_opteron -L/usr/lib/x86_64-linux-gnu
-lKJB -lfftw3 -lgsl -lgslcblas -ljpeg -lSVM -lstdc++ -lpthread -lSLATEC -lg2c -lacml -lacml_mv -lblas -lg2c -lncursesw
int kjb_system_2
(
const char *command,
int *prog_rc_ptr
);
DESCRIPTION
This function is different than kjb_system() in that 1) it dodges the process
that sits in the background to handle incomming system call requests; and 2)
it provides a simple return code for the command executed (if argument
prog_rc_ptr is not NULL). It is different than system() in that output to
stderr is collected as error messages (until the space for them is used up,
in which case they should be dropped --- we should check this still work!).
If argument prog_rc_ptr is not NULL, then *prog_rc_ptr will be set to the
shell return codes by the following table (not everything has been checked),
and, if none of these apply, then the return code of what running program
chooses to return, as you would expect.
| 1 Catchall for general errors
2 Misuse of shell builtins
126 Command invoked cannot execute
127 "command not found"
128 Invalid argument to exit
128+n Fatal error signal "n"
255 Exit status out of range
This function has historical baggage due to trying to do what seems hard to
do easily which is to separate out the notions of 1) the shell failing to get
the command(s) running with the various IO redirections; and 2) the
subsequently well formed command reports an error return code. This is not
implemented due to difficulties --- it seems that doing so in the general
case would require parsing composite commands into smaller commands, checking
that they can be executed, and checking the IO redirects. Currently, the
cases we cannot handle well are composite cases that we do not want to do
this analysis, and so we adopt the shell's version of the situation, which
means that something like:
ls < NON_EXISTANT
will have an error code of "1" which may or may not be what we want (but it
is consistant with the shell). However,
NON_EXISTANT
will get return code "127", and
NON_PERMITTED
will get return code "126".
DISCLAIMER
This software is not adequatedly tested. It is recomended that
results are checked independantly where appropriate.
AUTHOR
Kobus Barnard
DOCUMENTER
Kobus Barnard
SEE ALSO
is_interactive
,
get_user_id
,
get_group
,
kjb_get_env
,
create_system_command_process
,
kjb_system
,
kjb_exec
,
kjb_waitpid
,
kjb_waitpid2
,
check_child
,
check_child2
,
reset_cleanup_for_fork
,
add_cleanup_function
,
kjb_cleanup
,
kjb_cleanup_for_abort
,
kjb_optional_abort
,
kjb_abort
,
kjb_exit
,
kjb_exit_2
,
terminate_child_process
,
process_is_alive
,
get_idle_time
,
get_temp_file_name
,
kjb_fork