commit 5933cb06bf773a91f41dc82ad0f0720f33cba651
parent e57de22d9c3d20df7061a041e7770e1d380c76cf
Author: xplshn <anto@xplshn.com.ar>
Date: Tue, 24 Nov 2026 14:37:27 -0300
tty: a backend per kernel
Diffstat:
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/ninqu.rules b/ninqu.rules
@@ -50,7 +50,8 @@
"passwd_netbsd.c" "passwd_openbsd.c" "passwd_other.c"
"proc_linux.c" "proc_other.c"
"session_linux.c" "session_other.c"
- "sysinfo_linux.c" "sysinfo_other.c")
+ "sysinfo_linux.c" "sysinfo_other.c"
+ "tty_linux.c" "tty_other.c")
(dep $(MATCH) FEATURES_H)
(after NOFORK_LIST_H)
(out "$(STEM).o")
@@ -84,7 +85,9 @@
"shared/libutil/session_linux.c"
"shared/libutil/session_other.c"
"shared/libutil/sysinfo_linux.c"
- "shared/libutil/sysinfo_other.c")
+ "shared/libutil/sysinfo_other.c"
+ "shared/libutil/tty_linux.c"
+ "shared/libutil/tty_other.c")
(dep $(MATCH) "shared/diskutil.h" "shared/filesystem.h" "shared/net.h" "shared/passwd.h"
"shared/proc.h" "shared/session.h" "shared/sysinfo.h" "shared/util.h"
FEATURES_H)
diff --git a/shared/libutil/tty_linux.c b/shared/libutil/tty_linux.c
@@ -1,4 +1,9 @@
/* see LICENSE file for copyright and license details */
+#include "../util.h"
+
+/* the numbers are the ones linux gives ttys, and the dev the encoding
+ * of tty_nr in /proc/<pid>/stat */
+#if defined(__linux__) && !defined(ARUU_FORCE_OTHER)
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
@@ -12,7 +17,6 @@
#include <unistd.h>
#include "../paths.h"
-#include "../util.h"
void
devtotty(int dev, int *tty_maj, int *tty_min)
@@ -95,3 +99,4 @@ err0:
return r;
}
+#endif
diff --git a/shared/libutil/tty_other.c b/shared/libutil/tty_other.c
@@ -0,0 +1,28 @@
+/* see LICENSE file for copyright and license details */
+#include "../filesystem.h"
+#include "../util.h"
+
+#include <stddef.h>
+
+/* a kernel with no backend: the numbers are the ones its dev_t holds,
+ * and no name is known for them */
+#if !defined(__linux__) || defined(ARUU_FORCE_OTHER)
+void
+devtotty(int dev, int *tty_maj, int *tty_min)
+{
+ *tty_maj = fs_devmajor(dev);
+ *tty_min = fs_devminor(dev);
+}
+
+int
+ttytostr(int tty_maj, int tty_min, char *str, size_t n)
+{
+ (void)tty_maj;
+ (void)tty_min;
+ if (n < 2)
+ return -1;
+ str[0] = '?';
+ str[1] = '\0';
+ return 0;
+}
+#endif