]> git.pld-linux.org Git - packages/util-linux.git/blame - util-linux-ctty3.patch
- files shuffling to avoid confusion later
[packages/util-linux.git] / util-linux-ctty3.patch
CommitLineData
5545a732
JR
1The login program (which allows users to gain access to the system) does
2not handle signals correctly, causing some programs to stay running after
3the user has logged out.
4
5--- util-linux-2.13-pre1/login-utils/login.c.ctty3 2005-08-02 18:10:24.000000000 +0200
6+++ util-linux-2.13-pre1/login-utils/login.c 2005-08-15 15:51:35.000000000 +0200
7@@ -285,7 +285,21 @@
8 updwtmp(_PATH_BTMP, &ut);
9 #endif
10 }
11-#endif /* HAVE_SECURITY_PAM_MISC_H */
12+
13+static int childPid = 0;
14+static volatile int got_sig = 0;
15+
16+static void
17+parent_sig_handler(int signal)
18+{
19+ if(childPid)
20+ kill(-childPid, signal);
21+ else
22+ got_sig = 1;
23+ if(signal == SIGTERM)
24+ kill(-childPid, SIGHUP); /* because the shell often ignores SIGTERM */
25+}
26+#endif /* HAVE_SECURITY_PAM_MISC_H */
27
28 int
29 main(int argc, char **argv)
30@@ -307,7 +321,7 @@
31 int retcode;
32 pam_handle_t *pamh = NULL;
33 struct pam_conv conv = { misc_conv, NULL };
34- pid_t childPid;
35+ struct sigaction sa, oldsa_hup, oldsa_term;
36 #else
37 char *salt, *pp;
38 #endif
39@@ -1023,7 +1037,18 @@
40 * We must fork before setuid() because we need to call
41 * pam_close_session() as root.
42 */
43+ memset(&sa, 0, sizeof(sa));
44+ sa.sa_handler = SIG_IGN;
45+ sigaction(SIGINT, &sa, NULL);
46+
47+ sigaction(SIGHUP, &sa, &oldsa_hup); /* ignore while we detach from the tty */
48+ ioctl(0, TIOCNOTTY, NULL);
49+
50+ sa.sa_handler = parent_sig_handler;
51+ sigaction(SIGHUP, &sa, NULL);
52+ sigaction(SIGTERM, &sa, &oldsa_term);
53
54+ closelog();
55 childPid = fork();
56 if (childPid < 0) {
57 int errsv = errno;
58@@ -1034,19 +1059,20 @@
59 }
60
61 if (childPid) {
62- /* parent - wait for child to finish, then cleanup session */
63- signal(SIGHUP, SIG_IGN);
64- signal(SIGINT, SIG_IGN);
65- signal(SIGQUIT, SIG_IGN);
66- signal(SIGTSTP, SIG_IGN);
67- signal(SIGTTIN, SIG_IGN);
68- signal(SIGTTOU, SIG_IGN);
69-
70- wait(NULL);
71+ close(0); close(1); close(2);
72+ sa.sa_handler = SIG_IGN;
73+ sigaction(SIGQUIT, &sa, NULL);
74+ sigaction(SIGINT, &sa, NULL);
75+ while(wait(NULL) == -1 && errno == EINTR) /**/ ;
76+ openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
77 PAM_END;
78 exit(0);
79 }
80
81+ sigaction(SIGHUP, &oldsa_hup, NULL);
82+ sigaction(SIGTERM, &oldsa_term, NULL);
83+ if(got_sig) exit(1);
84+
85 /* child */
86 /*
87 * Problem: if the user's shell is a shell like ash that doesnt do
88@@ -1058,14 +1084,15 @@
89 setsid();
90
91 /* make sure we have a controlling tty */
92- opentty(ttyn);
93 openlog("login", LOG_ODELAY, LOG_AUTHPRIV); /* reopen */
94
95 /*
96 * TIOCSCTTY: steal tty from other process group.
97 */
98- if (ioctl(0, TIOCSCTTY, 1))
99- syslog(LOG_ERR, _("TIOCSCTTY failed: %m"));
100+ if (ioctl(0, TIOCSCTTY, (char *)1)) {
101+ syslog(LOG_ERR, _("Couldn't set controlling terminal: %s"), strerror(errno));
102+ exit(1);
103+ }
104 #endif
105 signal(SIGINT, SIG_DFL);
106
This page took 0.057776 seconds and 4 git commands to generate.