mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Only the tty1 login session powers off.
This commit is contained in:
parent
88a6317700
commit
7de1942803
2 changed files with 26 additions and 2 deletions
3
sh/sh.c
3
sh/sh.c
|
@ -1551,6 +1551,9 @@ bool does_line_editing_need_another_line(void* ctx, const char* line)
|
|||
|
||||
bool is_outermost_shell(void)
|
||||
{
|
||||
char* name = ttyname(0);
|
||||
if ( !name || strcmp(name, "/dev/tty1") != 0 )
|
||||
return false;
|
||||
const char* shlvl_str = getenv("SHLVL");
|
||||
if ( !shlvl_str )
|
||||
return true;
|
||||
|
|
|
@ -19,11 +19,24 @@
|
|||
* of a typo.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char* tty_name(void)
|
||||
{
|
||||
int tty_fd = open("/dev/tty", O_RDONLY);
|
||||
const char* result = NULL;
|
||||
if ( 0 <= tty_fd )
|
||||
{
|
||||
result = ttyname(tty_fd);
|
||||
close(tty_fd);
|
||||
}
|
||||
return result ? result : "/dev/tty";
|
||||
}
|
||||
|
||||
void suggest_editor(const char* filename)
|
||||
{
|
||||
fprintf(stderr, "No command '%s' found, did you mean:\n", filename);
|
||||
|
@ -63,7 +76,11 @@ void suggest_logout(const char* filename)
|
|||
void suggest_poweroff(const char* filename)
|
||||
{
|
||||
fprintf(stderr, "No command '%s' found, did you mean:\n", filename);
|
||||
if ( getenv("LOGIN_PID") )
|
||||
if ( strcmp(tty_name(), "/dev/tty1") != 0 )
|
||||
{
|
||||
fprintf(stderr, " Powering off on /dev/tty1.\n");
|
||||
}
|
||||
else if ( getenv("LOGIN_PID") )
|
||||
{
|
||||
fprintf(stderr, " Exiting your shell normally to logout.\n");
|
||||
fprintf(stderr, " Login as user 'poweroff' to power off computer.\n");
|
||||
|
@ -77,7 +94,11 @@ void suggest_poweroff(const char* filename)
|
|||
void suggest_reboot(const char* filename)
|
||||
{
|
||||
fprintf(stderr, "No command '%s' found, did you mean:\n", filename);
|
||||
if ( getenv("LOGIN_PID") )
|
||||
if ( strcmp(tty_name(), "/dev/tty1") != 0 )
|
||||
{
|
||||
fprintf(stderr, " Rebooting on /dev/tty1.\n");
|
||||
}
|
||||
else if ( getenv("LOGIN_PID") )
|
||||
{
|
||||
fprintf(stderr, " Exiting your shell normally to logout.\n");
|
||||
fprintf(stderr, " Login as user 'reboot' to reboot computer.\n");
|
||||
|
|
Loading…
Reference in a new issue