summaryrefslogtreecommitdiffstats
path: root/debian/patches/81_session_creation_util.patch
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:20:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:20:21 +0000
commitef3904423d3301d87b4b499b7e5feb359d622405 (patch)
tree981032c10096a70b0cb95ea74de48492f9f08251 /debian/patches/81_session_creation_util.patch
parentAdding upstream version 4.6.2. (diff)
downloadscreen-ef3904423d3301d87b4b499b7e5feb359d622405.tar.xz
screen-ef3904423d3301d87b4b499b7e5feb359d622405.zip
Adding debian version 4.6.2-3+deb10u1.debian/4.6.2-3+deb10u1debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/patches/81_session_creation_util.patch')
-rw-r--r--debian/patches/81_session_creation_util.patch77
1 files changed, 77 insertions, 0 deletions
diff --git a/debian/patches/81_session_creation_util.patch b/debian/patches/81_session_creation_util.patch
new file mode 100644
index 0000000..85d3d18
--- /dev/null
+++ b/debian/patches/81_session_creation_util.patch
@@ -0,0 +1,77 @@
+Author: Jan Christoph Nordholz <hesso@pool.math.tu-berlin.de>
+Description: Add lookup code for the creation time of each session.
+ Requires digging in /proc/$pid and /proc/uptime, though, so it's
+ definitely no candidate for the Beautiful C contest.
+ .
+ Affects screen's behaviour in the following situations:
+ .
+ * 'screen -ls' lists available sessions sorted chronologically
+ * 'screen -RR' now picks the youngest session instead of an
+ arbitrary one
+ .
+ Patch 2/3: new utility functions
+Bug-Debian: https://bugs.debian.org/206572
+Forwarded: not-yet
+
+--- a/extern.h
++++ b/extern.h
+@@ -393,6 +393,8 @@
+ #else
+ extern int xsnprintf __P(());
+ #endif
++extern time_t SessionCreationTime __P((const char *));
++extern time_t GetUptime __P((void));
+
+
+ /* acl.c */
+--- a/misc.c
++++ b/misc.c
+@@ -29,6 +29,7 @@
+ #include <sys/types.h>
+ #include <sys/stat.h> /* mkdir() declaration */
+ #include <signal.h>
++#include <fcntl.h>
+
+ #include "config.h"
+ #include "screen.h"
+@@ -769,3 +770,40 @@
+ }
+
+ #endif
++
++time_t SessionCreationTime(const char *fifo) {
++ char ppath[20];
++ int pfd;
++ char pdata[512];
++ char *jiffies;
++
++ int pid = atoi(fifo);
++ if (pid <= 0) return 0;
++ sprintf(ppath, "/proc/%u/stat", pid);
++ pfd = open(ppath, O_RDONLY);
++ if (pfd < 0) return 0;
++ while (1) {
++ int R=0, RR;
++ RR = read(pfd, pdata + R, 512-R);
++ if (RR < 0) {close(pfd); return 0;}
++ else if (RR == 0) break;
++ }
++ close(pfd);
++
++ for (pfd=21, jiffies=pdata; pfd; --pfd) {
++ jiffies = strchr(jiffies, ' ');
++ if (!jiffies) break; else ++jiffies;
++ }
++ if (!jiffies) return 0;
++
++ return atol(jiffies) / 100;
++}
++
++time_t GetUptime(void) {
++ char uptimestr[32];
++ int fd = open("/proc/uptime", O_RDONLY);
++ if (fd < 0) return 0;
++ (void)read(fd, uptimestr, 32);
++ close(fd);
++ return atol(uptimestr);
++}