Project

General

Profile

Bug #12057

Writing part of the string to stderr makes zlogin exit

Added by Alexander Pyhalov 12 months ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

Login to running zone with zlogin and run the following sample program:

#include <stdio.h>

int main()
{

  char *word=".";

  fputs(&word[1], stderr);
  fflush(stderr);

 return 0;
}       

Console session will be terminated with SIGHUP.

Reproducible on illumos-ad3e6d4dd8 (November 2019).


Related issues

Related to illumos gate - Bug #12286: Terminal gets SIGHUP in Global Zone after 'npm' command is runNew

Actions
Related to illumos gate - Bug #12306: XPG4v2 slave pty behaviour should generally be disabledClosedAndy Fiddaman

Actions
#1

Updated by Alexander Pyhalov 12 months ago

  • Description updated (diff)
#3

Updated by Andy Fiddaman 12 months ago

A bit of dtracing shows that zlogin is calling poll, and getting POLLRDNORM | POLLIN for the zone side stdout, but then getting 0 returned from a subsequent read() on the file descriptor which it handles as an EOF and closes the connection.

Changing zlogin.c:process_output() so that read() == 0 is not handled as an EOF makes zlogin stop exhibiting this problem.

What's strange is that this is happening on stdout and not stderr, yet the test program only triggers the problem when writing to stderr.

#4

Updated by Andy Fiddaman 12 months ago

The behaviour of zlogin changes depending on whether it is built with gcc7 or gcc 4.4.4:

gcc 7

% pwd
/data/omnios-build/omniosorg/bloody/illumos/usr/src/cmd/zlogin
% make
...

% pfexec ./zlogin test
[Connected to zone 'test' pts/2]
Last login: Wed Dec 11 13:45:06 2019 on pts/2
OmniOS 5.11     omnios-master-f3e2549426        December 2019
root@test:~# ./zcons
.root@test:~#
[Connection to zone 'test' pts/2 closed]

gcc 4.4.4

% PRIMARY_CC=gcc4,/opt/gcc-4.4.4/bin/gcc,gnu make
...

% pfexec ./zlogin test
[Connected to zone 'test' pts/2]
Last login: Wed Dec 11 13:44:34 2019 on pts/2
OmniOS 5.11     omnios-master-f3e2549426        December 2019
root@test:~# ./zcons
.root@test:~#
root@test:~# logout

[Connection to zone 'test' pts/2 closed]
#5

Updated by Andy Fiddaman 12 months ago

The problem here is not the compiler but rather that gcc7 is including values-xpg6.o in the link for C99 and above.

The problem was exposed by

commit d3b5f56344d8bfcdd6cfb82446af0e5e55ad9ebe
CommitDate: Fri Aug 16 01:57:38 2019 -0700

    11528 Makefile.noget can get gone
    11529 Use -Wno-maybe-initialized

because it changed zlogin to build with C99.

Building zlogin without the C99 flags produces a binary which does not exhibit this problem.

#6

Updated by Andy Fiddaman 12 months ago

Summary:

In August, a change (11529) that was cleaning up the use of -Wno-initialized in
various places changed the zlogin Makefile to use -std=gnu99 instead of
-std=gnu98. This caused the illumos version of gcc7 to link values-xpg6.o into
the final object which has a number of side-effects.

Most important for zlogin is that when read() on a terminal returns 0, it no
longer means EOF, just that no data is available.

#7

Updated by Electric Monk 11 months ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit 7b2eb3f3c068e560c7357b0f314172448bb8d1e0

commit  7b2eb3f3c068e560c7357b0f314172448bb8d1e0
Author: Andy Fiddaman <omnios@citrus-it.co.uk>
Date:   2019-12-19T11:28:29.000Z

    12057 Writing part of the string to stderr makes zlogin exit
    Reviewed by: John Levon <john.levon@joyent.com>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Reviewed by: Alexander Pyhalov <apyhalov@gmail.com>
    Approved by: Dan McDonald <danmcd@joyent.com>

#8

Updated by Gergő Mihály Doma 10 months ago

  • Related to Bug #12286: Terminal gets SIGHUP in Global Zone after 'npm' command is run added
#9

Updated by Andy Fiddaman 9 months ago

  • Related to Bug #12306: XPG4v2 slave pty behaviour should generally be disabled added

Also available in: Atom PDF