Skip to contentSkip to conversation

Is 'iptables-restore' not caching EOF ??

DISCUSSION Lucas Brasilino 1 participant 1 message Jul 25, 2006 netfilter

lore
Share & tools
lore
#0 lore raw

Hi All:

Hope this issue isn't off-topic.
I'm developing a daemon which authenticates a user and creates netfilter rules based on user profile.
Following Harald's advise, during FISL 7.0 here in Brazil, he said to open a pipe to 'iptables-restore --noflush' rather than fork()ing/exec()ing lots of 'iptables' binary. And I'm doing that. My problem is that I fork(), dup2() and execv() 'iptables-restore' and then I write() from parent end of the pipe and close() it, the 'iptables-restore' forked child seems not receiving EOF because it isn't exiting. And I need the exit status to verify if rules was created.

I've tried two way of writing to the pipe and closing it:

First try:

ret = write(CommIptablesRestore[COMM_WRITE], buffer, strlen (buffer)); close(CommIptablesRestore[COMM_WRITE]);

Second try (as of 'iptables-restore' reading code):

FILE *fp = NULL;
fp = fdopen(CommIptablesRestore[COMM_WRITE], "w"); fputs(buffer, fp);
fflush(fp);
fclose(fp);

Where 'CommIptablesRestore[COMM_WRITE]' is the parent end of pipe filedescriptor and 'buffer' stores rules until 'COMMIT\n'.

So after closing my daemon exits and 'iptables-restore' does not exits and stills on sleep status. Using 'strace' I can see that 'iptables-restore' stills read()ing STDIN. So seems it is not caching 'EOF' to exit.

Is that a feature, bug or I'm messing something up?

I didn´t post where a full code snippet to avoid mailing list pollution... but I can send directly.

Thanks a lot in advance.

Signature · 6 lines
[]'s

Lucas Brasilino
[email protected]
Procuradoria da República no Estado de Roraima
+55-95-36239642