mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
6e6fc38935
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
75 lines
2.9 KiB
C
75 lines
2.9 KiB
C
#if 0
|
|
/*─────────────────────────────────────────────────────────────────╗
|
|
│ To the extent possible under law, Justine Tunney has waived │
|
|
│ all copyright and related or neighboring rights to this file, │
|
|
│ as it is written in the following disclaimers: │
|
|
│ • http://unlicense.org/ │
|
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
|
╚─────────────────────────────────────────────────────────────────*/
|
|
#endif
|
|
#include "libc/calls/struct/rlimit.h"
|
|
#include "libc/calls/calls.h"
|
|
#include "libc/errno.h"
|
|
#include "libc/intrin/describeflags.internal.h"
|
|
#include "libc/intrin/strace.internal.h"
|
|
#include "libc/log/color.internal.h"
|
|
#include "libc/macros.internal.h"
|
|
#include "libc/runtime/runtime.h"
|
|
#include "libc/stdio/stdio.h"
|
|
#include "libc/str/str.h"
|
|
#include "libc/sysv/consts/rlim.h"
|
|
#include "libc/sysv/consts/rlimit.h"
|
|
|
|
/**
|
|
* @fileoverview tool for printing and changing system resource limits
|
|
*
|
|
* This is what you do if you want to not accidentally bomb your system
|
|
* with runaway code. If you haven't accidentally bombed your UNIX
|
|
* system before then you're not pushing it hard enough.
|
|
*/
|
|
|
|
static void SetLimit(int resource, uint64_t soft, uint64_t hard) {
|
|
struct rlimit old;
|
|
struct rlimit lim = {soft, hard};
|
|
if (resource == 127)
|
|
return;
|
|
if (setrlimit(resource, &lim) == -1) {
|
|
if (!getrlimit(resource, &old)) {
|
|
lim.rlim_max = MIN(hard, old.rlim_max);
|
|
lim.rlim_cur = MIN(soft, old.rlim_max);
|
|
if (!setrlimit(resource, &lim)) {
|
|
fprintf(stderr, "%sNOTE: SETRLIMIT(%s) DOWNGRADED TO {%,ld, %,ld}\n",
|
|
DescribeRlimitName(resource), lim.rlim_cur, lim.rlim_max);
|
|
return;
|
|
}
|
|
}
|
|
fprintf(stderr, "ERROR: SETRLIMIT(%s, %,ld, %,ld) FAILED %m%n",
|
|
DescribeRlimitName(resource), soft, hard);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
int i, rc;
|
|
char rlnbuf[20];
|
|
struct rlimit rlim;
|
|
|
|
// // example of how you might change the limits
|
|
// SetLimit(RLIMIT_CPU, 3, 33);
|
|
// SetLimit(RLIMIT_NPROC, 4, 128);
|
|
// SetLimit(RLIMIT_NOFILE, 32, 128);
|
|
// SetLimit(RLIMIT_SIGPENDING, 16, 1024);
|
|
// SetLimit(RLIMIT_AS, 8 * 1024 * 1024, 1l * 1024 * 1024 * 1024);
|
|
// SetLimit(RLIMIT_RSS, 8 * 1024 * 1024, 1l * 1024 * 1024 * 1024);
|
|
// SetLimit(RLIMIT_DATA, 8 * 1024 * 1024, 1l * 1024 * 1024 * 1024);
|
|
// SetLimit(RLIMIT_FSIZE, 8 * 1000 * 1000, 1l * 1000 * 1000 * 1000);
|
|
|
|
for (i = 0; i < RLIM_NLIMITS; ++i) {
|
|
rc = getrlimit(i, &rlim);
|
|
printf("SETRLIMIT(%-20s, %,16ld, %,16ld) → %d %s\n",
|
|
(DescribeRlimitName)(rlnbuf, i), rlim.rlim_cur, rlim.rlim_max, rc,
|
|
!rc ? "" : strerror(errno));
|
|
}
|
|
|
|
return 0;
|
|
}
|