All of lore.kernel.org
 help / color / mirror / Atom feed
From: benjamin@sipsolutions.net
To: linux-um@lists.infradead.org
Cc: Benjamin Berg <benjamin@sipsolutions.net>
Subject: [PATCH v3 06/11] um: Reap winch thread if it fails
Date: Fri, 10 Nov 2023 12:03:43 +0100	[thread overview]
Message-ID: <20231110110348.1815612-7-benjamin@sipsolutions.net> (raw)
In-Reply-To: <20231110110348.1815612-1-benjamin@sipsolutions.net>

From: Benjamin Berg <benjamin@sipsolutions.net>

When the winch thread runs into an error condition, it would exit(1) and
never be reaped until shutdown time. Change this to write a command byte
which causes the driver to kill it, therefore reaping the child.

Signed-off-by: Benjamin Berg <benjamin@sipsolutions.net>
---
 arch/um/drivers/chan_user.c | 16 +++++++++++-----
 arch/um/drivers/line.c      | 13 ++++++++-----
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index c2b83cb99aae..ed7cc830b3e7 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -141,7 +141,7 @@ struct winch_data {
 	int pipe_fd;
 };
 
-static int winch_thread(void *arg)
+static __noreturn int winch_thread(void *arg)
 {
 	struct winch_data *data = arg;
 	sigset_t sigs;
@@ -168,7 +168,7 @@ static int winch_thread(void *arg)
 	if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) {
 		os_info("winch_thread : sigprocmask failed, errno = %d\n",
 			errno);
-		exit(1);
+		goto wait_kill;
 	}
 	/* In sigsuspend(), block anything else than SIGWINCH. */
 	sigdelset(&sigs, SIGWINCH);
@@ -176,19 +176,19 @@ static int winch_thread(void *arg)
 	if (setsid() < 0) {
 		os_info("winch_thread : setsid failed, errno = %d\n",
 		       errno);
-		exit(1);
+		goto wait_kill;
 	}
 
 	if (ioctl(pty_fd, TIOCSCTTY, 0) < 0) {
 		os_info("winch_thread : TIOCSCTTY failed on "
 			"fd %d err = %d\n", pty_fd, errno);
-		exit(1);
+		goto wait_kill;
 	}
 
 	if (tcsetpgrp(pty_fd, os_getpid()) < 0) {
 		os_info("winch_thread : tcsetpgrp failed on fd %d err = %d\n",
 			pty_fd, errno);
-		exit(1);
+		goto wait_kill;
 	}
 
 	/*
@@ -214,6 +214,12 @@ static int winch_thread(void *arg)
 			os_info("winch_thread : write failed, err = %d\n",
 				errno);
 	}
+
+wait_kill:
+	c = 2;
+	count = write(pipe_fd, &c, sizeof(c));
+	while (1)
+		pause();
 }
 
 static int winch_tramp(int fd, struct tty_port *port, int *fd_out,
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index b98545f3edb5..449d320c3f55 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -629,15 +629,18 @@ static irqreturn_t winch_interrupt(int irq, void *data)
 
 	if (fd != -1) {
 		err = generic_read(fd, &c, NULL);
-		if (err < 0) {
+		/* A read of 2 means the winch thread failed and has warned */
+		if (err < 0 || (err == 1 && c == 2)) {
 			if (err != -EAGAIN) {
 				winch->fd = -1;
 				list_del(&winch->list);
 				os_close_file(fd);
-				printk(KERN_ERR "winch_interrupt : "
-				       "read failed, errno = %d\n", -err);
-				printk(KERN_ERR "fd %d is losing SIGWINCH "
-				       "support\n", winch->tty_fd);
+				if (err < 0) {
+					printk(KERN_ERR "winch_interrupt : read failed, errno = %d\n",
+					       -err);
+					printk(KERN_ERR "fd %d is losing SIGWINCH support\n",
+					       winch->tty_fd);
+				}
 				INIT_WORK(&winch->work, __free_winch);
 				schedule_work(&winch->work);
 				return IRQ_HANDLED;
-- 
2.41.0


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

  parent reply	other threads:[~2023-11-10 11:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 11:03 [PATCH v3 00/11] General cleanups and fixes from SECCOMP patchset benjamin
2023-11-10 11:03 ` [PATCH v3 01/11] um: Drop support for hosts without SYSEMU_SINGLESTEP support benjamin
2023-11-10 11:03 ` [PATCH v3 02/11] um: Drop NULL check from start_userspace benjamin
2023-11-10 11:03 ` [PATCH v3 03/11] um: Make errors to stop ptraced child fatal during startup benjamin
2023-11-10 11:03 ` [PATCH v3 04/11] um: Don't use vfprintf() for os_info() benjamin
2024-01-04 22:37   ` Richard Weinberger
2024-01-05  8:12     ` Benjamin Berg
2024-01-05  8:56       ` Johannes Berg
2024-01-05  9:16         ` Richard Weinberger
2023-11-10 11:03 ` [PATCH v3 05/11] um: Do not use printk in SIGWINCH helper thread benjamin
2023-11-10 11:03 ` benjamin [this message]
2023-11-10 11:03 ` [PATCH v3 07/11] um: Do not use printk in userspace trampoline benjamin
2023-11-10 11:03 ` [PATCH v3 08/11] um: Always inline stub functions benjamin
2023-11-10 11:03 ` [PATCH v3 09/11] um: Rely on PTRACE_SETREGSET to set FS/GS base registers benjamin
2024-01-04 23:05   ` Richard Weinberger
2024-01-04 23:34     ` Richard Weinberger
2024-01-05  9:54     ` Benjamin Berg
2024-01-05 13:29       ` Richard Weinberger
2023-11-10 11:03 ` [PATCH v3 10/11] um: Remove unused register save/restore functions benjamin
2023-11-10 11:03 ` [PATCH v3 11/11] um: Mark 32bit syscall helpers as clobbering memory benjamin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231110110348.1815612-7-benjamin@sipsolutions.net \
    --to=benjamin@sipsolutions.net \
    --cc=linux-um@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.