Debian Bug report logs - #491257
liblua5.1-posix1: posix.rpoll does not works on pipes

version graph

Package: liblua5.1-posix1; Maintainer for liblua5.1-posix1 is (unknown);

Reported by: Myhailo Danylenko <isbear@ukrpost.net>

Date: Fri, 18 Jul 2008 02:36:01 UTC

Severity: normal

Found in version lua-posix/5.1.2-3

Fixed in version lua-posix/5.1.3-1

Done: Enrico Tassi <gareuselesinge@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Enrico Tassi <gareuselesinge@debian.org>:
Bug#491257; Package liblua5.1-posix1. (full text, mbox, link).


Acknowledgement sent to Myhailo Danylenko <isbear@ukrpost.net>:
New Bug report received and forwarded. Copy sent to Enrico Tassi <gareuselesinge@debian.org>. (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Myhailo Danylenko <isbear@ukrpost.net>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: liblua5.1-posix1: posix.rpoll does not works on pipes
Date: Fri, 18 Jul 2008 05:32:51 +0300
Package: liblua5.1-posix1
Version: 5.1.2-3
Severity: normal



  How to reproduce:

[isbear:~] cat one
adsf
fasdfea adf
fdasfeaf
fdaaaffff
fdag
fdasffffasddf

[isbear:~] cat luatest2.lua
-- pipe

require ( 'posix' )

f = io.popen ( 'cat one' )
c = 10
while c > 0 do
        c   = c - 1
        ret = posix.rpoll ( f, 500 )
        lin = nil
--      if ret == 1 then
                lin = f:read ()
--      end
        print ( ret, lin )
end

-- The End.
[isbear:~] lua luatest2.lua
nil     adsf
nil     fasdfea adf
nil     fdasfeaf
nil     fdaaaffff
nil     fdag
nil     fdasffffasddf
nil
nil     nil
nil     nil
nil     nil

As we see, rpoll returns nil on successfully opened pipe. Though, there
are even more amazing example:

[isbear:~] cat luatest3.lua
-- pipe with delay

require ( 'posix' )

f = io.popen ( 'sleep 1 ; cat one' )
c = 10
while c > 0 do
        c   = c - 1
        ret = posix.rpoll ( f, 500 )
        lin = nil
        if ( ret == 1 ) then
                lin = f:read ()
        end
        print ( ret, lin )
end

-- The End.
[isbear:~] lua luatest3.lua
0       nil
0       nil
1       adsf
nil     nil
nil     nil
nil     nil
nil     nil
nil     nil
nil     nil
nil     nil

rpoll's behaviour looks strange, isn't it?



  No any error messages



  How it is expected to be

There is corresponding code snippet from lposix.c:

/* from http://lua-users.org/lists/lua-l/2007-11/msg00346.html */
static int Ppoll(lua_State *L)   /** poll(filehandle, timeout) */
{
        struct pollfd fds;
        FILE* file = *(FILE**)luaL_checkudata(L,1,LUA_FILEHANDLE);
        int ret,timeout = luaL_checkint(L,2);
        fds.fd = fileno(file);
        fds.events = POLLIN;
        ret = poll(&fds,1,timeout);
        if (ret == -1) {
                lua_error(L);
        }
        if (ret == 1 && ((fds.revents & POLLHUP) || (fds.revents & POLLNVAL))) {
                lua_pushnil(L);
        } else {
                lua_pushnumber(L,ret);
        }    
        return 1;
}


I'll use next simple C program to demonstrate what is going behind the
scenes:
[isbear:~] cat poll.c

#include <poll.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>

int main ( int argc, char **argv )
{
        int ret;
        struct pollfd fds;
        char a[10];
        int c = 10;

        switch ( *argv[1] ) {
        case 'p':
                fds.fd = fileno ( popen ( argv[2], "r" ) );
                break;
        case 'f':
                fds.fd = open ( argv[2], O_RDONLY );
                break;
        default:
                fds.fd = fileno ( stdin );
                break;
        }

        fds.events = POLLIN;
        printf ( "file number: %d\n", fds.fd );
        printf ( "(POLLIN %X, POLLPRI %X, POLLOUT %X, POLLERR %X,"
                 " POLLHUP %X, POLLNVAL %X)\n",
                 POLLIN, POLLPRI, POLLOUT, POLLERR, POLLHUP, POLLNVAL );

        do {
                ret = poll ( &fds, 1, 400 );
                printf ( "Poll: %d, revents: %X", ret, fds.revents );

                if ( ret ) {
                        int num = read ( fds.fd, a, 9 );
                        printf ( ", read: %d", num );
                }

                puts ("");

		sleep ( 1 );
        } while ( c-- > 0 );
}

/* The End. */
[isbear:~] gcc poll.c
[isbear:~] ./a.out f 'one'
file number: 3
(POLLIN 1, POLLPRI 2, POLLOUT 4, POLLERR 8, POLLHUP 10, POLLNVAL 20)
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 2
Poll: 1, revents: 1, read: 0
Poll: 1, revents: 1, read: 0
Poll: 1, revents: 1, read: 0
Poll: 1, revents: 1, read: 0
[isbear:~] ./a.out p 'cat one'
file number: 3
(POLLIN 1, POLLPRI 2, POLLOUT 4, POLLERR 8, POLLHUP 10, POLLNVAL 20)
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 2
Poll: 1, revents: 10, read: 0
Poll: 1, revents: 10, read: 0
Poll: 1, revents: 10, read: 0
Poll: 1, revents: 10, read: 0
[isbear:~] ./a.out p 'sleep 1; cat one; sleep 3'
file number: 3
(POLLIN 1, POLLPRI 2, POLLOUT 4, POLLERR 8, POLLHUP 10, POLLNVAL 20)
Poll: 0, revents: 0
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 1, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 9
Poll: 1, revents: 11, read: 2
Poll: 1, revents: 10, read: 0
Poll: 1, revents: 10, read: 0
Poll: 1, revents: 10, read: 0

so, when pipe command finishes (but data are still available), poll
sets POLLHUP, and rpoll then returns nil.

man 2 poll says:
              POLLHUP
                     Hang up (output only).
              POLLNVAL
                     Invalid request: fd not open (output only).

So, these flags are relative to output, not to input (as we claimed in
fds.events, we interested only in input events). IMHO, these flags
should be ignored.

When I added patch below and rebuilt package, all works fine.
--- lua-posix-5.1.2.a/posix.c   2008-01-29 14:54:24.000000000 +0200
+++ lua-posix-5.1.2/lposix.c    2008-07-18 03:39:39.000000000 +0300
@@ -495,11 +495,11 @@
        if (ret == -1) {
                lua_error(L);
        }
-       if (ret == 1 && ((fds.revents & POLLHUP) || (fds.revents & POLLNVAL))) {
+/*     if (ret == 1 && ((fds.revents & POLLHUP) || (fds.revents & POLLNVAL))) {
                lua_pushnil(L);
-       } else {
+       } else {*/
                lua_pushnumber(L,ret);
-       }    
+/*     }    */
        return 1;
 }



  Reportbug output:

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing'), (50, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=uk_UA.UTF-8, LC_CTYPE=uk_UA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages liblua5.1-posix1 depends on:
ii  libc6                         2.7-10     GNU C Library: Shared libraries

liblua5.1-posix1 recommends no packages.

-- no debconf information


-- 
Михайло Даниленко
-------------------------------
jabber:	<isbear@jabber.kiev.ua>
icq:    200352743




Reply sent to Enrico Tassi <gareuselesinge@debian.org>:
You have taken responsibility. (full text, mbox, link).


Notification sent to Myhailo Danylenko <isbear@ukrpost.net>:
Bug acknowledged by developer. (full text, mbox, link).


Message #10 received at 491257-close@bugs.debian.org (full text, mbox, reply):

From: Enrico Tassi <gareuselesinge@debian.org>
To: 491257-close@bugs.debian.org
Subject: Bug#491257: fixed in lua-posix 5.1.3-1
Date: Fri, 18 Jul 2008 09:02:16 +0000
Source: lua-posix
Source-Version: 5.1.3-1

We believe that the bug you reported is fixed in the latest version of
lua-posix, which is due to be installed in the Debian FTP archive:

liblua5.1-posix-dev_5.1.3-1_amd64.deb
  to pool/main/l/lua-posix/liblua5.1-posix-dev_5.1.3-1_amd64.deb
liblua5.1-posix1_5.1.3-1_amd64.deb
  to pool/main/l/lua-posix/liblua5.1-posix1_5.1.3-1_amd64.deb
lua-posix_5.1.3-1.diff.gz
  to pool/main/l/lua-posix/lua-posix_5.1.3-1.diff.gz
lua-posix_5.1.3-1.dsc
  to pool/main/l/lua-posix/lua-posix_5.1.3-1.dsc
lua-posix_5.1.3.orig.tar.gz
  to pool/main/l/lua-posix/lua-posix_5.1.3.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 491257@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Enrico Tassi <gareuselesinge@debian.org> (supplier of updated lua-posix package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Fri, 18 Jul 2008 09:49:22 +0200
Source: lua-posix
Binary: liblua5.1-posix1 liblua5.1-posix-dev
Architecture: source amd64
Version: 5.1.3-1
Distribution: unstable
Urgency: low
Maintainer: Enrico Tassi <gareuselesinge@debian.org>
Changed-By: Enrico Tassi <gareuselesinge@debian.org>
Description: 
 liblua5.1-posix-dev - posix development files for the lua language version 5.1
 liblua5.1-posix1 - posix library for the lua language version 5.1
Closes: 491257
Changes: 
 lua-posix (5.1.3-1) unstable; urgency=low
 .
   * New upstream release
   * Patch by Myhailo Danylenko integrated (Closes: #491257)
Checksums-Sha1: 
 e3776c129ff737cf9c984acfe4f9020a275d3382 1239 lua-posix_5.1.3-1.dsc
 fb4e255f89d8b9dafae1fb573a0117cd7ffd8906 13132 lua-posix_5.1.3.orig.tar.gz
 57d973f6d36872f67101fae44be7e7e6d8ddfbaf 10353 lua-posix_5.1.3-1.diff.gz
 0ebd443cd70ec65ab86dfd79e864e6c8b4dc0573 19112 liblua5.1-posix1_5.1.3-1_amd64.deb
 4c859c9ed2f1ada7b9ecd43deb79dddb1e695e4e 19192 liblua5.1-posix-dev_5.1.3-1_amd64.deb
Checksums-Sha256: 
 99a92882f30ab180f2914f426866fe744fe7c86224889a4f3000e7ae5b306467 1239 lua-posix_5.1.3-1.dsc
 59450fd6bc5e2e5452503a2947a52785b666fea11a2b2e2bbc81f36edefda592 13132 lua-posix_5.1.3.orig.tar.gz
 9fbfddcc622854914f6f2f4f09b752857031db058b99b57663c6323eeaf115e3 10353 lua-posix_5.1.3-1.diff.gz
 cca70282ff8c3ab7eb769000875ffde155621a3cd969f32cf34b68e127f75c99 19112 liblua5.1-posix1_5.1.3-1_amd64.deb
 40858e2d2e513992f6999d20bcf152004d3465e6d7bbbc00078a57692822f942 19192 liblua5.1-posix-dev_5.1.3-1_amd64.deb
Files: 
 6686cc835c37db3ce56ac9d276552ea5 1239 interpreters optional lua-posix_5.1.3-1.dsc
 4271f321c39d0560d9fbe6ca882a67aa 13132 interpreters optional lua-posix_5.1.3.orig.tar.gz
 38815556131f64bfe50ea2da2bd1393d 10353 interpreters optional lua-posix_5.1.3-1.diff.gz
 80bbe8f0d91d8fd8e493c45079e1c46e 19112 interpreters optional liblua5.1-posix1_5.1.3-1_amd64.deb
 44bcda0abf031f9d9af2fc04cfb1f096 19192 libdevel optional liblua5.1-posix-dev_5.1.3-1_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkiAUGYACgkQ7kkcPgEj8vIRhgCgpav4VgZLkyGea7dJKiR9F83O
LkYAn2y50SGaF7WtvyUrdLYjhpozxq0i
=vuhU
-----END PGP SIGNATURE-----





Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Sun, 30 Nov 2008 08:11:54 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Mar 9 01:16:51 2023; Machine Name: bembo

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.