Need to close and re-open a process pipeline

Need to close and re-open a process pipeline

Post by kspa » Sun, 11 Jan 2004 16:21:56


I need to call qmail-queue. From the man page, it expects the
following:

qmail-queue reads a mail message from descriptor 0. It then
reads
envelope information from descriptor 1.

You can simulate this with a shell as follows:

$ /var/qmail/bin/qmail-queue
line 1<cr>
line 2<cr>
<cr>
line 3<cr>
^D
envelope<cr>

I tried this:

set qmail_queue [open |/var/qmail/bin/qmail-queue w]
puts $qmail_queue $input_buffer
puts $qmail_queue "\0"
flush $qmail_queue
puts $qmail_queue $envelope_buffer
flush $qmail_queue
if [ catch {
close $qmail_queue
} msg ] {
foreach { - pid code } $::errorCode { break }
puts "exiting with code $code"
exit $code
}
puts "closed"

The problem is, I can not simulate the "eof" character to close the
first file descriptor without using the close command. Once closed, I
can't re-open it to send the remaining data.

Sending "\0" (or "\000" or "" or ... ) does not actually send an EOF
to the file descriptor on the other end of the pipe. When I do send a
close, it takes the spot of the <control-D> in the above shell
simulation. Qmail-queue then expects to read MORE from fd 1 so Tcl's
close thinks that there is buffered data (channel is still readable?)
and the close command blocks indefinitely.

If I hit the return key, then close gets flushed and I get the return
code to print, but it seems IMPOSSIBLE to flush this close command and
have it work properly. This blocking would stop ALL incoming mail so
manually hitting a return key wouldn't cut it...

Any ideas?
 
 
 

Need to close and re-open a process pipeline

Post by Benjamin R » Mon, 12 Jan 2004 23:34:32

Hi Kevin,


XXXX@XXXXX.COM (Kevin McCarthy) writes:

What is your "EOF" character? From your description it sounds like
qmail uses control-D in this situation?


Have you tried control-D? That would be "\4" in Tcl, as we don't have
a special control character syntax.

You also want to use the command [flush] make sure that qmail gets the
information immediately.


Background: In general there is no "EOF" character with streams like
files or pipes on Unix. EOF is just an artefact of the C language, it
is not a real character. Terminals, some printers and some programs
have the concept of a terminating character for individual jobs. In
that situation control-D is often used. There doesn't seem a terminal
or printer involved in this situation, so it's qmail's interpretation
that counts.


benny

 
 
 

Need to close and re-open a process pipeline

Post by lvirde » Tue, 13 Jan 2004 22:15:21


According to Kevin McCarthy < XXXX@XXXXX.COM >:
:qmail-queue reads a mail message from descriptor 0. It then
:reads
:envelope information from descriptor 1.

Wow - it _reads_ information from stdout ?

That's rather ... different.

Perhaps what you need to do is as simple as this.

set fd [open "/tmp/envelope" "w"]
puts $fd "stuff for the envelope"
close $fd

close stdout
set stdout [open "/tmp/envelope" "r"]
set qmail_queue [open |/var/qmail/bin/qmail-queue w]

and so on.

In other words, attach stdout to a file that will contain the info
you want to go to qmail.

Then, in theory, it would read that file at the appropriate time.

Warning - if it tries to output to stdout as well, you will have a problem,
because it won't be able to do it.




--
<URL: http://www.yqcomputer.com/ ; In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto: XXXX@XXXXX.COM > <URL: http://www.yqcomputer.com/ ;