Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.8.3 - POSIX::ctermid() on Solaris #7067

Closed
p5pRT opened this issue Jan 26, 2004 · 10 comments
Closed

5.8.3 - POSIX::ctermid() on Solaris #7067

p5pRT opened this issue Jan 26, 2004 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 26, 2004

Migrated from rt.perl.org#25270 (status was 'resolved')

Searchable as RT25270$

@p5pRT
Copy link
Author

p5pRT commented Jan 26, 2004

From Peter.Dintelmann@dresdner-bank.com

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.34 running under perl v5.8.3.

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

  $ perl583 -MPOSIX -le 'print ctermid()'

  $

The expected output is "/dev/tty" which is produced by a simple C program.


Flags​:
  category=library
  severity=low


Site configuration information for perl v5.8.3​:

Configured by p013176 at Wed Jan 21 08​:51​:05 MET 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration​:
  Platform​:
  osname=solaris, osvers=2.8, archname=sun4-solaris-thread-multi
  uname='sunos oikbm03 5.8 generic_108528-23 sun4u sparc sunw,ultra-5_10 '
  config_args='-Dprefix=/opt/MISperl -Uinstallusrbinperl -Dcc=gcc -Doptimize=-O2 -Duseshrplib -Duseperlio -Dusethreads -des'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include'
  ccversion='', gccversion='2.95.3 20010315 (release)', gccosandvers='solaris2.8'
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='gcc', ldflags =' -L/usr/local/lib '
  libpth=/usr/local/lib /usr/lib /usr/ccs/lib
  libs=-lsocket -lnsl -lgdbm -ldl -lm -lpthread -lc
  perllibs=-lsocket -lnsl -ldl -lm -lpthread -lc
  libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-E -R /opt/MISperl/lib/5.8.3/sun4-solaris-thread-multi/CORE'
  cccdlflags='-fPIC', lddlflags=' -Wl,-E -G -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl v5.8.3​:
  /opt/MISperl/lib/5.8.3/sun4-solaris-thread-multi
  /opt/MISperl/lib/5.8.3
  /opt/MISperl/lib/site_perl/5.8.3/sun4-solaris-thread-multi
  /opt/MISperl/lib/site_perl/5.8.3
  /opt/MISperl/lib/site_perl
  .


Environment for perl v5.8.3​:
  HOME=/export/home/p013176
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH=/usr/local/ssl/lib​:/usr/local/lib
  LOGDIR (unset)
  PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin​:/opt/ssh/bin​:/usr/local/bin​:/usr/afs/bin​:/usr/afsws/bin
  PERL_BADLANG (unset)
  SHELL=/usr/local/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jan 29, 2004

From @doughera88

On Mon, 26 Jan 2004, Peter.Dintelmann@​Dresdner-Bank.Com wrote​:

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

$ perl583 \-MPOSIX \-le 'print ctermid\(\)'

$

The expected output is "/dev/tty" which is produced by a simple C program.

This is only a problem if you have threads enabled (which you do). I
think the problem is that the ctermid() interface is not threadsafe, so
Solaris uses the C preprocessor to replace the ctermid() call with
ctermid_r(). However, that re-entrant interface doesn't support calling
ctermid(NULL), which happens to be how POSIX.xs calls ctermid(). The end
result is the null result you see.

Here's the relevant excerpt from the man page for ctermid​:

  ctermid_r(s)
  The ctermid_r() function behaves as ctermid() except that if
  s is a null pointer, the function returns NULL. This func-
  tion is as proposed in the POSIX.4a Draft #6 document, and
  is subject to change to be compliant to the standard when it
  is accepted.

The solution is to re-work POSIX.xs so that it supplies a buffer of length
L_ctermid (defined in <stdio.h>) to ctermid_r(). If someone wants to make
this conditional, Configure already figures out whether or not the user
has ctermid_r(), but it should also be safe to always supply the buffer
ourselves.

--
  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jan 29, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2004

From @rgarcia

Peter.Dintelmann@​dresdner-bank.com (via RT) wrote​:

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.34 running under perl v5.8.3.

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

$ perl583 \-MPOSIX \-le 'print ctermid\(\)'

$ 

The expected output is "/dev/tty" which is produced by a simple C program.

I can't reproduce this on linux, both threaded and non-threaded.

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2004

From @doughera88

On Tue, 27 Jan 2004, Rafael Garcia-Suarez wrote​:

Peter.Dintelmann@​dresdner-bank.com (via RT) wrote​:

This is a bug report for perl from Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.34 running under perl v5.8.3.

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

$ perl583 \-MPOSIX \-le 'print ctermid\(\)'

$

The expected output is "/dev/tty" which is produced by a simple C program.

I can't reproduce this on linux, both threaded and non-threaded.

You may have missed it in the viral flood, but I have verified that this
is a real problem under threads on solaris. Here's what I wrote​:

This is only a problem if you have threads enabled (which you do). I
think the problem is that the ctermid() interface is not threadsafe, so
Solaris uses the C preprocessor to replace the ctermid() call with
ctermid_r(). However, that re-entrant interface doesn't support calling
ctermid(NULL), which happens to be how POSIX.xs calls ctermid(). The end
result is the null result you see.

Here's the relevant excerpt from the man page for ctermid​:

  ctermid_r(s)
  The ctermid_r() function behaves as ctermid() except that if
  s is a null pointer, the function returns NULL. This func-
  tion is as proposed in the POSIX.4a Draft #6 document, and
  is subject to change to be compliant to the standard when it
  is accepted.

The solution is to re-work POSIX.xs so that it supplies a buffer of length
L_ctermid (defined in <stdio.h>) to ctermid_r(). If someone wants to make
this conditional, Configure already figures out whether or not the user
has ctermid_r(), but it should also be safe to always supply the buffer
ourselves.

--
  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Feb 11, 2004

From Peter.Dintelmann@dresdner-bank.com

Summarizing, it seems that there is no problem on linux but
definitely on solaris. Andy has already done some research
on the solaris case (see below).

Can someone please write a patch for POSIX.xs?

  Peter

-----Original Message-----
From​: Andrew Dougherty [mailto​:doughera@​lafayette.edu]
Sent​: Montag, 2. Februar 2004 19​:14
To​: Rafael Garcia-Suarez
Cc​: perl5-porters@​perl.org
Subject​: Re​: [perl #25270] 5.8.3 - POSIX​::ctermid() on Solaris

On Tue, 27 Jan 2004, Rafael Garcia-Suarez wrote​:

Peter.Dintelmann@​dresdner-bank.com (via RT) wrote​:

This is a bug report for perl from
Peter.Dintelmann@​dresdner-bank.com,
generated with the help of perlbug 1.34 running under perl v5.8.3.

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

$ perl583 \-MPOSIX \-le 'print ctermid\(\)'

$

The expected output is "/dev/tty" which is produced by a
simple C program.

I can't reproduce this on linux, both threaded and non-threaded.

You may have missed it in the viral flood, but I have
verified that this
is a real problem under threads on solaris. Here's what I wrote​:

This is only a problem if you have threads enabled (which you do). I
think the problem is that the ctermid() interface is not
threadsafe, so
Solaris uses the C preprocessor to replace the ctermid() call with
ctermid_r(). However, that re-entrant interface doesn't
support calling
ctermid(NULL), which happens to be how POSIX.xs calls
ctermid(). The end
result is the null result you see.

Here's the relevant excerpt from the man page for ctermid​:

ctermid_r(s)
The ctermid_r() function behaves as ctermid() except that if
s is a null pointer, the function returns NULL. This func-
tion is as proposed in the POSIX.4a Draft #6 document, and
is subject to change to be compliant to the standard when it
is accepted.

The solution is to re-work POSIX.xs so that it supplies a
buffer of length
L_ctermid (defined in <stdio.h>) to ctermid_r(). If someone
wants to make
this conditional, Configure already figures out whether or
not the user
has ctermid_r(), but it should also be safe to always supply
the buffer
ourselves.

--
Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Feb 27, 2004

From @doughera88

On Tue, 27 Jan 2004, Andrew Dougherty wrote​:

On Mon, 26 Jan 2004, Peter.Dintelmann@​Dresdner-Bank.Com wrote​:

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

$ perl583 \-MPOSIX \-le 'print ctermid\(\)'

$

The expected output is "/dev/tty" which is produced by a simple C program.

This is only a problem if you have threads enabled (which you do). I
think the problem is that the ctermid() interface is not threadsafe, so
Solaris uses the C preprocessor to replace the ctermid() call with
ctermid_r(). However, that re-entrant interface doesn't support calling
ctermid(NULL), which happens to be how POSIX.xs calls ctermid(). The end
result is the null result you see.

Here's the relevant excerpt from the man page for ctermid​:

ctermid_r(s)
The ctermid_r() function behaves as ctermid() except that if
s is a null pointer, the function returns NULL. This func-
tion is as proposed in the POSIX.4a Draft #6 document, and
is subject to change to be compliant to the standard when it
is accepted.

The solution is to re-work POSIX.xs so that it supplies a buffer of length
L_ctermid (defined in <stdio.h>) to ctermid_r(). If someone wants to make
this conditional, Configure already figures out whether or not the user
has ctermid_r(), but it should also be safe to always supply the buffer
ourselves.

Here's a simple patch that leaks memory, but otherwise at least appears to
work on Solaris. I wouldn't apply it to the repository yet, however.

Does anyone know the proper way to do this so the memory gets freed at the
appropriate point in a threaded environment?

Inline Patch
--- perl-5.8.x/ext/POSIX/POSIX.xs	Thu Feb 26 17:56:56 2004
+++ perl-5.8.x-andy/ext/POSIX/POSIX.xs	Fri Feb 27 13:48:23 2004
@@ -1806,7 +1806,7 @@

 char *
 ctermid(s = 0)
-	char *		s = 0;
+	char *		s = safemalloc((size_t) L_ctermid);

 char *
 cuserid(s = 0)


-- 

  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

From @doughera88

On Mon, 26 Jan 2004, Peter.Dintelmann@​Dresdner-Bank.Com wrote​:

POSIX​::ctermid() does not seem to work in 5.8.3 on Solaris 8.

$ perl583 \-MPOSIX \-le 'print ctermid\(\)'

$

The expected output is "/dev/tty" which is produced by a simple C program.

The problem is that (under threads) POSIX.xs needed to allocate storage
for the ctermid_r() function that gets called by Solaris.

This patch (suggested by Tim Jenness under the perlxstut thread) does
that. It worked for me under Solaris 8/threads, and should be safe
to apply.

Inline Patch
diff -r -u perl-5.8.x/ext/POSIX/POSIX.xs perl-5.8.x-andy/ext/POSIX/POSIX.xs
--- perl-5.8.x/ext/POSIX/POSIX.xs	Thu Feb 26 17:56:56 2004
+++ perl-5.8.x-andy/ext/POSIX/POSIX.xs	Thu Mar  4 12:39:22 2004
@@ -1806,7 +1806,9 @@

 char *
 ctermid(s = 0)
-	char *		s = 0;
+	char *          s = safemalloc((size_t) L_ctermid);
+    CLEANUP:
+	Safefree(s);

 char *
 cuserid(s = 0)

-- 

  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

From @rgs

Andrew Dougherty wrote​:

The problem is that (under threads) POSIX.xs needed to allocate storage
for the ctermid_r() function that gets called by Solaris.

This patch (suggested by Tim Jenness under the perlxstut thread) does
that. It worked for me under Solaris 8/threads, and should be safe
to apply.

which is done now, thanks, as change #22436.

diff -r -u perl-5.8.x/ext/POSIX/POSIX.xs perl-5.8.x-andy/ext/POSIX/POSIX.xs
--- perl-5.8.x/ext/POSIX/POSIX.xs Thu Feb 26 17​:56​:56 2004

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant