Jacek Konieczny
2012-Nov-09 13:56 UTC
[PATCH] Fix locking in tools/hotplug/Linux/locking.sh
The claim_lock() function would fail in the perl code with: Invalid argument at -e line 2. because the Perl snippet opens for reading the file descriptor, which was earlier opened for write (append). Signed-off-by: Jacek Konieczny <jajcus@jajcus.net> --- tools/hotplug/Linux/locking.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh index e34f155..122bcfb 100644 --- a/tools/hotplug/Linux/locking.sh +++ b/tools/hotplug/Linux/locking.sh @@ -44,7 +44,7 @@ claim_lock() # See below for a correctness proof. local rightfile while true; do - eval "exec $_lockfd>>$_lockfile" + eval "exec $_lockfd<>$_lockfile" flock -x $_lockfd || return $? # We can''t just stat /dev/stdin or /proc/self/fd/$_lockfd or # use bash''s test -ef because those all go through what is -- 1.7.12.4
Ian Campbell
2012-Nov-12 16:42 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Fri, 2012-11-09 at 13:56 +0000, Jacek Konieczny wrote:> The claim_lock() function would fail in the perl code with: > > Invalid argument at -e line 2. > > because the Perl snippet opens for reading the file descriptor, which > was earlier opened for write (append).Looks plausible to me. How does this interact with the eval "exec $_lockfd<&-" which Olaf added in 26079:b3b03536789a ? I suppose close is close and <&- and >&- or even <>&- are equivalent?> > Signed-off-by: Jacek Konieczny <jajcus@jajcus.net> > --- > tools/hotplug/Linux/locking.sh | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh > index e34f155..122bcfb 100644 > --- a/tools/hotplug/Linux/locking.sh > +++ b/tools/hotplug/Linux/locking.sh > @@ -44,7 +44,7 @@ claim_lock() > # See below for a correctness proof. > local rightfile > while true; do > - eval "exec $_lockfd>>$_lockfile" > + eval "exec $_lockfd<>$_lockfile" > flock -x $_lockfd || return $? > # We can''t just stat /dev/stdin or /proc/self/fd/$_lockfd or > # use bash''s test -ef because those all go through what is
Jacek Konieczny
2012-Nov-12 18:05 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Mon, Nov 12, 2012 at 04:42:37PM +0000, Ian Campbell wrote:> On Fri, 2012-11-09 at 13:56 +0000, Jacek Konieczny wrote: > > The claim_lock() function would fail in the perl code with: > > > > Invalid argument at -e line 2. > > > > because the Perl snippet opens for reading the file descriptor, which > > was earlier opened for write (append). > > Looks plausible to me. > > How does this interact with the > eval "exec $_lockfd<&-" > which Olaf added in 26079:b3b03536789a ? I suppose close is close and > <&- and >&- or even <>&- are equivalent?It seems <&- and >&- are indeed the same and there is no such thing as ''<>&-''. I have added the Olaf''s change to my test setup and it works properly. So no conflict here.> > > > Signed-off-by: Jacek Konieczny <jajcus@jajcus.net> > > --- > > tools/hotplug/Linux/locking.sh | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh > > index e34f155..122bcfb 100644 > > --- a/tools/hotplug/Linux/locking.sh > > +++ b/tools/hotplug/Linux/locking.sh > > @@ -44,7 +44,7 @@ claim_lock() > > # See below for a correctness proof. > > local rightfile > > while true; do > > - eval "exec $_lockfd>>$_lockfile" > > + eval "exec $_lockfd<>$_lockfile" > > flock -x $_lockfd || return $? > > # We can''t just stat /dev/stdin or /proc/self/fd/$_lockfd or > > # use bash''s test -ef because those all go through what is
Olaf Hering
2012-Nov-12 18:07 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Mon, Nov 12, Ian Campbell wrote:> On Fri, 2012-11-09 at 13:56 +0000, Jacek Konieczny wrote: > > The claim_lock() function would fail in the perl code with: > > > > Invalid argument at -e line 2. > > > > because the Perl snippet opens for reading the file descriptor, which > > was earlier opened for write (append). > > Looks plausible to me. > > How does this interact with the > eval "exec $_lockfd<&-" > which Olaf added in 26079:b3b03536789a ? I suppose close is close and > <&- and >&- or even <>&- are equivalent?I did not see the perl error, in what environment did you notice this error? Olaf
Jacek Konieczny
2012-Nov-12 18:34 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Mon, Nov 12, 2012 at 07:07:38PM +0100, Olaf Hering wrote:> On Mon, Nov 12, Ian Campbell wrote: > > > On Fri, 2012-11-09 at 13:56 +0000, Jacek Konieczny wrote: > > > The claim_lock() function would fail in the perl code with: > > > > > > Invalid argument at -e line 2. > > > > > > because the Perl snippet opens for reading the file descriptor, which > > > was earlier opened for write (append). > > > > Looks plausible to me. > > > > How does this interact with the > > eval "exec $_lockfd<&-" > > which Olaf added in 26079:b3b03536789a ? I suppose close is close and > > <&- and >&- or even <>&- are equivalent? > > I did not see the perl error, in what environment did you notice this > error?Xen 4.2.0 # uname -rm 3.6.6-aos4 x86_64 # perl --version This is perl, v5.8.8 built for x86_64-pld-linux-thread-multi I find it a bit strange that it seems to work for everybody else that me, but the source of my error seems obvious (opening write-only file descriptor for reading). I guess my perl, for some reason, does something more when using open() on an existing file descriptor. Greets, Jacek
Olaf Hering
2012-Nov-12 18:40 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Mon, Nov 12, Jacek Konieczny wrote:> # perl --version > This is perl, v5.8.8 built for x86_64-pld-linux-thread-multisles11sp2 has perl 5.10.0, maybe there is different behaviour in different perl versions. Olaf
Ian Campbell
2012-Nov-13 11:08 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
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. Perhaps its a security thing (e.g. selinux or something like that) enforcing something extra? Might be interesting to run things under strace ? Per the attached t.sh. Which for me produces the below without complaint: Ian. + _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"], [/* 35 vars */]) = 0 brk(0) = 0xea0000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f08728d7000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=68197, ...}) = 0 mmap(NULL, 68197, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f08728c6000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/usr/lib/libperl.so.5.10", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\222\3\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=1495208, ...}) = 0 mmap(NULL, 3590856, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f087234f000 mprotect(0x7f08724b4000, 2093056, PROT_NONE) = 0 mmap(0x7f08726b3000, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x164000) = 0x7f08726b3000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libdl.so.2", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\r\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=14696, ...}) = 0 mmap(NULL, 2109696, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f087214b000 mprotect(0x7f087214d000, 2097152, PROT_NONE) = 0 mmap(0x7f087234d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f087234d000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libm.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360>\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=530736, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f08728c5000 mmap(NULL, 2625768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0871ec9000 mprotect(0x7f0871f49000, 2097152, PROT_NONE) = 0 mmap(0x7f0872149000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x80000) = 0x7f0872149000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libpthread.so.0", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360Y\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=131258, ...}) = 0 mmap(NULL, 2208640, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0871cad000 mprotect(0x7f0871cc4000, 2093056, PROT_NONE) = 0 mmap(0x7f0871ec3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7f0871ec3000 mmap(0x7f0871ec5000, 13184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0871ec5000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\355\1\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1437064, ...}) = 0 mmap(NULL, 3545160, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f087194b000 mprotect(0x7f0871aa4000, 2093056, PROT_NONE) = 0 mmap(0x7f0871ca3000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x158000) = 0x7f0871ca3000 mmap(0x7f0871ca8000, 18504, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0871ca8000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libcrypt.so.1", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\n\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=35104, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f08728c4000 mmap(NULL, 2318784, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0871714000 mprotect(0x7f087171c000, 2093056, PROT_NONE) = 0 mmap(0x7f087191b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7f087191b000 mmap(0x7f087191d000, 184768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f087191d000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f08728c3000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f08728c2000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f08728c1000 arch_prctl(ARCH_SET_FS, 0x7f08728c2700) = 0 mprotect(0x7f087191b000, 4096, PROT_READ) = 0 mprotect(0x7f0871ca3000, 16384, PROT_READ) = 0 mprotect(0x7f0871ec3000, 4096, PROT_READ) = 0 mprotect(0x7f0872149000, 4096, PROT_READ) = 0 mprotect(0x7f087234d000, 4096, PROT_READ) = 0 mprotect(0x7f08728d9000, 4096, PROT_READ) = 0 munmap(0x7f08728c6000, 68197) = 0 set_tid_address(0x7f08728c29d0) = 17761 set_robust_list(0x7f08728c29e0, 0x18) = 0 futex(0x7fffbb03b91c, FUTEX_WAKE_PRIVATE, 1) = 0 futex(0x7fffbb03b91c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7f08728c2700) = -1 EAGAIN (Resource temporarily unavailable) rt_sigaction(SIGRTMIN, {0x7f0871cb2870, [], SA_RESTORER|SA_SIGINFO, 0x7f0871cbbff0}, NULL, 8) = 0 rt_sigaction(SIGRT_1, {0x7f0871cb2900, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f0871cbbff0}, 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, 0x7f087197d230}, {SIG_DFL, [], 0}, 8) = 0 brk(0) = 0xea0000 brk(0xec1000) = 0xec1000 getuid() = 1161 geteuid() = 1161 getgid() = 10020 getegid() = 10020 open("/usr/lib/locale/locale-archive", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=2018512, ...}) = 0 mmap(NULL, 2018512, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0871527000 close(3) = 0 open("/dev/urandom", O_RDONLY) = 3 read(3, "\346\340\354H", 4) = 4 close(3) = 0 readlink("/proc/self/exe", "/usr/bin/perl", 4095) = 13 stat("/usr/local/lib/site_perl/5.10.1/x86_64-linux-gnu-thread-multi", 0x7fffbb03b390) = -1 ENOENT (No such file or directory) stat("/usr/local/lib/site_perl/5.10.1", 0x7fffbb03b390) = -1 ENOENT (No such file or directory) stat("/usr/local/lib/site_perl/x86_64-linux-gnu-thread-multi", 0x7fffbb03b390) = -1 ENOENT (No such file or directory) stat("/usr/local/lib/perl/5.10.0", 0x7fffbb03b4d0) = -1 ENOENT (No such file or directory) stat("/usr/local/share/perl/5.10.0", 0x7fffbb03b4d0) = -1 ENOENT (No such file or directory) ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffbb03b260) = -1 EINVAL (Invalid argument) lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffbb03b270) = -1 ENOTTY (Inappropriate ioctl for device) lseek(2, 0, SEEK_CUR) = 7954 open("/dev/null", O_RDONLY) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffbb03b390) = -1 ENOTTY (Inappropriate ioctl for device) lseek(3, 0, SEEK_CUR) = 0 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 brk(0xee2000) = 0xee2000 close(3) = 0 dup(42) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffbb03b320) = -1 ENOTTY (Inappropriate ioctl for device) lseek(3, 0, SEEK_CUR) = 0 fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 dup2(3, 0) = 0 close(3) = 0 fcntl(0, F_SETFD, 0) = 0 fstat(0, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 stat("/tmp/lockfile", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 rt_sigaction(SIG_0, NULL, {0x7fffbb03b810, ~[HUP INT QUIT TRAP BUS FPE USR1 SEGV USR2 TERM CONT TTIN TTOU URG XFSZ PROF WINCH RTMIN RT_1 RT_2 RT_3 RT_5 RT_6 RT_7 RT_8 RT_16 RT_17 RT_18 RT_19 RT_20 RT_21 RT_22 RT_23 RT_24 RT_25 RT_26 RT_27 RT_28 RT_29 RT_30 RT_31], 0}, 8) = -1 EINVAL (Invalid argument) rt_sigaction(SIGHUP, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGILL, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGTRAP, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGABRT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGBUS, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGFPE, NULL, {SIG_IGN, [FPE], SA_RESTORER|SA_RESTART, 0x7f087197d230}, 8) = 0 rt_sigaction(SIGKILL, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGUSR1, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGSEGV, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGUSR2, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGPIPE, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGALRM, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGSTKFLT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGCONT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGSTOP, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGTSTP, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGTTIN, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGTTOU, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGURG, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGXCPU, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGXFSZ, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGVTALRM, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGPROF, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGWINCH, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGIO, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGPWR, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGSYS, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_2, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_3, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_4, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_5, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_6, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_7, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_8, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_9, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_10, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_11, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_12, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_13, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_14, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_15, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_16, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_17, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_18, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_19, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_20, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_21, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_22, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_23, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_24, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_25, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_26, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_27, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_28, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_29, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_30, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_31, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGRT_32, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGABRT, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGIO, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGSYS, NULL, {SIG_DFL, [], 0}, 8) = 0 write(1, "y\n", 2) = 2 exit_group(0) = ? + rightfile=y + echo y _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Jacek Konieczny
2012-Nov-13 13:27 UTC
Re: [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@lists.xen.org http://lists.xen.org/xen-devel
Ian Jackson
2012-Nov-13 16:21 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
Jacek Konieczny writes ("Re: [Xen-devel] [PATCH] Fix locking in tools/hotplug/Linux/locking.sh"):> fcntl(3, F_GETFL) = 0x8401 (flags O_WRONLY|O_APPEND|O_LARGEFILE)So it seems perl is going out of its way to spot this earlier. That explains the mystery. Anyway the patch is fine. Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Ian Campbell
2012-Nov-13 16:25 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Tue, 2012-11-13 at 16:21 +0000, Ian Jackson wrote:> Jacek Konieczny writes ("Re: [Xen-devel] [PATCH] Fix locking in tools/hotplug/Linux/locking.sh"): > > fcntl(3, F_GETFL) = 0x8401 (flags O_WRONLY|O_APPEND|O_LARGEFILE) > > So it seems perl is going out of its way to spot this earlier. > That explains the mystery.Looking at glibc it seems like it has had this test since the mid-nineties, so quite why we aren''t seeing it elsewhere I can''t explain (maybe bash buggily opens the fd RDWR?)> Anyway the patch is fine. > > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>Yes, irrespective of why this patch does seem to be correct: Acked-by: Ian Campbell <ian.campbell@citrix.com>
Ian Campbell
2012-Nov-14 10:24 UTC
Re: [PATCH] Fix locking in tools/hotplug/Linux/locking.sh
On Tue, 2012-11-13 at 16:25 +0000, Ian Campbell wrote:> On Tue, 2012-11-13 at 16:21 +0000, Ian Jackson wrote:> > Anyway the patch is fine. > > > > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> > > Yes, irrespective of why this patch does seem to be correct: > > Acked-by: Ian Campbell <ian.campbell@citrix.com>Applied, thanks all.