Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2003-11

Bug in AssignPipe() on Linux

17 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jeff Pohlmeyer

Using the latest version of the compiler, and I am having a problem with the popen() function on Linux.

It looks like popen() fails because AssignStream() fails, because AssignPipe() fails, and that's about as far as I got. ( I'm lost when it comes to the do_SysCall() stuff. )

Maybe whoever broke it will understand better what is wrong ;-)

[EXAMPLE]

program pipetest;
uses errors, {$IFDEF VER1_0} linux {$ELSE} unix {$ENDIF};
var
  pipi, pipo: text;
  s: string;
begin
  writeln ('assigning pipes.');
  if not assignpipe(pipi,pipo) then
  begin
    perror('assignpipe',linuxerror);
    halt(1);
  end;
  writeln ('writing to pipe, and flushing.');
  writeln (pipo,'this is a textstring');
  close(pipo);
  writeln ('reading from pipe.');
  while not eof(pipi) do
  begin
    readln (pipi,s);
   writeln ('read from pipe : ',s);
  end;
  close (pipi);
  writeln ('closed pipes.');
  writeln;
end.

[/EXAMPLE]

I tried this with four different compiler versions -
- here are the results:

WORKS: version 1.0.10 [2003/06/26] for i386 (pre-built binary)

WORKS: version 1.1 [2003/10/11] for i386 (CVS)

FAILS: version 1.9.0 [2003/11/05] for i386 (pre-built binary)

FAILS: version 1.9.1 [2003/11/07] for i386 (CVS)

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Vincent Snijders
to Jeff Pohlmeyer
Show quoted text 10 lines
Using the latest version of the compiler, and I am having a problem with the popen() function on Linux. It looks like popen() fails because AssignStream() fails, because AssignPipe() fails, and that's about as far as I got. ( I'm lost when it comes to the do_SysCall() stuff. ) Maybe whoever broke it will understand better what is wrong ;-)

For your information, bug 2761 has the same cause.

Regards,
Vincent.

Peter Vreman
to Jeff Pohlmeyer: Using the latest version of the compiler, and I am having a problem with the popen()…
Show quoted text 12 lines
Using the latest version of the compiler, and I am having a problem with the popen() function on Linux. It looks like popen() fails because AssignStream() fails, because AssignPipe() fails, and that's about as far as I got. ( I'm lost when it comes to the do_SysCall() stuff. ) FAILS: version 1.9.0 [2003/11/05] for i386 (pre-built binary) FAILS: version 1.9.1 [2003/11/07] for i386 (CVS)

Did you only test the 1.9.0 compiler or also distributed the 1.9.0 RTL ?

Please check for a leftover syscallo.inc in fpc/rtl/linux/. It should only be available in in fpc/rtl/linux/i386/ with rev. 1.2

FYI: The default calling convention has changed to stdcall, that means that the registers ebx,esi,edi need to be saved. The problem that you have is that do_syscall did not save those registers in older versions. THat has been fixed a week ago.

Jeff Pohlmeyer

Hello, Peter - thanks for your response.

Did you only test the 1.9.0 compiler or also distributed the 1.9.0 RTL ?

I tested with each compiler version with its own RTL.

Please check for a leftover syscallo.inc in fpc/rtl/linux/. It should only be available in in fpc/rtl/linux/i386/ with rev. 1.2

I did a fresh CVS checkout friday morning and the file is still in CVS - what do you mean "leftover" ?

I tried deleting the file, but the build failed on "oldlinux.pp" So I also deleted "oldlinux.pp" and did a fresh install. But AssignPipe() still does not work.

That has been fixed a week ago.

Did you try the example I posted?

If you can't reproduce the problem, then I will assume there is still something wrong with my installation.

Otherwise, I will regard this as an unfixed bug.

For your information, bug 2761 has the same cause.

Thanks, Vincent - I see that bug #2761 is still open!

- Jeff

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Peter Vreman
to Jeff Pohlmeyer
you wrote 21 lines
Hello, Peter - thanks for your response. > Did you only test the 1.9.0 compiler or also distributed the 1.9.0 RTL ? I tested with each compiler version with its own RTL. > Please check for a leftover syscallo.inc in fpc/rtl/linux/. It should only > be available in in fpc/rtl/linux/i386/ with rev. 1.2 I did a fresh CVS checkout friday morning and the file is still in CVS - what do you mean "leftover" ? I tried deleting the file, but the build failed on "oldlinux.pp" So I also deleted "oldlinux.pp" and did a fresh install. But AssignPipe() still does not work. > That has been fixed a week ago. Did you try the example I posted?

Yes, and it runs fine.

Peter

Jeff Pohlmeyer
> Did you try the example I posted? Yes, and it runs fine. Peter

hmmm...
I have tried everything you suggested ( and everything else I can think of ) but I still can't get it to work.

Could someone else please try this with the Linux 1.9.0 compiler, and let me know the results ?

program pipetest;
uses errors, unix;
var
  pipi, pipo: text;
begin
  AssignPipe(pipi, pipo);
  perror('AssignPipe', LinuxError);
end.

Thanks,
- Jeff

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Pedro Lopez-Cabanillas
to Jeff Pohlmeyer: hmmm... I have tried everything you suggested ( and everything else I can think of ) but…
Jeff Pohlmeyer wrote 12 lines
Could someone else please try this with the Linux 1.9.0 compiler, and let me know the results ? program pipetest; uses errors, unix; var pipi, pipo: text; begin AssignPipe(pipi, pipo); perror('AssignPipe', LinuxError); end.

I've tried it, with fpc 1.9.0 (binary rpm downloaded from sf).

$ fpc pipetest.pp
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 1.9.0 [2003/11/05] for i386 Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Linux for i386
Compiling pipetest.pp
Linking pipetest
9 Lines compiled, 0.7 sec

$ ./pipetest
AssignPipe: Success

Regards,
Pedro

ALSA Library Bindings for Pascal http://alsapas.alturl.com
Marco van de Voort
to Pedro Lopez-Cabanillas
Show quoted text 19 lines
> pipi, pipo: text; > begin > AssignPipe(pipi, pipo); > perror('AssignPipe', LinuxError); > end. I've tried it, with fpc 1.9.0 (binary rpm downloaded from sf). $ fpc pipetest.pp Hint: End of reading config file /etc/fpc.cfg Free Pascal Compiler version 1.9.0 [2003/11/05] for i386 Copyright (c) 1993-2002 by Florian Klaempfl Target OS: Linux for i386 Compiling pipetest.pp Linking pipetest 9 Lines compiled, 0.7 sec $ ./pipetest AssignPipe: Success

- Do an strace, and see if there is a function that fails.

Pedro Lopez-Cabanillas
to Marco van de Voort
Marco van de Voort wrote
- Do an strace, and see if there is a function that fails.

Everything seems OK.

$ strace pipetest
execve("/home/plc/Pascal/test1.9/pipetest", ["pipetest"], [/* 63 vars */]) = 0 sigaction(SIGFPE, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 sigaction(SIGSEGV, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 sigaction(SIGBUS, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 sigaction(SIGILL, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 getpid() = 4307
readlink("/proc/4307/exe", "/home/plc/Pascal/test1.9/pipetest", 255) = 33 open("/etc/timezone", O_RDONLY) = 3
read(3, "Europe/Madrid", 255) = 13
close(3) = 0
open("/usr/share/zoneinfo/Europe/Madrid", O_RDONLY) = 3 read(3, "TZif\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\10\0\0\0\10"..., 44) = 44 read(3, "\234\363\360p\235\276\367p\236\272\305\360\237\240*\360"..., 652) = 652
read(3, "\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0\2\0\2\0"..., 163) = 163
read(3, "\0\0\16\20", 4) = 4
read(3, "\1", 1) = 1
read(3, "\0", 1) = 1
read(3, "\0\0\0\0", 4) = 4
read(3, "\0", 1) = 1
read(3, "\5", 1) = 1
read(3, "\0\0\34 ", 4) = 4
read(3, "\1", 1) = 1
read(3, "\t", 1) = 1
read(3, "\0\0\16\20", 4) = 4
read(3, "\1", 1) = 1
read(3, "\0", 1) = 1
read(3, "\0\0\34 ", 4) = 4
read(3, "\1", 1) = 1
read(3, "\16", 1) = 1
read(3, "\0\0\16\20", 4) = 4
read(3, "\0", 1) = 1
read(3, "\23", 1) = 1
read(3, "\0\0\34 ", 4) = 4
read(3, "\1", 1) = 1
read(3, "\16", 1) = 1
read(3, "\0\0\16\20", 4) = 4
read(3, "\0", 1) = 1
read(3, "\23", 1) = 1
read(3, "WEST\0WET\0WEMT\0CEST\0CET\0", 23) = 23
read(3, "\1\1\1\0\0\0\1\1", 8) = 8
read(3, "\0\0\0\0\0\0\1\1", 8) = 8
close(3) = 0
time([1068403026]) = 1068403026 pipe([3, 4]) = 0
write(2, "AssignPipe: Success\n", 20AssignPipe: Success ) = 20
_exit(0) = ?

I've compiled the latest Lazarus snapshot, successfully. It fails when invoke fpc with the message:

[TCompiler.Compile] CmdLine="/usr/bin/ppc386 -Rintel -S2cgi -CD -Ch8000000 -OG1p1 -gl -XD -vewnhi -l -Fu/usr/share/lazarus/lcl/units/ -Fu/usr/share/lazarus/lcl/units/gtk/ -Fu/usr/share/lazarus/packager/units/ -Fu. -dLCL /home/plc/Pascal/prueba1/project1.lpr"
[TCompiler.Compile] exception "Failed to create pipe." TOutputFilter: "Failed to create pipe."

I'm suspecting that an old tree of fpc sources was lying around (fpcsrc rpm from Lazarus site) when i compiled Lazarus. I'm cleaning everything before rebuilding it again.

Regards,
Pedro

ALSA Library Bindings for Pascal http://alsapas.alturl.com
Marco van de Voort
to Pedro Lopez-Cabanillas

[ Charset ISO-8859-1 unsupported, converting... ]

Show quoted text 14 lines
Marco van de Voort wrote: > - Do an strace, and see if there is a function that fails. Everything seems OK. $ strace pipetest execve("/home/plc/Pascal/test1.9/pipetest", ["pipetest"], [/* 63 vars */]) = 0 sigaction(SIGFPE, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 sigaction(SIGSEGV, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 sigaction(SIGBUS, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 sigaction(SIGILL, {0x805a9d4, [], 0}, {SIG_DFL}, 0x40054d58) = 0 getpid() = 4307 readlink("/proc/4307/exe", "/home/plc/Pascal/test1.9/pipetest", 255) = 33 open("/etc/timezone", O_RDONLY) = 3

This is the culprit. People that have this file don't have the problem. If this one goes wrong, the errno value remains there, and the next decision that bases itself on linuxerror goes wrong.

This is why it was hard to reproduce:

In my case, this happens

getpid() = 3953
readlink("/proc/3953/exe", "/export/home/marcov/pipetest", 255) = 28 open("/etc/timezone", O_RDONLY) = -1 ENOENT (No such file or directory)

-> failed

stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1074, ...}) = 0 open("/etc/localtime", O_RDONLY) = 3

-> found, but errno is untouched.

Pedro Lopez-Cabanillas
to Marco van de Voort
Marco van de Voort wrote 5 lines
> open("/etc/timezone", O_RDONLY) = 3 This is the culprit. People that have this file don't have the problem. If this one goes wrong, the errno value remains there, and the next decision that bases itself on linuxerror goes wrong.

Confirmed. Removing /etc/timezone, the program returns... AssignPipe: No such file or directory

Regards,
Pedro

ALSA Library Bindings for Pascal http://alsapas.alturl.com
GongYu

Jeff Pohlmeyer:
I do not try your sample(I remove it and install 1.0.10), but the lazarus IDE on my pc always show the same error("can not create pipe") with FPC 1.9.0 Compiler!

  

Show quoted text 37 lines
> > Did you try the example I posted? > Yes, and it runs fine. > Peter hmmm... I have tried everything you suggested ( and everything else I can think of ) but I still can't get it to work. Could someone else please try this with the Linux 1.9.0 compiler, and let me know the results ? program pipetest; uses errors, unix; var pipi, pipo: text; begin AssignPipe(pipi, pipo); perror('AssignPipe', LinuxError); end. Thanks, - Jeff __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

= = = = = = = = = = = = = = = = = = = =

GongYu

2003-11-09

Jeff Pohlmeyer
This is the culprit. People that have this file don't have the problem.

Yes, that's the problem -

open("/etc/timezone", O_RDONLY) = -1 ENOENT

If I create an empty file named /etc/timezone
the program still fails:

open("/usr/share/zoneinfo/localtime", O_RDONLY) = -1 ENOENT

If I also create that file, the program succeeds.

On my system (SuSE 7.1) I have /etc/localtime:
symbolic link to /usr/share/zoneinfo/CST6CDT

- but I can't find a file named "timezone" anywhere.

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Marco van de Voort
to Jeff Pohlmeyer
Show quoted text 6 lines
> This is the culprit. On my system (SuSE 7.1) I have /etc/localtime: symbolic link to /usr/share/zoneinfo/CST6CDT - but I can't find a file named "timezone" anywhere.

It is a FPC/FCL/LCL/Lazarus bug, but mostly fpc.

I've to talk to Peter first before fixing this.

Jeff Pohlmeyer
It is a FPC/FCL/LCL/Lazarus bug, but mostly fpc.

I don't use Lazarus - ironically, I ran into this bug while trying to recompile a program that interfaces FPC with NEdit. It doesn't use Lazarus or GTK, but it uses popen(F, 'ppc386 -iV', 'R') to check the compiler version. As a temporary workaround, I can use oldlinux.popen() or shell('ppc386 -iV > version.txt') and read the result from there.

Thanks a bunch for your help - I would never have guessed the timezone file had anything to do with opening a pipe!

- Jeff

PS: For some reason my posts never get nested in the right thread - Maybe pipermail doesn't like yahoo's headers ?

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Marco van de Voort
to Jeff Pohlmeyer
Show quoted text 11 lines
> It is a FPC/FCL/LCL/Lazarus bug, but mostly fpc. I don't use Lazarus - ironically, I ran into this bug while trying to recompile a program that interfaces FPC with NEdit. It doesn't use Lazarus or GTK, but it uses popen(F, 'ppc386 -iV', 'R') to check the compiler version. As a temporary workaround, I can use oldlinux.popen() or shell('ppc386 -iV > version.txt') and read the result from there. Thanks a bunch for your help - I would never have guessed the timezone file had anything to do with opening a pipe!

The real, more fundamental problem a convention change about errorhandling.

A side effect is that uncatched errors internally in the RTL can propagate to the next call.

The actual (convention) problem was that assignpipe read "errno" when the call hadn't failed. This was no problem in the old convention (errno/linuxerror reset to zero on succesfull call) but is in the new one.

PS: For some reason my posts never get nested in the right thread - Maybe pipermail doesn't like yahoo's headers ?

Maybe the yahoo client or server mutilates some headers. I don't use threading in email atm, so I wouldn't know.