[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] Fix locking in tools/hotplug/Linux/locking.sh



On Tue, Nov 13, 2012 at 11:08:29AM +0000, Ian Campbell wrote:
> On Mon, 2012-11-12 at 18:40 +0000, Olaf Hering wrote:
> > On Mon, Nov 12, Jacek Konieczny wrote:
> > 
> > > # perl --version
> > > This is perl, v5.8.8 built for x86_64-pld-linux-thread-multi
> > 
> > sles11sp2 has perl 5.10.0, maybe there is different behaviour in
> > different perl versions.
> 
> More likely to be the kernel, since Perl would have to jump through
> hoops to figure out if a random fd which it got passed was r/o or r/w, I
> think.

I suspected my perl just checks the file descriptor which is to be
opened for reading, and it seems to be the case.

âhowever, after looking into Perl source code it seems it might be
glibc and its fdopen() implementation, as Perl calls fdopen() (unless
'sfio' is used instead of 'stdio').

And from the fdopen(3) manual:

> The  mode  of the stream (one of the values "r", "r+", "w", "w+",
> "a", "a+") must be compatible with  the  mode of the file  descriptor.

# rpm -q glibc
glibc-2.15-10.aos1.x86_64

> Perhaps its a security thing (e.g. selinux or something like that)
> enforcing something extra?

Nothing like that here.

> 
> Might be interesting to run things under strace ? 

Here you are, (notice the fcntl(3, F_GETFL) call before the error):

+ _lockfd=42
+ _lockfile=/tmp/lockfile
+ eval 'exec 42>>/tmp/lockfile'
++ exec
+ flock -x 42
++ strace perl -e '
            open STDIN, "<&42" or die $!;
            my $fd_inum = (stat STDIN)[1]; die $! unless defined $fd_inum;
            my $file_inum = (stat $ARGV[0])[1];
            print "y\n" if $fd_inum eq $file_inum;
                             ' /tmp/lockfile
execve("/usr/bin/perl", ["perl", "-e", "\n            open STDIN, \"<&42\" 
"..., "/tmp/lockfile"], [/* 28 vars */]) = 0
brk(0)                                  = 0x1c01000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae6c000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/tls/x86_64/libperl.so.5.8.0",
 O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/tls/x86_64", 
0x7fff5242d820) = -1 ENOENT (No such file or directory)
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/tls/libperl.so.5.8.0",
 O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/tls", 
0x7fff5242d820) = -1 ENOENT (No such file or directory)
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/x86_64/libperl.so.5.8.0",
 O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/x86_64", 
0x7fff5242d820) = -1 ENOENT (No such file or directory)
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/libperl.so.5.8.0",
 O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@Y\3\0\0\0\0\0"..., 832) 
= 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1425032, ...}) = 0
mmap(NULL, 3528768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f217a8ee000
mprotect(0x7f217aa40000, 2093056, PROT_NONE) = 0
mmap(0x7f217ac3f000, 45056, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x151000) = 0x7f217ac3f000
mmap(0x7f217ac4a000, 6208, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f217ac4a000
close(3)                                = 0
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/libdl.so.2", 
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=24104, ...}) = 0
mmap(NULL, 24104, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f217ae66000
close(3)                                = 0
open("/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\16\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=14672, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae65000
mmap(NULL, 2109688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f217a6ea000
mprotect(0x7f217a6ec000, 2097152, PROT_NONE) = 0
mmap(0x7f217a8ec000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f217a8ec000
close(3)                                = 0
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/libm.so.6", 
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260U\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=997640, ...}) = 0
mmap(NULL, 3092776, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f217a3f6000
mprotect(0x7f217a4e9000, 2093056, PROT_NONE) = 0
mmap(0x7f217a6e8000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf2000) = 0x7f217a6e8000
close(3)                                = 0
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/libpthread.so.0",
 O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`m\0\0\0\0\0\0"..., 832) 
= 832
fstat(3, {st_mode=S_IFREG|0755, st_size=135433, ...}) = 0
mmap(NULL, 2212784, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f217a1d9000
mprotect(0x7f217a1f1000, 2093056, PROT_NONE) = 0
mmap(0x7f217a3f0000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f217a3f0000
mmap(0x7f217a3f2000, 13232, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f217a3f2000
close(3)                                = 0
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/libc.so.6", 
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\25\2\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1728816, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae64000
mmap(NULL, 3841120, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f2179e2f000
mprotect(0x7f2179fcf000, 2097152, PROT_NONE) = 0
mmap(0x7f217a1cf000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a0000) = 0x7f217a1cf000
mmap(0x7f217a1d5000, 15456, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f217a1d5000
close(3)                                = 0
open("/usr/lib64/perl5/5.8.8/x86_64-pld-linux-thread-multi/CORE/libcrypt.so.1", 
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libcrypt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\n\0\0\0\0\0\0"..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=47280, ...}) = 0
mmap(NULL, 2331072, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f2179bf5000
mprotect(0x7f2179c00000, 2093056, PROT_NONE) = 0
mmap(0x7f2179dff000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa000) = 0x7f2179dff000
mmap(0x7f2179e01000, 184768, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2179e01000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae63000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae62000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae61000
arch_prctl(ARCH_SET_FS, 0x7f217ae62700) = 0
mprotect(0x7f217a1cf000, 16384, PROT_READ) = 0
mprotect(0x7f2179dff000, 4096, PROT_READ) = 0
mprotect(0x7f217a3f0000, 4096, PROT_READ) = 0
mprotect(0x7f217a6e8000, 4096, PROT_READ) = 0
mprotect(0x7f217a8ec000, 4096, PROT_READ) = 0
mprotect(0x7f217ac3f000, 12288, PROT_READ) = 0
mprotect(0x603000, 4096, PROT_READ)     = 0
mprotect(0x7f217ae6d000, 4096, PROT_READ) = 0
munmap(0x7f217ae66000, 24104)           = 0
set_tid_address(0x7f217ae629d0)         = 30903
set_robust_list(0x7f217ae629e0, 0x18)   = 0
futex(0x7fff5242e07c, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x7fff5242e07c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 
7f217ae62700) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGRTMIN, {0x7f217a1df7c0, [], SA_RESTORER|SA_SIGINFO, 
0x7f217a1e8de0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f217a1df850, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 
0x7f217a1e8de0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
rt_sigaction(SIGFPE, {SIG_IGN, [FPE], SA_RESTORER|SA_RESTART, 0x7f2179e63d00}, 
{SIG_DFL, [], 0}, 8) = 0
brk(0)                                  = 0x1c01000
brk(0x1c23000)                          = 0x1c23000
getuid()                                = 0
geteuid()                               = 0
getgid()                                = 0
getegid()                               = 0
open("/usr/lib64/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2223712, ...}) = 0
mmap(NULL, 2223712, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f21799d6000
close(3)                                = 0
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae40000
open("/dev/urandom", O_RDONLY)          = 3
read(3, "^nbc", 4)                      = 4
close(3)                                = 0
open("/dev/null", O_RDONLY)             = 3
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fstat(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
readlink("/proc/self/exe", "/usr/bin/perl5.8.8", 4095) = 18
brk(0x1c44000)                          = 0x1c44000
getppid()                               = 30902
fstat(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 
0x7fff5242d618) = -1 ENOTTY (Inappropriate ioctl for device)
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f217ae6b000
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_SET)                   = 0
close(3)                                = 0
munmap(0x7f217ae6b000, 4096)            = 0
dup(42)                                 = 3
fcntl(3, F_GETFL)                       = 0x8401 (flags 
O_WRONLY|O_APPEND|O_LARGEFILE)
close(3)                                = 0
write(2, "Invalid argument at -e line 2.\n", 31Invalid argument at -e line 2.
) = 31
exit_group(22)                          = ?
+ rightfile=


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.