hi,
been tinkering with that the past day and i'm at a point where i have
something that feels acceptable. xterm in base has been using
pledge/unveil for now more than 10 years, so i've tried achieving
something similar, while adapting for the specificities of gtk/vte3.
that's an interesting experiment, i dont know if it's worth getting
further, but that shows that it's possible to hide ~/.ssh from the
terminal process itself, like it's been done for xterm. Or what is
needed to add pledge/unveil to "generic" gtk applications.
since sakura has support for tabs, it needs a bit more than xterm
because opening a new shell requires write access to /dev/ptm, and read
access to /dev/ttyp*. this isnt needed if you don't open tabs/new
windows.. openind a new window via ctrl-shift-o tries to spawn 'sakura'
without the full path so that now fails (and unveiling it with the full
path isn't enough).
gtk_main() loads glib/gtk modules, so that needs prot_exec to dlopen
/usr/local/lib/gtk-3.0/ & /usr/local/lib/gio.
on wayland, gtk itself additionally needs wpath on /tmp/*shm, and
sendfd/recvfd.
i've only unveiled /bin/ksh rx, but adding support for the user's shell
should be trivial.
on the vte3 side, the diff does two things:
- disable ioctl(TIOCPKT) on the slave pty, that's not permitted by
pledge tty, and that's apparently not useful. Havent spotted
differences in using sakura/xfce4-terminal, but other apps might do
other things with vte..
- don't call chdir() if the current dir is already the desired one. with
that tweak, i don't need to unveil($HOME) in sakura (which is the
default cwd) since the shell that will be spawned by the new tab will
already have access to the existing CWD (as ksh itself doesnt use
unveil())
now that sakura works, i'll try to apply similar treatment to
xfce4-terminal.
feedback & testing welcome.
Landry
Index: Makefile
===================================================================
RCS file: /cvs/ports/x11/sakura/Makefile,v
diff -u -r1.35 Makefile
--- Makefile 26 May 2025 20:48:47 -0000 1.35
+++ Makefile 6 Nov 2026 13:22:05 -0000
@@ -3,6 +3,7 @@
DISTNAME = sakura-${V}
EXTRACT_SUFX = .tar.bz2
CATEGORIES = x11
+REVISION = 0
HOMEPAGE = http://www.pleyades.net/david/projects/sakura/
MAINTAINER = Victor Kukshiev <[email protected]>
Index: patches/patch-src_sakura_c
===================================================================
RCS file: patches/patch-src_sakura_c
diff -N patches/patch-src_sakura_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_sakura_c 6 Nov 2026 13:22:05 -0000
@@ -0,0 +1,102 @@
+add pledge/unveil
+
+Index: src/sakura.c
+--- src/sakura.c.orig
++++ src/sakura.c
+@@ -3098,7 +3098,7 @@ sakura_add_tab()
+ /* If OSC7 method doesn't work, use the old one as fallback */
+ if ((cwd = sakura_get_term_cwd_osc7(prev_term)) == NULL) {
+ SAY("osc7 is null");
+- sakura_get_term_cwd(prev_term);
++ cwd = sakura_get_term_cwd(prev_term);
+ }
+
+ sk_tab->colorset = prev_term->colorset;
+@@ -3843,6 +3843,87 @@ main(int argc, char **argv)
+
+ sakura_sanitize_working_directory();
+
++#ifdef __OpenBSD__
++ char *env;
++
++ if ((env = getenv("HOME"))) {
++ char homefile[PATH_MAX];
++ if (snprintf(homefile, sizeof homefile, "%s/.fonts", env) <=
sizeof(homefile))
++ if (unveil(homefile, "r") == -1)
++ g_error("unveil %s", homefile);
++ if (snprintf(homefile, sizeof homefile, "%s/.cache/fontconfig",
env) <= sizeof(homefile))
++ if (unveil(homefile, "r") == 1)
++ g_error("unveil %s", homefile);
++ if (snprintf(homefile, sizeof homefile, "%s/.icons", env) <=
sizeof(homefile))
++ if (unveil(homefile, "r") == -1)
++ g_error("unveil %s", homefile);
++ }
++
++ if ((env = getenv("XDG_CONFIG_HOME"))) {
++ char xdgfile[PATH_MAX];
++ if (snprintf(xdgfile, sizeof xdgfile, "%s/fontconfig", env) <=
sizeof(xdgfile))
++ if (unveil(xdgfile, "r") == -1)
++ g_error("unveil %s", xdgfile);
++ if (snprintf(xdgfile, sizeof xdgfile, "%s/icons", env) <=
sizeof(xdgfile))
++ if (unveil(xdgfile, "r") == -1)
++ g_error("unveil %s", xdgfile);
++ }
++
++ if ((env = getenv("XDG_DATA_HOME"))) {
++ char xdgfile[PATH_MAX];
++ if (snprintf(xdgfile, sizeof xdgfile, "%s/fontconfig", env) <=
sizeof(xdgfile))
++ if (unveil(xdgfile, "r") == -1)
++ g_error("unveil %s", xdgfile);
++ if (snprintf(xdgfile, sizeof xdgfile, "%s/icons", env) <=
sizeof(xdgfile))
++ if (unveil(xdgfile, "r") == -1)
++ g_error("unveil %s", xdgfile);
++ }
++
++ if ((env = getenv("XDG_CACHE_HOME"))) {
++ char xdgfile[PATH_MAX];
++ if (snprintf(xdgfile, sizeof xdgfile, "%s/fontconfig", env) <=
sizeof(xdgfile))
++ if (unveil(xdgfile, "r") == -1)
++ g_error("unveil %s", xdgfile);
++ }
++
++ if (unveil("/usr/X11R6", "r") == -1)
++ g_error("unveil /usr/X11R6");
++ if (unveil("/usr/local/lib", "r") == -1)
++ g_error("unveil /usr/local/lib");
++ if (unveil("/var/cache/fontconfig", "r") == -1)
++ g_error("unveil /var/cache/fontconfig");
++ if (unveil("/usr/local/share", "r") == -1)
++ g_error("unveil /usr/local/share");
++
++ if (unveil("/bin/ksh", "rx") == -1) {
++ g_error ("unveil /bin/ksh failed");
++ exit(1);
++ }
++ /* needed for ptm & ttypX */
++ if (unveil("/dev/", "rw") == -1) {
++ g_error ("unveil /dev/ failed");
++ exit(1);
++ }
++ // gtk initialisation needs dlopen(modules) -> prot_exec
++ // proc+exec+wpath on /dev/ptm needed to open new tabs
++ const gchar *wayland = g_getenv("WAYLAND_DISPLAY");
++ if (wayland == NULL) {
++ if (pledge("stdio prot_exec wpath rpath proc exec tty", NULL)
== -1) {
++ g_error ("pledge failed");
++ exit(1);
++ }
++ } else {
++ // wayland needs wpath /tmp/*shm and sendfd/recvfd
++ if (unveil("/tmp", "rwc") == -1) {
++ g_error ("unveil /tmp failed");
++ exit(1);
++ }
++ if (pledge("stdio prot_exec recvfd sendfd cpath wpath rpath
proc exec tty", NULL) == -1) {
++ g_error ("pledge failed");
++ exit(1);
++ }
++ }
++#endif
+ gtk_main();
+
+ return 0;
Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/vte3/Makefile,v
diff -u -r1.155 Makefile
--- Makefile 2 Aug 2026 03:54:31 -0000 1.155
+++ Makefile 6 Nov 2026 13:22:23 -0000
@@ -4,6 +4,7 @@
GNOME_PROJECT= vte
GNOME_VERSION= 0.84.1
+REVISION= 0
PKGNAME-main= vte3-${GNOME_VERSION}
PKGNAME-gtk4= vte3-gtk4-${GNOME_VERSION}
Index: patches/patch-src_pty_cc
===================================================================
RCS file: patches/patch-src_pty_cc
diff -N patches/patch-src_pty_cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_pty_cc 6 Nov 2026 13:22:23 -0000
@@ -0,0 +1,14 @@
+disable TIOCPKT, not available with pledge on OpenBSD
+
+Index: src/pty.cc
+--- src/pty.cc.orig
++++ src/pty.cc
+@@ -349,7 +349,7 @@ static int
+ fd_set_cpkt(vte::libc::FD& fd)
+ {
+ auto ret = 0;
+-#if defined(TIOCPKT)
++#if defined(TIOCPKT) && !defined(__OpenBSD__)
+ /* tty_ioctl(4) -> every read() gives an extra byte at the beginning
+ * notifying us of stop/start (^S/^Q) events. */
+ int one = 1;
Index: patches/patch-src_spawn_cc
===================================================================
RCS file: patches/patch-src_spawn_cc
diff -N patches/patch-src_spawn_cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_spawn_cc 6 Nov 2026 13:22:23 -0000
@@ -0,0 +1,29 @@
+dont chdir() if we're already in the target dir
+
+prevents issues when the dir isnt unveiled, the child shell will still start
in the right dir
+Index: src/spawn.cc
+--- src/spawn.cc.orig
++++ src/spawn.cc
+@@ -390,16 +390,20 @@ SpawnContext::exec(vte::libc::FD& child_report_error_p
+ return ExecError::FDWALK;
+
+ /* Working directory */
+- if (m_cwd && chdir(m_cwd.get()) < 0) {
++ char * cwd = g_get_current_dir();
++ if (m_cwd && g_strcmp0(cwd, m_cwd.get()) != 0 && chdir(m_cwd.get()) <
0) {
+ /* If the fallback fails too, make sure to return the errno
+ * from the original cwd, not the fallback cwd.
+ */
+ auto errsv = vte::libc::ErrnoSaver{};
+- if (m_fallback_cwd && chdir(m_fallback_cwd.get()) < 0)
++ if (m_fallback_cwd && chdir(m_fallback_cwd.get()) < 0) {
++ g_free(cwd);
+ return ExecError::CHDIR;
++ }
+
+ errsv.reset();
+ }
++ g_free(cwd);
+
+ /* Session */
+ if (!(pty()->flags() & VTE_PTY_NO_SESSION)) {
Index: patches/patch-src_vte_cc
===================================================================
RCS file: patches/patch-src_vte_cc
diff -N patches/patch-src_vte_cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_vte_cc 6 Nov 2026 13:22:23 -0000
@@ -0,0 +1,14 @@
+disable TIOCPKT, not available with pledge on OpenBSD
+
+Index: src/vte.cc
+--- src/vte.cc.orig
++++ src/vte.cc
+@@ -4489,7 +4489,7 @@ Terminal::pty_io_read(int const fd,
+ bp = chunk->begin_writing();
+ len = 0;
+ do {
+-#if defined(TIOCPKT)
++#if defined(TIOCPKT) && !defined(__OpenBSD__)
+ /* We'd like to read (fd, bp, rem); but due
to TIOCPKT mode
+ * there's an extra input byte returned at
the beginning.
+ * We need to see what that byte is, but
otherwise drop it