On 2017-01-18 at 12:11 GMT+01:00 Bill Allombert wrote:
On Sun, Jan 01, 2017 at 02:43:12PM +0100, Loïc Grenié wrote:
> Package: pari
> Version: dd75740be
> Severity: normal
>
>      Hi Karim and Bill, and happy new year,
>
>      on exit(), my libc version lseek()s the files which are open. This
>   wreaks havoc when ploth is used in a file which is read() by gp.
>   A simple solution, which according to me should not produce
>   any problem, is to use _exit(0) instead of exit(0) in pari_daemon().
>   (Patch below but it's faster to add the underscore by hand).

Hello Loïc,

This is very strange, the only difference between exit and _exit is that
atexit(3) and on_exit(3) handlers are ignored. Is something installing
handlers that use lseek ?

     This is indeed very strange. The problematic handlers are the
  fclose() for all open file desriptors.
 
Do you have an example file ?

     For pari/gp just make a few commands with a ploth() inside (it may
  be necessary for the file to have more than 4kbytes). Example
1
2
3
ploth(x=0,2*Pi,sin(x))
4
...
4096

   Otherwise I have a C-program that I wanted to file with the bug report
  for Debian -- but I failed the bug report.

    To use it, compile it in a directory where you can create a file,
  use it with ./fopen-bug and ./fopen-bug a. The second form (with
  an argument) forks while the first one does not. The output are not
  the same (while I would have expected that they are equal).

       Thanks,

           Loïc

------8<-----fopen-bug.c-------8<-------fopen-bug.c-------8<--------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char **argv)
{
    FILE *f = fopen("data", "r");
    char str[1024];

    if (!f) {
    int i;
    f = fopen("data", "w");
    for (i = 0; i <= 64; i++)
        fprintf(f, "%063i\n", i);
    fclose(f);
    fopen("data", "r");
    }
    (void)fgets(str, sizeof str, f);
    printf("%s", str);
    (void)fgets(str, sizeof str, f);
    printf("%s", str);
    (void)fgets(str, sizeof str, f);
    printf("%s", str);
    if (argc >= 2) {
    if (!fork()) exit(0);
    wait(NULL);
    }
    while (fgets(str, sizeof str, f))
    printf("%s", str);
    fclose(f);
    exit(0);
}