Make improvements

- Add rusage to redbean Lua API
- Add more redbean documentation
- Add pledge() to redbean Lua API
- Polyfill OpenBSD pledge() for Linux
- Increase PATH_MAX limit to 1024 characters
- Untrack sibling processes after fork() on Windows
This commit is contained in:
Justine Tunney 2022-04-28 09:42:36 -07:00
parent 9a6bd304a5
commit 47b3274665
212 changed files with 2251 additions and 834 deletions

View file

@ -40,7 +40,7 @@ int posix_spawn(int *pid, const char *path,
unsigned mode;
sigset_t allsigs;
struct sigaction dfl;
char *p, *q, opath[PATH_MAX + 1];
char *p, *q, opath[PATH_MAX];
int s, fd, newfd, oflag, tempfd;
if (!(*pid = vfork())) {
if (attrp) {
@ -77,7 +77,7 @@ int posix_spawn(int *pid, const char *path,
if (sscanf(p + 5, "%d,", &fd) != 1) _Exit(127);
p = strchr(p, ',') + 1;
q = strchr(p, '*');
if (!q || q - p > PATH_MAX) _Exit(127);
if (!q || q - p >= PATH_MAX) _Exit(127);
strncpy(opath, p, q - p);
opath[q - p] = '\0';
if (sscanf(q + 1, "%o,%o)", &oflag, &mode) != 2) _Exit(127);

View file

@ -31,7 +31,7 @@ int posix_spawnp(int *pid, const char *path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *attrp, char *const argv[],
char *const envp[]) {
char pathbuf[PATH_MAX + 1];
char pathbuf[PATH_MAX];
if (!(path = commandv(path, pathbuf, sizeof(pathbuf)))) return errno;
return posix_spawn(pid, path, file_actions, attrp, argv, envp);
}

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/macros.internal.h"
#include "libc/paths.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -29,14 +30,16 @@
*/
int systemexec(const char *cmdline) {
size_t n, m;
char *a, *b, *argv[4], comspec[PATH_MAX + 1];
char *a, *b, *argv[4], comspec[PATH_MAX];
if (!IsWindows()) {
argv[0] = _PATH_BSHELL;
argv[1] = "-c";
} else {
b = "cmd.exe";
a = kNtSystemDirectory;
if ((n = strlen(a)) + (m = strlen(b)) > PATH_MAX) return enametoolong();
if ((n = strlen(a)) + (m = strlen(b)) >= ARRAYLEN(comspec)) {
return enametoolong();
}
memcpy(mempcpy(comspec, a, n), b, m + 1);
argv[0] = comspec;
argv[1] = "/C";

View file

@ -32,10 +32,10 @@
*/
FILE *tmpfile(void) {
int fd;
char *tmp, *sep, tpl[PATH_MAX + 1];
char *tmp, *sep, tpl[PATH_MAX];
tmp = firstnonnull(getenv("TMPDIR"), kTmpPath);
sep = !isempty(tmp) && !endswith(tmp, "/") ? "/" : "";
if ((snprintf)(tpl, PATH_MAX + 1, "%s%stmp.%s.XXXXXX", tmp, sep,
if ((snprintf)(tpl, PATH_MAX, "%s%stmp.%s.XXXXXX", tmp, sep,
program_invocation_short_name) <= PATH_MAX) {
if ((fd = mkostemps(tpl, 0, 0)) != -1) {
return fdopen(fd, "w+");