Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.93k stars 552 forks source link

On AIX, kill(0, $pid) always returns false if process is owned by another user #8301

Closed p5pRT closed 18 years ago

p5pRT commented 18 years ago

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

Searchable as RT38374$

p5pRT commented 18 years ago

From gordoste@iinet.net.au

This is a bug report for perl from gordoste@​iinet.net.au\, generated with the help of perlbug 1.26 running under perl 5.00503.


If a process with PID $pid is running under another user\, then kill(0\, $pid) always returns false. This was discovered on AIX 4.3.3.



Site configuration information for perl 5.00503​:

Configured by root at Wed Aug 11 15​:58​:01 CDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:   Platform​:   osname=aix\, osvers=4.3.3.0\, archname=aix   uname='aix funny 3 4 000001716600 '   hint=recommended\, useposix=true\, d_sigaction=define   usethreads=undef useperlio=undef d_sfio=undef   Compiler​:   cc='cc'\, optimize='-O'\, gccversion=   cppflags='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384'   ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384'   stdchar='unsigned char'\, d_stdstdio=define\, usevfork=false   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8   d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=8   alignbytes=8\, usemymalloc=n\, prototype=define   Linker and Libraries​:   ld='ld'\, ldflags ='-s'   libpth=/lib /usr/lib /usr/ccs/lib   libs=-lnsl -ldbm -ldl -lld -lm -lc -lcrypt -lbsd -lPW -lC_r   libc=/lib/libc.a\, so=a\, useshrplib=false\, libperl=libperl.a   Dynamic Linking​:   dlsrc=dl_aix.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-bE​:perl.exp'   cccdlflags=' '\, lddlflags='-bhalt​:4 -bM​:SRE -bI​:$(PERL_INC)/perl.exp -bE​:$(BASEEXT).exp -b noentry -lc'

Locally applied patches​:  


@​INC for perl 5.00503​:   /opt/apps/ami/devl/lib/perl   /usr/opt/perl5/lib/5.00503/aix   /usr/opt/perl5/lib/5.00503   /usr/opt/perl5/lib/site_perl/5.005/aix   /usr/opt/perl5/lib/site_perl/5.005   .


Environment for perl 5.00503​:   HOME=/home/mqm   LANG=en_US   LANGUAGE (unset)   LC__FASTMSG=true   LD_LIBRARY_PATH=/u01/app/oracle/product/v817/lib   LOGDIR (unset)  
PATH=/usr/bin​:/etc​:/usr/sbin​:/usr/ucb​:/usr/lib​:/bin​:/usr/bin/X11​:/sbin​:/usr/local/bin​:/usr/local/menu​:/mfgpro/mfg74fmod/bin​:/usr/dc/bin​:/progress/dlc83b/bin​:/progress/opl32/bin​:/progress/opl32/lib​:/var/ifor​:/usr/opt/ifor/ls/conf​:/opt/apps/sysinfo/bin​:/opt/bin​:/u01/app/oracle/product/v817/bin​:/home/mqm/bin   PERL5LIB=/opt/apps/ami/devl/lib/perl   PERL_BADLANG (unset)   SHELL=/usr/bin/sh

p5pRT commented 18 years ago

From @nwc10

On Mon\, Jan 30\, 2006 at 09​:32​:36PM -0800\, gordoste @​ iinet. net. au wrote​:

If a process with PID $pid is running under another user\, then kill(0\, $pid) always returns false. This was discovered on AIX 4.3.3.

I believe that that's the expected behaviour of kill. I don't have access to AIX\, but the FreeBSD man page has​:

  For a process to have permission to send a signal to a process designated   by pid\, the real or effective user ID of the receiving process must match   that of the sending process or the user must have appropriate privileges   (such as given by a set-user-ID program or the user is the super-user).   A single exception is the signal SIGCONT\, which may always be sent to any   process with the same session ID as the caller.

and then in the list of error codes it includes​:

  [ESRCH] No process can be found corresponding to that speci-   fied by pid.

  [EPERM] The sending process is not the super-user and its   effective user id does not match the effective user-id   of the receiving process. When signaling a process   group\, this error is returned if any members of the   group could not be signaled.

So if your goal is to validate that a process ID exists\, whoever the owner is\, I suspect that you can get the answer if you also check $!

Nicholas Clark

p5pRT commented 18 years ago

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

p5pRT commented 18 years ago

From guest@guest.guest.xxxxxxxx

Thanks Nicholas\, this is indeed the case. It may be worth mentioning this in the documentation\, which currently says​:

If SIGNAL is zero\, no signal is sent to the process. This is a useful way to check that the process is alive and hasn't changed its UID. See perlport for notes on the portability of this construct.

Perhaps we could modify it to this​:

If SIGNAL is zero\, no signal is sent to the process. This is a useful way to check that a process is alive. (If kill returns zero\, check whether $! equals EPERM to determine whether the process is alive but owned by another user). See perlport for notes on the portability of this construct.

What do you think?

p5pRT commented 18 years ago

From @rgs

I applied the following doc patch to the current development sources :

http​://public.activestate.com/cgi-bin/perlbrowse?patch=27039

p5pRT commented 18 years ago

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

p5pRT commented 18 years ago

From gordoste@iinet.net.au

There is a small mistake​:

... the kill(2) system call will check whether it's possible so send a signal to it ...

should be

... the kill(2) system call will check whether it's possible to send a signal to it ...

Also\, I still think that since most of the time the kill(0\, $pid) construct would be used to check if a process is running\, the document should explicitly mention that you need to check $! to see if it is running as another user.

Strictly speaking\, kill(0\, $pid) returning true doesn't necessarily mean the process hasn't changed its UID\, since it may have changed its UID to the UID of the current process.

And I think the portion in parentheses is redundant since that information is already in the docs (I just didn't read them thoroughly enough).

Keeping all this in mind\, I would suggest the following​:

If SIGNAL is zero\, no signal is sent to the process\, but the kill(2) system call will check whether it's possible to send a signal to it. This is a useful way to check that a child process is alive and has the same UID as the current process ($! will be set to EPERM if the process is alive and has a different UID to the current process). See L\ for notes on the portability of this construct.

Hope this helps\,

Stephen Gordon

Rafael Garcia-Suarez via RT wrote​:

According to our records\, your request regarding "On AIX\, kill(0\, $pid) always returns false if process is owned by another user" has been resolved.

If you have any further questions or concerns\, please respond to this message.

For other topics\, please create a new ticket.

Please don't feel obligated to say "Thanks" or "Kudos" or "I owe you a beer" -- if you respond to this message it will reopen the ticket. If you must\, please send email directly to the person who handled your ticket\, and not to the tracking system.

\<URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=38374 >

p5pRT commented 18 years ago

From @smpeters

On Thu\, Feb 02\, 2006 at 07​:51​:34AM +1100\, Stephen Gordon wrote​:

There is a small mistake​:

... the kill(2) system call will check whether it's possible so send a signal to it ...

should be

... the kill(2) system call will check whether it's possible to send a signal to it ...

This has been included as change #27047.

And I think the portion in parentheses is redundant since that information is already in the docs (I just didn't read them thoroughly enough).

This part was added mainly due to the information being available in the kill(2) manpage\, but not available in Perl.

Steve Peters steve@​fisharerojo.org