Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active May 5, 2022 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-yuri/c3c715ea6355633de4546ae957a66410 to your computer and use it in GitHub Desktop.
Save x-yuri/c3c715ea6355633de4546ae957a66410 to your computer and use it in GitHub Desktop.

docker-compose.yml:

version: '3'
services:
    app:
        build: .
        tmpfs:
            - /tmp
            - /run
            - /run/lock
        volumes:
            - /sys/fs/cgroup:/sys/fs/cgroup:ro
        ports:
            - 5901:5901
volumes:
    config:

Dockerfile:

FROM ubuntu:22.04
RUN apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y \
        gnome-shell gnome-session gnome-terminal
RUN apt-get remove -y bluez rtkit \
    && apt-get install -y tigervnc-standalone-server \
    && useradd -ms /bin/bash a \
    && echo ':1=a' > /etc/tigervnc/vncserver.users \
    && systemctl enable tigervncserver@:1
USER a
RUN mkdir -p /home/a/.vnc \
    && echo acoman | vncpasswd -f > /home/a/.vnc/passwd \
    && chmod 600 /home/a/.vnc/passwd \
    && echo 'localhost=no' >> /home/a/.vnc/config \
    && echo 'geometry=1024x768' >> /home/a/.vnc/config
COPY --chown=a Xtigervnc-session /home/a/.vnc
USER root
RUN apt-get install -y mc less vim
RUN cd / \
    && apt-get install -y git \
    && git clone https://gitlab.gnome.org/GNOME/gnome-keyring \
    && cd gnome-keyring \
    && git checkout 40.0
COPY gkd-main.c /gnome-keyring/daemon
RUN apt install -y build-essential autoconf autopoint libtool libgcrypt20-dev pkg-config libglib2.0-dev libgck-1-dev libgcr-3-dev xsltproc libcap-ng-dev libpam0g-dev docbook-xsl gettext \
    && cd gnome-keyring \
    && ./autogen.sh \
    && make install
COPY gnome-keyring.service /usr/lib/systemd/user

CMD ["/sbin/init"]

gkd-main.c:

--- gkd-main.c.orig	2022-05-02 08:49:36.924182638 +0300
+++ gkd-main.c	2022-05-02 08:50:18.367949971 +0300
@@ -485,6 +485,8 @@
 cleanup_and_exit (int code)
 {
 	egg_cleanup_perform ();
+g_message("-- cleanup_and_exit: exit(code), %i, %i", code, __LINE__);
 	exit (code);
 }
 
@@ -639,24 +640,35 @@
 		return -1;
 	}
 
-	if (!g_unix_open_pipe (wakeup_fds, FD_CLOEXEC, NULL))
+	if (!g_unix_open_pipe (wakeup_fds, FD_CLOEXEC, NULL)) {
+g_message("-- fork_and_print_environment: exit(1), %i", __LINE__);
 		exit (1);
+    }
 
 	pid = fork ();
 
 	if (pid != 0) {
+g_message("-- fork_and_print_environment: fork(), parent, %i", __LINE__);
 		/* Here we are in the initial process */
 		close (wakeup_fds[1]);
 
 		if (run_daemonized) {
 
 			/* Initial process, waits for intermediate child */
-			if (pid == -1)
+			if (pid == -1) {

+g_message("-- fork_and_print_environment: exit(1), %i", __LINE__);
 				exit (1);
+            }
 
 			waitpid (pid, &status, 0);
-			if (WEXITSTATUS (status) != 0)
+			if (WEXITSTATUS (status) != 0) {

+g_message("-- fork_and_print_environment: exit(WEXITSTATUS(status)), %i, %i", WEXITSTATUS(status), __LINE__);
 				exit (WEXITSTATUS (status));
+            }
 
 		} else {
 			/* Not double forking, wait for child */
@@ -664,8 +676,12 @@
 		}
 
 		/* The initial process exits successfully */
+g_message("-- fork_and_print_environment: exit(0), %i", __LINE__);
 		exit (0);
 	}
+g_message("-- fork_and_print_environment: fork(), child, %i", __LINE__);
 
 	if (run_daemonized) {
 
@@ -680,6 +696,8 @@
 		pid = fork ();
 
 		if (pid != 0) {
+g_message("-- fork_and_print_environment: fork(), parent 2, %i", __LINE__);
 			close (wakeup_fds[1]);
 
 			/* Here we are in the intermediate child process */
@@ -688,15 +706,22 @@
 			 * This process exits, so that the final child will inherit
 			 * init as parent to avoid zombies
 			 */
-			if (pid == -1)
+			if (pid == -1) {
+g_message("-- fork_and_print_environment: exit(1), %i", __LINE__);
 				exit (1);
+            }
 
 			/* We've done two forks. */
 			block_on_fd (wakeup_fds[0]);
 
 			/* The intermediate child exits */
+g_message("-- fork_and_print_environment: exit(0), %i", __LINE__);
 			exit (0);
 		}
+g_message("-- fork_and_print_environment: fork(), child 2, %i", __LINE__);
 
 	}
 
@@ -824,8 +849,11 @@
 static gboolean
 on_login_timeout (gpointer data)
 {
-	if (!initialization_completed)
+	if (!initialization_completed) {
+g_message("-- on_login_timeout: cleanup_and_exit(0), %i", __LINE__);
 		cleanup_and_exit (0);
+    }
 	return FALSE;
 }
 
@@ -864,8 +892,11 @@
 	g_clear_pointer (&resultv, g_variant_unref);
 
 	/* yes, the session is closing, so we'll quit now */
-	if (should_quit)
+	if (should_quit) {
+g_message("-- on_logind_session_property_get: cleanup_and_exit(0), %i", __LINE__);
 		cleanup_and_exit (0);
+    }
 }
 
 static void on_logind_session_properties_changed (GDBusConnection *connection,
@@ -1011,6 +1042,8 @@
 
 	GDBusConnection *connection = NULL;
 	GError *error = NULL;
+g_message("-- main: %i", __LINE__);
 
 	/*
 	 * Before we do ANYTHING, we drop privileges so we don't become
@@ -1087,6 +1120,8 @@
 				g_clear_pointer (&loop, g_main_loop_unref);
 				g_clear_object (&connection);
 			}
+g_message("-- main: cleanup_and_exit(0), %i", __LINE__);
 			cleanup_and_exit (0);
 		}
 
@@ -1171,5 +1206,7 @@
 	g_free (control_directory);
 
 	g_debug ("exiting cleanly");
+g_message("-- main: return 0, %i", __LINE__);
 	return 0;
 }

gnome-keyring.service:

--- gnome-keyring.service.orig	2022-05-02 08:49:48.684116620 +0300
+++ gnome-keyring.service	2022-05-02 08:08:37.797973752 +0300
@@ -4,6 +4,8 @@
 
 [Service]
 Type=oneshot
+# ExecStartPre=/usr/bin/sleep 5
 ExecStart=/usr/local/bin/gnome-keyring-daemon --start --components pkcs11,secrets
 
 [Install]

Xtigervnc-session:

exec /etc/X11/Xsession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment