scroll

scrollbackbuffer program for st
git clone git://git.suckless.org/scroll
Log | Files | Refs | README

commit b11c164c60aedf10026bfc1a168ce79ba005fe43
parent 4cef6f04e98d99c94ffe56502054adee77018d1b
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Thu,  9 Apr 2020 20:29:27 +0200

set resource limit for scroll back buffer size

Diffstat:
Mscroll.c | 39++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -21,6 +21,7 @@ #include <sys/ioctl.h> #include <sys/wait.h> #include <sys/queue.h> +#include <sys/resource.h> #include <assert.h> #include <errno.h> @@ -333,9 +334,37 @@ jumpdown(char *buf, size_t size) scrolldown(buf, size, ws.ws_row); } +void +usage(void) { + die("usage: scroll [-M] [-m mem] <program>"); +} + int main(int argc, char *argv[]) { + int ch; + struct rlimit rlimit; + + if (getrlimit(RLIMIT_DATA, &rlimit) == -1) + die("getrlimit"); + + while ((ch = getopt(argc, argv, "Mm:")) != -1) { + switch (ch) { + case 'M': + rlimit.rlim_cur = rlimit.rlim_max; + break; + case 'm': + rlimit.rlim_cur = strtoull(optarg, NULL, 0); + if (errno != 0) + die("strtoull: %s", optarg); + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + TAILQ_INIT(&head); if (isatty(STDIN_FILENO) == 0) @@ -343,8 +372,8 @@ main(int argc, char *argv[]) if (isatty(STDOUT_FILENO) == 0) die("stdout it not a tty"); - if (argc <= 1) - die("usage: scroll <program>"); + if (argc < 1) + usage(); /* save terminal settings for resetting after exit */ if (tcgetattr(STDIN_FILENO, &dfl) == -1) @@ -360,11 +389,15 @@ main(int argc, char *argv[]) if (child == -1) die("forkpty:"); if (child == 0) { /* child */ - execvp(argv[1], argv + 1); + execvp(argv[0], argv); perror("execvp"); _exit(127); } + /* set maximum memory size for scrollback buffer */ + if (setrlimit(RLIMIT_DATA, &rlimit) == -1) + die("setrlimit:"); + #ifdef __OpenBSD__ if (pledge("stdio tty proc", NULL) == -1) die("pledge:");