mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00: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
|
String VirtualConsole::ttyName() const
|
||||||
{
|
{
|
||||||
char buf[8];
|
char buf[16];
|
||||||
ksprintf(buf, "tty%u", m_index);
|
ksprintf(buf, "/dev/tty%u", m_index);
|
||||||
return String(buf);
|
return String(buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ cp ../Userland/clear mnt/bin/clear
|
||||||
cp ../Userland/tst mnt/bin/tst
|
cp ../Userland/tst mnt/bin/tst
|
||||||
cp ../Userland/mm mnt/bin/mm
|
cp ../Userland/mm mnt/bin/mm
|
||||||
cp ../Userland/kill mnt/bin/kill
|
cp ../Userland/kill mnt/bin/kill
|
||||||
|
cp ../Userland/tty mnt/bin/tty
|
||||||
sh sync-local.sh
|
sh sync-local.sh
|
||||||
cp kernel.map mnt/
|
cp kernel.map mnt/
|
||||||
umount mnt
|
umount mnt
|
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -15,3 +15,4 @@ clear
|
||||||
tst
|
tst
|
||||||
mm
|
mm
|
||||||
kill
|
kill
|
||||||
|
tty
|
||||||
|
|
|
@ -13,7 +13,8 @@ OBJS = \
|
||||||
clear.o \
|
clear.o \
|
||||||
tst.o \
|
tst.o \
|
||||||
mm.o \
|
mm.o \
|
||||||
kill.o
|
kill.o \
|
||||||
|
tty.o
|
||||||
|
|
||||||
APPS = \
|
APPS = \
|
||||||
id \
|
id \
|
||||||
|
@ -30,7 +31,8 @@ APPS = \
|
||||||
clear \
|
clear \
|
||||||
tst \
|
tst \
|
||||||
mm \
|
mm \
|
||||||
kill
|
kill \
|
||||||
|
tty
|
||||||
|
|
||||||
ARCH_FLAGS =
|
ARCH_FLAGS =
|
||||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
|
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
|
||||||
|
@ -95,6 +97,9 @@ mm: mm.o
|
||||||
kill: kill.o
|
kill: kill.o
|
||||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||||
|
|
||||||
|
tty: tty.o
|
||||||
|
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
struct GlobalState {
|
struct GlobalState {
|
||||||
String cwd;
|
String cwd;
|
||||||
String username;
|
String username;
|
||||||
|
const char* ttyname_short { nullptr };
|
||||||
char ttyname[32];
|
char ttyname[32];
|
||||||
char hostname[32];
|
char hostname[32];
|
||||||
};
|
};
|
||||||
|
@ -160,7 +161,7 @@ static void greeting()
|
||||||
perror("uname");
|
perror("uname");
|
||||||
return;
|
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**)
|
int main(int, char**)
|
||||||
|
@ -172,6 +173,8 @@ int main(int, char**)
|
||||||
rc = ttyname_r(0, g->ttyname, sizeof(g->ttyname));
|
rc = ttyname_r(0, g->ttyname, sizeof(g->ttyname));
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
perror("ttyname_r");
|
perror("ttyname_r");
|
||||||
|
else
|
||||||
|
g->ttyname_short = strrchr(g->ttyname, '/') + 1;
|
||||||
{
|
{
|
||||||
auto* pw = getpwuid(getuid());
|
auto* pw = getpwuid(getuid());
|
||||||
if (pw)
|
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…
Add table
Add a link
Reference in a new issue