zsh-workers
 help / color / mirror / code / Atom feed
* Re: [Cooker] /bin/login from util-linux-2.11c-2mdk  breaks zsh ctty hadling
       [not found] ` <m3n183su14.fsf@giants.mandrakesoft.com>
@ 2001-05-27 14:07   ` Andrej Borsenkow
  2001-06-06 17:12     ` Chmouel Boudjnah
  0 siblings, 1 reply; 4+ messages in thread
From: Andrej Borsenkow @ 2001-05-27 14:07 UTC (permalink / raw)
  To: cooker, ZSH Workers Mailing List

Chmouel Boudjnah wrote:

 > Andrej Borsenkow <Andrej.Borsenkow@mow.siemens.ru> writes:
 >
 >
 >>After I upgraded to the latest util-linux all login zsh's are running
 >>without controlling tty. bash seems to run normally (attached to
 >>tty). consoletype fails with EPERM that results in returning "serial"
 >>instead "vt" and russian charset not activated. I had to copy
 >>/bin/login from Mdk8 to be able to work.
 >>
 >>It is also 2.4.4-3mdk kernel
 >>
 >>Chmoul?
 >>
 >
 > ????? really couldn't reproduce the problem, here...
 >
 >

O.K., I have found why it happens. Here goes.

Here is what happens around a fork in /bin/login for a "good" login
(1188 is login process):

1188  fork()                            = 1200
1188  wait4(-1,  <unfinished ...>
1200  rt_sigaction(SIGINT, {SIG_DFL}, {SIG_IGN}, 8) = 0
1200  msgget(501, 0x2|02)               = 0
1200  chdir("/home/bor")                = 0
1200  execve("/bin/zsh", ["-zsh"], [/* 6 vars */]) = 0

Here is what happens at the same place for a "bad" login (1175 is
login). I marked offending call:

1175  fork()                            = 1178
1175  ioctl(0, TIOCNOTTY)               = 0
1175  --- SIGHUP (Hangup) ---
1175  --- SIGCONT (Continued) ---
1175  rt_sigaction(SIGHUP, {SIG_DFL}, {SIG_IGN}, 8) = 0
1175  wait4(-1,  <unfinished ...>
1178  --- SIGCONT (Continued) ---
  >>> 1178  setsid()                           = 1178
1178  rt_sigaction(SIGHUP, {SIG_DFL}, {SIG_IGN}, 8) = 0
1178  rt_sigaction(SIGINT, {SIG_DFL}, {SIG_IGN}, 8) = 0
1178  msgget(501, 0x2|02)               = 0
1178  chdir("/home/bor")                = 0
1178  execve("/bin/zsh", ["-zsh"], [/* 6 vars */]) = 0


As you see, new login now does setsid(). Unfortunately, this call has a
side effect of resetting process' ctty, so anything exec'ed next runs
without controlling tty.

The reason bash still works is that it checks if /dev/tty is available,
and if not it reopens it:

2916  open("/dev/tty", O_RDWR|O_NONBLOCK|O_LARGEFILE) = -1 ENXIO (No
such device or address)
2916  ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
2916  brk(0)                            = 0x80c008c
2916  brk(0x80c1000)                    = 0x80c1000
2916  brk(0x80c3000)                    = 0x80c3000
2916  readlink("/proc/self/fd/0", "/dev/tty3", 4095) = 9
2916  open("/dev/tty3", O_RDWR|O_NONBLOCK|O_LARGEFILE) = 3
2916  close(3)                          = 0

the last two open/close pair makes current stdin to controlling tty. Zsh
does not do it - it inherits std{in,out,err} and opens its SHIN with
O_NOCTTY.

I still claim it is a /bin/login bug. It should make sure porgram is
exec'ed with correct environment that includes ctty.

-andrej

P.S. The problem is not limited to zsh - any program that expects
/dev/tty fails.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cooker] /bin/login from util-linux-2.11c-2mdk  breaks zsh ctty hadling
  2001-05-27 14:07   ` [Cooker] /bin/login from util-linux-2.11c-2mdk breaks zsh ctty hadling Andrej Borsenkow
@ 2001-06-06 17:12     ` Chmouel Boudjnah
  2001-06-06 20:48       ` Andrej Borsenkow
  0 siblings, 1 reply; 4+ messages in thread
From: Chmouel Boudjnah @ 2001-06-06 17:12 UTC (permalink / raw)
  To: Andrej.Borsenkow; +Cc: cooker, ZSH Workers Mailing List

Andrej Borsenkow <arvidjaar@mail.ru> writes:

> O.K., I have found why it happens. Here goes.

ok fixed in latest util-linux of cooker..


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cooker] /bin/login from util-linux-2.11c-2mdk  breaks zsh ctty hadling
  2001-06-06 17:12     ` Chmouel Boudjnah
@ 2001-06-06 20:48       ` Andrej Borsenkow
  2001-06-08 19:16         ` Chmouel Boudjnah
  0 siblings, 1 reply; 4+ messages in thread
From: Andrej Borsenkow @ 2001-06-06 20:48 UTC (permalink / raw)
  To: Chmouel Boudjnah; +Cc: cooker, ZSH Workers Mailing List

Chmouel Boudjnah wrote:

 > Andrej Borsenkow <arvidjaar@mail.ru> writes:
 >
 >
 >>O.K., I have found why it happens. Here goes.
 >>
 >
 > ok fixed in latest util-linux of cooker..
 >
 >

No, sorry. It now tries to open /dev/tty but in wrong place - in parent,
not in child.

(ttypts/2)% rpm -q util-linux
util-linux-2.11d-1mdk
1166  read(0, "b", 1)                   = 1
1166  read(0, "o", 1)                   = 1
1166  read(0, "r", 1)                   = 1
1166  read(0, "\n", 1)                  = 1
1166  execve("/bin/login", ["/bin/login", "--", "bor"], [/* 8 vars */]) = 0
...
1166  setsid()                          = -1 EPERM (Operation not permitted)
1166  open("/dev/tty3", O_RDWR|O_NONBLOCK|O_LARGEFILE) = 3
        ^^^^^^^^^^^^^^^^ useless here because ...
...
1166  fork()                            = 2397
2397  setsid()                          = 2397
        ^^^^^^^^ ... Oops!
2397  rt_sigaction(SIGHUP, {SIG_DFL}, {SIG_IGN}, 8) = 0
2397  rt_sigaction(SIGINT, {SIG_DFL}, {SIG_IGN}, 8) = 0
2397  msgget(501, 0x2|02)               = 0
2397  chdir("/home/bor")                = 0
2397  execve("/bin/zsh", ["-zsh"], [/* 6 vars */]) = 0


The same applies - setsid() in child resets ctty.

-andrej



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cooker] /bin/login from util-linux-2.11c-2mdk  breaks zsh ctty hadling
  2001-06-06 20:48       ` Andrej Borsenkow
@ 2001-06-08 19:16         ` Chmouel Boudjnah
  0 siblings, 0 replies; 4+ messages in thread
From: Chmouel Boudjnah @ 2001-06-08 19:16 UTC (permalink / raw)
  To: Andrej.Borsenkow; +Cc: cooker, ZSH Workers Mailing List

Andrej Borsenkow <arvidjaar@mail.ru> writes:

> Chmouel Boudjnah wrote:
> 
>  > Andrej Borsenkow <arvidjaar@mail.ru> writes:
>  >
>  >
>  >>O.K., I have found why it happens. Here goes.
>  >>
>  >
>  > ok fixed in latest util-linux of cooker..
>  >
>  >
> 
> No, sorry. It now tries to open /dev/tty but in wrong place - in parent,
> not in child.

ok i understand now, the setsid is definitvely broken (for ash shell
:-(), i'll revert the changes here, can you try this[1] :

--- util-linux-2.11e/login-utils/login.c.chmou  Thu Jun  7 20:49:09 2001
+++ util-linux-2.11e/login-utils/login.c        Fri Jun  8 21:14:03 2001
@@ -1071,15 +1071,8 @@
      * We must fork before setuid() because we need to call
      * pam_close_session() as root.
      */
-    /*
-     * Problem: if the user's shell is a shell like ash that doesnt do
-     * setsid() or setpgrp(), then a ctrl-\, sending SIGQUIT to every
-     * process in the pgrp, will kill us.
-     * Solution: use TIOCNOTTY and setsid().
-     */
     signal(SIGINT, SIG_IGN);
-    signal(SIGHUP, SIG_IGN);   /* ignore signal from TIOCNOTTY below */
-    
+
     childPid = fork();
     if (childPid < 0) {
        int errsv = errno;
@@ -1088,18 +1081,11 @@
        PAM_END;
        exit(0);
     } else if (childPid) {
-       /* parent - wait for child to finish, then cleanup session */
-       ioctl(0, TIOCNOTTY, NULL);
-       signal(SIGHUP, SIG_DFL);
-
        wait(NULL);
        PAM_END;
        exit(0);
     }
     /* child */
-    setsid();
-    /* reopen, as we need controlling tty in the child */
-    opentty(ttyn);
 #endif
     signal(SIGHUP, SIG_DFL);
     signal(SIGINT, SIG_DFL);


Footnotes: 
[1]  or get the file https://qa.mandrakesoft.com/~chmou/misc/login


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-06-08 19:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <3B0BF59E.6030408@mow.siemens.ru>
     [not found] ` <m3n183su14.fsf@giants.mandrakesoft.com>
2001-05-27 14:07   ` [Cooker] /bin/login from util-linux-2.11c-2mdk breaks zsh ctty hadling Andrej Borsenkow
2001-06-06 17:12     ` Chmouel Boudjnah
2001-06-06 20:48       ` Andrej Borsenkow
2001-06-08 19:16         ` Chmouel Boudjnah

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).