fix: make KF6 Pty build on Redox

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-05-07 08:06:59 +01:00
parent 52954456f2
commit d8d26eaff3
3 changed files with 36 additions and 8 deletions
+16 -1
View File
@@ -439,7 +439,7 @@ void KPty::setCTty()
setsid();
// make our slave pty the new controlling terminal.
ioctl(d->slaveFd, TIOCSCTTY, 0);
ioctl(d->slaveFd, TIOCSCTTY, nullptr);
// make our new process group the foreground group on the pty
int pgrp = getpid();
@@ -448,6 +448,15 @@ void KPty::setCTty()
void KPty::login(const char *user, const char *remotehost)
{
#ifdef __redox__
// Redox provides PTY allocation and terminal attributes, but it does not yet
// expose a utmp/wtmp database API. Keep KPty functional while making login
// accounting an explicit no-op on this target rather than referencing
// incomplete libc utmp declarations.
Q_UNUSED(user);
Q_UNUSED(remotehost);
return;
#else
#ifdef UTEMPTER_PATH
Q_D(KPty);
@@ -533,10 +542,15 @@ void KPty::login(const char *user, const char *remotehost)
#endif
#endif
#endif
#endif
}
void KPty::logout()
{
#ifdef __redox__
// See KPty::login(): there is no Redox utmp/wtmp backend to update yet.
return;
#else
#ifdef UTEMPTER_PATH
Q_D(KPty);
@@ -612,6 +626,7 @@ void KPty::logout()
#endif
#endif
#endif
#endif
}
bool KPty::tcGetAttr(struct ::termios *ttmode) const
@@ -17,6 +17,7 @@
#include <KLocalizedString>
#include <cerrno>
#include <ctime>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
@@ -42,6 +43,18 @@
#define KMAXINT ((int)(~0U >> 1))
static void currentTimeval(struct timeval *tv)
{
#ifdef __redox__
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
#else
gettimeofday(tv, nullptr);
#endif
}
/////////////////////////////////////////////////////
// Helper. Remove when QRingBuffer becomes public. //
/////////////////////////////////////////////////////
@@ -365,7 +378,7 @@ bool KPtyDevicePrivate::doWait(int msecs, bool reading)
tv.tv_sec = msecs / 1000;
tv.tv_usec = (msecs % 1000) * 1000;
#ifndef Q_OS_LINUX
gettimeofday(&etv, nullptr);
currentTimeval(&etv);
timeradd(&tv, &etv, &etv);
#endif
tvp = &tv;
@@ -387,7 +400,7 @@ bool KPtyDevicePrivate::doWait(int msecs, bool reading)
#ifndef Q_OS_LINUX
if (tvp) {
gettimeofday(&tv, nullptr);
currentTimeval(&tv);
timersub(&etv, &tv, &tv);
if (tv.tv_sec < 0) {
tv.tv_sec = tv.tv_usec = 0;