incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Black <>
Subject Re: [patch] exec utility child process limits (unix)
Date Mon, 28 Aug 2006 22:15:01 GMT

Attached is take two on the patch.

Probably the major change between the previous version and this one is 
that most things that had been conditionally defined are now 
unconditionally defined.  If a particular limit can't be set on a given 
platform, a warning is issued during option parsing.  I'm not certain 
the warn logic is quite what would be desired, as multiple warnings for 
a given option could be issued if said unsupported option is specified 
multiple times.   Similarly, no warning is provided if the platform 
lacks support for the setrlimit syscall, explaining that all limits will 

Another failing that I am realizing is that cmdopt.cpp may (will?) fail 
to compile if struct rlimit includes more fields than rlim_cur and 
rlim_max.  Similarly, things may be incorrectly initialized if rlim_max 
is before rlim_cur in the structure.

I've changed things enough that I think a replacement changelog is needed.

--Andrew Black

     * cmdopt.h [_WIN32 || _WIN64 || !_XOPEN_UNIX]: Define placeholder 
struct rlimit.
       Define struct limit_set, declare child_limits.
     * cmdopt.c [!_WIN32 && !_WIN64 && _XOPEN_UNIX]: Include sys/resource.h
defined, initialize child_limits.
       usage_text[]: Document --ulimit switch.
       parse_limit_opts: Define helper function for parsing --rlimit 
option (borrowed in part from _rw_setopt_ulimit in tests/src/driver.cpp).
       eval_options(): Define opt_ulimit character string, use with 
parse_limit_opts to handle --ulimit command line switch.
     * exec.cpp [!_WIN32 && !_WIN64 && _XOPEN_UNIX]: Include sys/resource.h
       LIMIT: Define helper macro for...
       limit_process(): New helper function to set resource limits, 
based on the values in child_limits (borrowed in part from 
_rw_setopt_ulimit in tests/src/driver.cpp).
       exec_file(): Call above prior to execv.

Martin Sebor wrote:
> Andrew Black wrote:
>> Greetings all.
>> Attached is a patch that enables the exec utility to place limits on 
>> its child process, using the setrlimit() command.  These changes are 
>> based on the _rw_setopt_ulimit function in tests/src/driver.cpp.  It 
>> should be noted that the sys/resource.h header is an XSI extension to 
>> the POSIX standard, so it may not be possible to rely on this header 
>> being present, though an assumption to this effect is made in this 
>> patch and in tests/src/driver.cpp.
> I think either _XOPEN_UNIX or _XOPEN_VERSION is the macro to check
> (after #including <unistd.h>) in order to determine XSI conformance.
> I.e., this would be the magic chant:
>   #include <unistd.h>
>   #if defined (_XOPEN_UNIX)
>       /* XSI extensions supported */
>   #  include <sys/resource.h>
>   #endif   /* _XOPEN_UNIX */
> As for the patch, I'm not sure that recognizing command line options
> only when they are implemented or supported is the best approach. The
> utility contains the (possibly complex) logic to determine whether it
> is or isn't possible to provide the feature so avoiding failures due
> to it being invoked with the unimplemented option will basically mean
> duplicating the same logic in the caller.
> I think handling the unavailability of the options the same was as
> the failure to set the limit (i.e., warning and proceeding) would
> be more robust. After all, on platforms where there is no way to set
> the resource limit we will still want to be able to run our tests.
> Martin

View raw message