summaryrefslogtreecommitdiffstats
path: root/x11/kdebase4-runtime/files/patch-TEPty.C
blob: 9bfd5db25ccd002551a03a0dec1cec7dff843a8d (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--- konsole/src/TEPty.C.orig	Fri Dec  8 11:51:24 2000
+++ konsole/src/TEPty.C	Fri Dec  8 11:52:51 2000
@@ -180,27 +180,57 @@
 // param grant: 1 to grant, 0 to revoke
 // returns 1 on success 0 on fail
 {
-  pid_t pid = fork();
-  if (pid < 0)
-  {
-    return 0;
-  }
-  if (pid == 0)
-  {
-    /* We pass the master pseudo terminal as file descriptor PTY_FILENO. */
-    if (fd != PTY_FILENO && dup2(fd, PTY_FILENO) < 0) exit(1);
-    QString path = locate("exe", BASE_CHOWN);
+  pid_t pid;
+  int pstat;
+  struct sigaction ign;
+  struct sigaction intact;	// interupt action
+  struct sigaction quitact;	// quit action
+  sigset_t newsigblock, oldsigblock;
+	QString path;
+
+  ign.sa_handler = SIG_IGN;
+  sigemptyset(&ign.sa_mask);
+  ign.sa_flags = 0;
+  sigaction(SIGINT, &ign, &intact);
+  sigaction(SIGQUIT, &ign, &quitact);
+  sigemptyset(&newsigblock);
+  sigaddset(&newsigblock, SIGCHLD);
+  sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
+
+  switch (pid = fork()) {
+  case -1:
+    return(0);
+		break;
+  case 0:			// child
+    if (fd != PTY_FILENO && dup2(fd, PTY_FILENO) < 0)
+      exit(1);
+    path = locate("exe", BASE_CHOWN);
+
+    sigaction(SIGINT, &intact, NULL);
+    sigaction(SIGQUIT, &quitact, NULL);
+    sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
     execle(path.ascii(), BASE_CHOWN, grant?"--grant":"--revoke", NULL, NULL);
-    exit(1); // should not be reached
-  }
-  if (pid > 0)
-  { int w;
-  retry:
-    int rc = waitpid (pid, &w, 0);
-    if ((rc == -1) && (errno == EINTR))
-      goto retry;
-    return (rc != -1 && WIFEXITED(w) && WEXITSTATUS(w) == 0);
+    exit(1);
+		break;
+  default:
+    do {
+      pid = waitpid(pid, &pstat, 0);
+    } while (pid == -1 && errno == EINTR);
+    break;
   }
+  sigaction(SIGINT, &intact, NULL);
+  sigaction(SIGQUIT, &quitact, NULL);
+  sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
+
+  if (pid == -1) {
+    return 0;
+	}
+  else if (WIFEXITED(pstat) && (WEXITSTATUS(pstat) == 0)) {
+    return 1;
+	}
+  else {
+    return 0;
+	}
   return 0; //dummy.
 }
 
@@ -225,7 +255,7 @@
 #ifdef HAVE_UTEMPTER
   removeLineFromUtmp(ttynam, fd);
 #elif defined(USE_LOGIN)
-  char *tty_name=ttyname(0);
+  char *tty_name=ttyname(fd);
   if (tty_name)
   {
   	if (strncmp(tty_name, "/dev/", 5) == 0)
OpenPOWER on IntegriCloud