diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 140ce1fc9..b2508572c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -34,7 +34,7 @@ Interactive improvements - The default command-not-found handler now reports a special error if there is a non-executable file (:issue:`8804`) - ``less`` and other interactive commands would occasionally be stopped when run in a pipeline with fish functions; this has been fixed (:issue:`8699`). - Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`). -- ``ulimit`` learned a number of new options for the resource limits available on Linux (:issue:`8786`). +- ``ulimit`` learned a number of new options for the resource limits available on Linux, FreeBSD and NetBSD (:issue:`8786`). New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc_src/cmds/ulimit.rst b/doc_src/cmds/ulimit.rst index 9b823bc57..fec8e55a3 100644 --- a/doc_src/cmds/ulimit.rst +++ b/doc_src/cmds/ulimit.rst @@ -18,6 +18,9 @@ Description Use one of the following switches to specify which resource limit to set or report: +**-b** or **--socket-buffers** + The maximum size of socket buffers. + **-c** or **--core-size** The maximum size of core files created. By setting this limit to zero, core dumps can be disabled. @@ -57,13 +60,25 @@ Use one of the following switches to specify which resource limit to set or repo **-u** or **--process-count** The maximum number of processes available to the current user. +**-w** or **--swap-size** + The maximum swap space available to the current user. + **-v** or **--virtual-memory-size** The maximum amount of virtual memory available to the shell. **-y** or **--realtime-maxtime** The maximum contiguous realtime CPU time in microseconds. -Note that not all these limits are available in all operating systems. +**-K** or **--kernel-queues** + The maximum number of kqueues (kernel queues) for the current user. + +**-P** or **--ptys** + The maximum number of pseudo-terminals for the current user. + +**-T** or **--threads** + The maximum number of simultaneous threads for the current user. + +Note that not all these limits are available in all operating systems; consult the documentation for ``setrlimit`` in your operating system. The value of limit can be a number in the unit specified for the resource or one of the special values ``hard``, ``soft``, or ``unlimited``, which stand for the current hard limit, the current soft limit, and no limit, respectively. diff --git a/share/completions/ulimit.fish b/share/completions/ulimit.fish index 25d8b44e7..f510e5a3d 100644 --- a/share/completions/ulimit.fish +++ b/share/completions/ulimit.fish @@ -3,6 +3,7 @@ complete -c ulimit -s S -l soft -d "Set or get soft limit" complete -c ulimit -s H -l hard -d "Set or get hard limit" complete -c ulimit -s a -l all -d "Get all current limits" +complete -c ulimit -s b -l socket-buffers -d "Maximum size of socket buffers" complete -c ulimit -s c -l core-size -d "Maximum size of core files created" complete -c ulimit -s d -l data-size -d "Maximum size of a process's data segment" complete -c ulimit -s e -l nice -d "Control of maximum nice priority" @@ -17,7 +18,11 @@ complete -c ulimit -s s -l stack-size -d "Maximum stack size" complete -c ulimit -s t -l cpu-time -d "Maximum amount of cpu time in seconds" complete -c ulimit -s u -l process-count -d "Maximum number of processes available to a single user" complete -c ulimit -s v -l virtual-memory-size -d "Maximum amount of virtual memory available to the shell" +complete -c ulimit -s w -l swap-size -d "Maximum swap space" complete -c ulimit -s y -l realtime-maxtime -d "Maximum contiguous realtime CPU time" +complete -c ulimit -s K -l kernel-queues -d "Maximum number of kqueues" +complete -c ulimit -s P -l ptys -d "Maximum number of pseudo-terminals" +complete -c ulimit -s T -l threads -d "Maximum number of simultaneous threads" complete -c ulimit -s h -l help -d "Display help and exit" diff --git a/src/builtins/ulimit.cpp b/src/builtins/ulimit.cpp index 457d9ea8b..0c7f1af85 100644 --- a/src/builtins/ulimit.cpp +++ b/src/builtins/ulimit.cpp @@ -26,6 +26,9 @@ struct resource_t { /// Array of resource_t structs, describing all known resource types. static const struct resource_t resource_arr[] = { +#ifdef RLIMIT_SBSIZE + {RLIMIT_SBSIZE, L"Maximum size of socket buffers", L'b', 1024}, +#endif {RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024}, {RLIMIT_DATA, L"Maximum size of a process’s data segment", L'd', 1024}, #ifdef RLIMIT_NICE @@ -56,8 +59,20 @@ static const struct resource_t resource_arr[] = { #ifdef RLIMIT_AS {RLIMIT_AS, L"Maximum amount of virtual memory available to each process", L'v', 1024}, #endif +#ifdef RLIMIT_SWAP + {RLIMIT_SWAP, L"Maximum swap space", L'w', 1024}, +#endif #ifdef RLIMIT_RTTIME {RLIMIT_RTTIME, L"Maximum contiguous realtime CPU time", L'y', 1}, +#endif +#ifdef RLIMIT_KQUEUES + {RLIMIT_KQUEUES, L"Maximum number of kqueues", L'K', 1}, +#endif +#ifdef RLIMIT_NPTS + {RLIMIT_NPTS, L"Maximum number of pseudo-terminals", L'P', 1}, +#endif +#ifdef RLIMIT_NTHR + {RLIMIT_NTHR, L"Maximum number of simultaneous threads", L'T', 1}, #endif {0, nullptr, 0, 0}}; @@ -173,11 +188,12 @@ maybe_t builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar bool soft = false; int what = RLIMIT_FSIZE; - static const wchar_t *const short_options = L":HSacdefilmnqrstuvyh"; + static const wchar_t *const short_options = L":HSabcdefilmnqrstuvwyKPTh"; static const struct woption long_options[] = { {L"all", no_argument, nullptr, 'a'}, {L"hard", no_argument, nullptr, 'H'}, {L"soft", no_argument, nullptr, 'S'}, + {L"socket-buffers", no_argument, nullptr, 'b'}, {L"core-size", no_argument, nullptr, 'c'}, {L"data-size", no_argument, nullptr, 'd'}, {L"nice", no_argument, nullptr, 'e'}, @@ -192,7 +208,11 @@ maybe_t builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar {L"cpu-time", no_argument, nullptr, 't'}, {L"process-count", no_argument, nullptr, 'u'}, {L"virtual-memory-size", no_argument, nullptr, 'v'}, + {L"swap-size", no_argument, nullptr, 'w'}, {L"realtime-maxtime", no_argument, nullptr, 'y'}, + {L"kernel-queues", no_argument, nullptr, 'K'}, + {L"ptys", no_argument, nullptr, 'P'}, + {L"threads", no_argument, nullptr, 'T'}, {L"help", no_argument, nullptr, 'h'}, {nullptr, 0, nullptr, 0}}; @@ -212,6 +232,12 @@ maybe_t builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar soft = true; break; } +#ifdef RLIMIT_SBSIZE + case 'b': { + what = RLIMIT_SBSIZE; + break; + } +#endif case 'c': { what = RLIMIT_CORE; break; @@ -284,11 +310,35 @@ maybe_t builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar break; } #endif +#ifdef RLIMIT_SWAP + case 'w': { + what = RLIMIT_SWAP; + break; + } +#endif #ifdef RLIMIT_RTTIME case 'y': { what = RLIMIT_RTTIME; break; } +#endif +#ifdef RLIMIT_KQUEUES + case 'K': { + what = RLIMIT_KQUEUES; + break; + } +#endif +#ifdef RLIMIT_NPTS + case 'P': { + what = RLIMIT_NPTS; + break; + } +#endif +#ifdef RLIMIT_NTHR + case 'T': { + what = RLIMIT_NTHR; + break; + } #endif case 'h': { builtin_print_help(parser, streams, cmd);