Subject: p_read() returning -1 ??!

From: SEP Lutz <[email-masked]>
Date: Wed, 6 Oct 1993 18:36:15 +0100 (MET)

Hello POSTGRES developers,

in order to copy data with transaction protection from one POSTGRES
database to another, I use the fork() system call to duplicate
my copy process and send the data read in the source database by the
child process part using SysV messages to the father process part of my
program, which stores the received data into the target database.

This procedure works pretty well for "normal" tuple data read into a
portal buffer by retrieve commands.

But when I tried to copy large objects in the same way,
after successfully opening the inversion file, the child gets a return
value of -1 from the p_read() function:

  invfd = p_open(invname, INV_READ);
#if DEBUG_DB_COMPONENT
  fprintf (DEBUGOUT, "invfd = %d\n", invfd);
  fflush (DEBUGOUT);
#endif

  unixfd = open(unixname,             /* neu erstellen, exclusiv */
	        O_WRONLY | O_CREAT | O_EXCL, 
		S_IRUSR | S_IWUSR);   /* User kriegt Schreib/Leserechte */
  if (unixfd == (-1))
    return (FILEEXISTS);              /* Fehler wenn Datei schon existiert */

  if (invfd == (-1))                  /* Datei existiert in PG nicht */
    return (INVNEXISTS);
  
  readcnt = p_read(invfd, buffer, P_BUFSIZE);

#if DEBUG_DB_COMPONENT
  fprintf (DEBUGOUT, "read = ");
  fflush (DEBUGOUT);
#endif

  sumread = readcnt;
  while (readcnt > 0) {                  /* Alle Daten */
    error = write(unixfd, buffer, readcnt);
    sumread += readcnt;

#if DEBUG_DB_COMPONENT
  fprintf (DEBUGOUT, "%d ", sumread);
  fflush (DEBUGOUT);
#endif

    readcnt = p_read(invfd, buffer, P_BUFSIZE);
  }

#if DEBUG_DB_COMPONENT
  fprintf (DEBUGOUT, "%d\n", sumread);
  fflush (DEBUGOUT);
#endif

prints out "read = -1", although reading the large object from a
simple program not using fork() works well.

Any hints or suggestions? Am I doing something wrong?

Thanks for any help,

Andreas Loew
([email-masked])

-- 
SE Projektgruppe GeSAMiC      Email: [email-masked]
Fachbereich 1
Technische Hochschule Darmstadt / Germany