summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/VirtualConsole.cpp4
-rwxr-xr-xKernel/sync.sh (renamed from Kernel/sync-sh)1
-rw-r--r--Userland/.gitignore1
-rw-r--r--Userland/Makefile9
-rw-r--r--Userland/sh.cpp5
-rw-r--r--Userland/tty.cpp13
6 files changed, 28 insertions, 5 deletions
diff --git a/Kernel/VirtualConsole.cpp b/Kernel/VirtualConsole.cpp
index eea5bb2bb7..b6479493e6 100644
--- a/Kernel/VirtualConsole.cpp
+++ b/Kernel/VirtualConsole.cpp
@@ -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);
}
diff --git a/Kernel/sync-sh b/Kernel/sync.sh
index 680f3c33d2..8a16e5329a 100755
--- a/Kernel/sync-sh
+++ b/Kernel/sync.sh
@@ -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
diff --git a/Userland/.gitignore b/Userland/.gitignore
index 7207e83cfc..77d7e70b48 100644
--- a/Userland/.gitignore
+++ b/Userland/.gitignore
@@ -15,3 +15,4 @@ clear
tst
mm
kill
+tty
diff --git a/Userland/Makefile b/Userland/Makefile
index 87d1e0809f..c94558e2d6 100644
--- a/Userland/Makefile
+++ b/Userland/Makefile
@@ -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 $<
diff --git a/Userland/sh.cpp b/Userland/sh.cpp
index 3a660c0d01..f218ae7290 100644
--- a/Userland/sh.cpp
+++ b/Userland/sh.cpp
@@ -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)
diff --git a/Userland/tty.cpp b/Userland/tty.cpp
new file mode 100644
index 0000000000..a675893917
--- /dev/null
+++ b/Userland/tty.cpp
@@ -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;
+}