summaryrefslogtreecommitdiffstats
path: root/nullshell.c
blob: 9225fd2518008fa5f235d192caf8d632374947d1 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * (C) 2013-2014 by Christian Hesse <mail@eworm.de>
 *
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 *
 * Based on ideas from Sleep Dummy Shell (SleepShell)
 * by Mario A. Valdez-Ramirez (http://www.mariovaldez.net/)
 */

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include "config.h"
#include "version.h"

void sig_callback(int signal) {
	printf("\nReceived signal '%s', quitting.\nBye!\n", strsignal(signal));

	exit(EXIT_SUCCESS);
}

int main(int argc, char **argv) {
	time_t now;
	char *ssh_connection, *ssh_client, *ssh_tty;
	char * string = BANNER;

	/* 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);

	/* clear the screen and set cursor to the top left
	 * see 'man 4 console_codes' for details */
	fputs("\033[2J\033[1;1H", stdout);
	fflush(NULL);

	/* print some info if available */
	if (ssh_connection != NULL && ssh_client != NULL) {
		printf("Connection: %s\nClient: %s\n", ssh_connection, ssh_client);
		if (ssh_tty != NULL)
			printf("Terminal: %s\n", ssh_tty);
	}

	/* print an asterisk every SLEEPTIME seconds */
	while (1) {
		sleep(SLEEPTIME);
		putchar(*string);
		fflush(NULL);
		if (*string == 0) {
			time(&now);
			string = ctime(&now);
		} else
			string++;
	}

	/* we should never get here.... */
	return EXIT_SUCCESS;
}

// vim: set syntax=c: