mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
Add a /bin/tty command that prints the current tty.
Also fix ttyname() syscall to include "/dev/" in the name.
This commit is contained in:
parent
4605b549d6
commit
c7d5ce6b5a
6 changed files with 28 additions and 5 deletions
|
@ -400,7 +400,7 @@ void VirtualConsole::onTTYWrite(byte ch)
|
|||
|
||||
String VirtualConsole::ttyName() const
|
||||
{
|
||||
char buf[8];
|
||||
ksprintf(buf, "tty%u", m_index);
|
||||
char buf[16];
|
||||
ksprintf(buf, "/dev/tty%u", m_index);
|
||||
return String(buf);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ cp ../Userland/clear mnt/bin/clear
|
|||
cp ../Userland/tst mnt/bin/tst
|
||||
cp ../Userland/mm mnt/bin/mm
|
||||
cp ../Userland/kill mnt/bin/kill
|
||||
cp ../Userland/tty mnt/bin/tty
|
||||
sh sync-local.sh
|
||||
cp kernel.map mnt/
|
||||
umount mnt
|
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -15,3 +15,4 @@ clear
|
|||
tst
|
||||
mm
|
||||
kill
|
||||
tty
|
||||
|
|
|
@ -13,7 +13,8 @@ OBJS = \
|
|||
clear.o \
|
||||
tst.o \
|
||||
mm.o \
|
||||
kill.o
|
||||
kill.o \
|
||||
tty.o
|
||||
|
||||
APPS = \
|
||||
id \
|
||||
|
@ -30,7 +31,8 @@ APPS = \
|
|||
clear \
|
||||
tst \
|
||||
mm \
|
||||
kill
|
||||
kill \
|
||||
tty
|
||||
|
||||
ARCH_FLAGS =
|
||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
|
||||
|
@ -95,6 +97,9 @@ mm: mm.o
|
|||
kill: kill.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
tty: tty.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
struct GlobalState {
|
||||
String cwd;
|
||||
String username;
|
||||
const char* ttyname_short { nullptr };
|
||||
char ttyname[32];
|
||||
char hostname[32];
|
||||
};
|
||||
|
@ -160,7 +161,7 @@ static void greeting()
|
|||
perror("uname");
|
||||
return;
|
||||
}
|
||||
printf("\n%s/%s on %s\n\n", uts.sysname, uts.machine, g->ttyname);
|
||||
printf("\n%s/%s on %s\n\n", uts.sysname, uts.machine, g->ttyname_short);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
|
@ -172,6 +173,8 @@ int main(int, char**)
|
|||
rc = ttyname_r(0, g->ttyname, sizeof(g->ttyname));
|
||||
if (rc < 0)
|
||||
perror("ttyname_r");
|
||||
else
|
||||
g->ttyname_short = strrchr(g->ttyname, '/') + 1;
|
||||
{
|
||||
auto* pw = getpwuid(getuid());
|
||||
if (pw)
|
||||
|
|
13
Userland/tty.cpp
Normal file
13
Userland/tty.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <LibC/stdio.h>
|
||||
#include <LibC/unistd.h>
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
char* tty = ttyname(0);
|
||||
if (!tty) {
|
||||
perror("Error");
|
||||
return 1;
|
||||
}
|
||||
printf("%s\n", tty);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue