Function written in C, hangs on one machine and not another... - Mailing list pgsql-general

From CG
Subject Function written in C, hangs on one machine and not another...
Date
Msg-id 20051028133830.20569.qmail@web32515.mail.mud.yahoo.com
Whole thread Raw
Responses Re: Function written in C, hangs on one machine and not another...
List pgsql-general
PostgreSQL 7.4 ...

Essentially, I've written a function in C for use with PostgreSQL. The debugger
shows that the program is hanging on the part of the program that is writing
data into it's own STDIN.

[snip]

  // Open up and hijack STDIN
  int pipe_pair[2];
  int pipe_rv = pipe(pipe_pair);
  if (pipe_rv != 0)
  // Abort! Abort!
  {
    close(pipe_pair[1]);
    pfree(param_1);
    pfree(param_2);
    PG_RETURN_NULL();
  }

  int newfd = dup2(pipe_pair[0],STDIN_FILENO);
  if (newfd != 0)
  // Abort! Abort!
  {
    close(pipe_pair[1]);
    pfree(param_1);
    pfree(param_2);
    PG_RETURN_NULL();
  }

  // Write param_1 to hijacked pipe
  write(pipe_pair[1], param_1, param_1_len); // Hangs here...

[/snip]

It works on the machine I use for testing from within PostgreSQL, but it
doesn't work on the machine which is the production server. I'd hate for this
to matter, but I ought to disclose that testing machine is a 1-way AMD Box with
a more recent version of the Linux 2.6 kernel, and a more recent version of
libc. The production machine is a 2-way Dell Xeon processor. Same version of
PostgreSQL, compiled with the same flags (except with debugging symbols for the
testing machine). You'd, or at least I would, think simple code like this would
compile and run on multiple platforms...

I can perform the same STDIN hijacking on both machines in a standalone
program, but it fails under PostgreSQL.

I'm completely stumped, and I need YOUR insight! Thank you!!

CGV



__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Why database is corrupted after re-booting
Next
From: Marc Andre Paquin
Date:
Subject: Re: Looking for a command to list schemas