scroll

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

commit e37cb1032aa76478be9955cecece16b37c954cfe
parent f1e7a78ba26a8c12f92afe9434f1e8744e08e378
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Sun, 12 Apr 2020 00:01:08 +0200

take default shell if no program argument is given

Diffstat:
Mscroll.1 | 2+-
Mscroll.c | 16+++++++++++-----
2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/scroll.1 b/scroll.1 @@ -23,7 +23,7 @@ .Nm .Op Fl M .Op Fl m Ar size -.Ar program +.Op program Op arg ... .Sh DESCRIPTION The .Nm diff --git a/scroll.c b/scroll.c @@ -27,6 +27,7 @@ #include <errno.h> #include <fcntl.h> #include <poll.h> +#include <pwd.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> @@ -369,7 +370,7 @@ jumpdown(char *buf, size_t size) void usage(void) { - die("usage: scroll [-M] [-m mem] <program>"); + die("usage: scroll [-M] [-m mem] [program]"); } int @@ -405,9 +406,6 @@ main(int argc, char *argv[]) if (isatty(STDOUT_FILENO) == 0) die("stdout it not a tty"); - if (argc < 1) - usage(); - /* save terminal settings for resetting after exit */ if (tcgetattr(STDIN_FILENO, &dfl) == -1) die("tcgetattr:"); @@ -422,7 +420,15 @@ main(int argc, char *argv[]) if (child == -1) die("forkpty:"); if (child == 0) { /* child */ - execvp(argv[0], argv); + if (argc >= 1) { + execvp(argv[0], argv); + } else { + struct passwd *passwd = getpwuid(getuid()); + if (passwd == NULL) + die("getpwid:"); + execlp(passwd->pw_shell, passwd->pw_shell, NULL); + } + perror("execvp"); _exit(127); }