diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | config.def.h | 11 | ||||
-rw-r--r-- | nullshell.c | 26 |
4 files changed, 24 insertions, 18 deletions
@@ -15,7 +15,7 @@ LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie # this is just a fallback in case you do not use git but downloaded # a release tarball... -VERSION := 0.0.7 +VERSION := 0.0.8 all: nullshell README.html @@ -68,3 +68,6 @@ URL: Mirror: [eworm.de](https://git.eworm.de/cgit.cgi/nullshell/) [GitLab.com](https://gitlab.com/eworm-de/nullshell#nullshell) + +--- +[⬆️ Go back to top](#top) diff --git a/config.def.h b/config.def.h index 0c4de18..4a42bde 100644 --- a/config.def.h +++ b/config.def.h @@ -1,5 +1,5 @@ /* - * (C) 2013-2024 by Christian Hesse <mail@eworm.de> + * (C) 2013-2025 by Christian Hesse <mail@eworm.de> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,11 +19,14 @@ #ifndef _CONFIG_H #define _CONFIG_H -/* this is the time to sleep between printing characters */ -#define SLEEPTIME 1 +/* this is the time to sleep (in milli-seconds) between printing characters */ +#define SLEEPTIME 1000 + +/* this is the number of line between banner appears */ +#define BANNERCONST 20 /* some text to be printed */ -#define URL "https://github.com/eworm-de/nullshell" +#define URL "https://nullshell.eworm.de/" #define BANNER "Do-nothing-loop by nullshell " VERSION ",\n" \ "compiled on " __DATE__ " " __TIME__ ".\n" \ "Visit homepage: " URL "\n" diff --git a/nullshell.c b/nullshell.c index 9218c18..d053f8d 100644 --- a/nullshell.c +++ b/nullshell.c @@ -1,5 +1,5 @@ /* - * (C) 2013-2024 by Christian Hesse <mail@eworm.de> + * (C) 2013-2025 by Christian Hesse <mail@eworm.de> * * Based on ideas from Sleep Dummy Shell (SleepShell) * by Mario A. Valdez-Ramirez (http://www.mariovaldez.net/) @@ -40,22 +40,20 @@ void sig_callback(int signal) { int main(int argc, char **argv) { time_t now; - uint8_t start; + uint8_t lines = BANNERCONST; char *ssh_connection, *ssh_client, *ssh_tty; char * string = BANNER; - /* get the start time and calculate modulo */ - time(&now); - start = (now / 30) % 30; - /* read environment variables */ ssh_connection = getenv("SSH_CONNECTION"); ssh_client = getenv("SSH_CLIENT"); ssh_tty = getenv("SSH_TTY"); /* register signal callbacks */ - signal(SIGTERM, sig_callback); - signal(SIGINT, sig_callback); + struct sigaction act = { 0 }; + act.sa_handler = sig_callback; + sigaction(SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); /* clear the screen and set cursor to the top left * see 'man 4 console_codes' for details */ @@ -69,17 +67,19 @@ int main(int argc, char **argv) { printf("Terminal: %s\n", ssh_tty); } - /* print an character every SLEEPTIME seconds */ + /* print a character every SLEEPTIME milli-seconds */ while (1) { - sleep(SLEEPTIME); + usleep(SLEEPTIME * 1000); putchar(*string); fflush(NULL); if (*string == 0) { - time(&now); - if ((now / 30) % 30 != start) + if (lines-- > 0) { + time(&now); string = ctime(&now); - else + } else { string = BANNER; + lines = BANNERCONST; + } } else string++; } |