blob: 2b598bc3c6f5d23991e38dbcbbb0ac9011b4a63a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
From d4399c664ec1f1c9fc2c2e19a3db1e0948d37859 Mon Sep 17 00:00:00 2001
From: Alexandru Ardelean <alex@shruggie.ro>
Date: Wed, 20 Aug 2026 09:00:00 +0300
Subject: [PATCH] su: tolerate the absence of a controlling terminal
su drops the controlling terminal when running a command, treating a
missing one (ENXIO from open) as success. On musl, open("/dev/tty")
can fail with EACCES instead, or TIOCNOTTY can fail with ENOTTY;
handle both so "su <user> -c <cmd>" works without a controlling
terminal (init scripts, service supervisors). OpenWrt issue #1521.
Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>
---
--- a/src/su.c
+++ b/src/su.c
@@ -1165,8 +1165,12 @@ int main (int argc, char **argv)
if (fd >= 0) {
err = ioctl (fd, TIOCNOTTY, (char *) NULL);
+ if (-1 == err && ENOTTY == errno) {
+ /* There are no controlling terminal already */
+ err = 0;
+ }
(void) close (fd);
- } else if (ENXIO == errno) {
+ } else if (ENXIO == errno || EACCES == errno) {
/* There are no controlling terminal already */
err = 0;
}
|