And take 3, log below (slightly modified from last time).
One additional change that I made as a result of the feedback was to
only implement process limits (for unix systems) on platforms that
define _XOPEN_UNIX. This is needed to prevent compile failures in the
corner case where a platform provides a setrlimit function, but doesn't
define _XOPEN_UNIX.
A problem that will need to be considered is what to do if a platform
includes non-standard elements in their struct rlimit. At this time, a
compile failure will result, but I'm not certain what can be done about it.
--Andrew Black
Log:
* cmdopt.h [!_WIN32 && !_WIN64]: Include unistd.h
[_XOPEN_UNIX]: Include sys/resource.h
rw_rlim_t, struct rw_rlimit [!_XOPEN_UNIX]: Define placeholder
type/struct for rlim_t and struct rlimit respectively.
Define rw_rlimit, struct limit_set, declare child_limits.
* cmdopt.cpp [!_WIN32 && !_WIN64 && _XOPEN_UNIX]: Include
sys/resource.h
Define RLIM_INFINITY, RLIM_SAVED_CUR and RLIM_SAVED_MAX if not
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 [!_WIN32 && !_WIN64 && _XOPEN_UNIX]: Define helper macro for...
limit_process() [!_WIN32 && !_WIN64 && _XOPEN_UNIX]: 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() [!_WIN32 && !_WIN64 && _XOPEN_UNIX]: Call above prior
to execv.
Martin Sebor wrote:
> Andrew Black wrote:
>> Ok.
>>
>> Attached is take two on the patch.
>
> Sorry I've been taking so long to look at this...
>
> [...]
>> Index: cmdopt.h
>> ===================================================================
>> --- cmdopt.h (revision 437752)
>> +++ cmdopt.h (working copy)
>> @@ -39,6 +39,27 @@
>> extern const char suffix_sep; /**< File suffix seperator. */
>> extern const size_t exe_suffix_len; /**< Length of executable suffix. */
>>
>> +#if defined (_WIN32) || defined (_WIN64) || !defined (_XOPEN_UNIX)
>
> You need to #include <unistd.h> before testing _XOPEN_UNIX.
> (The patch fails to compile on Solaris because of this.) I'm also
> not sure it's safe to assume struct rlimit is not defined when the
> macro is undefined.
>
> I think a better way to handle this might be to introduce rw_rlimit
> and either make it a typedef for struct rlimit when the latter can
> safely be assumed to exist (i.e., when _XOPEN_UNIX is #defined in
> <unistd.h>), or define it identically to struct rlimit otherwise.
>
> Also, I'm growing increasingly uneasy about the growing number of
> global variables used throughout the program. I realize that some
> may be unavoidable but I would welcome a patch to reduce their
> number and consolidate the rest according their function (e.g.,
> all those used to invoke the child process, including the new
> child_limits).
>
> Martin
|