[Clamav-devel] proposed patch - fork() instead of system() for OnError/UpdateExecute

2005-02-25 Thread Per Jessen
I posted this on the user-lists - 

Here is a patch for clamav-0.83: 
http://jessen.ch/files/patch-clamav-0.83-freshclam-with-fork


With this, freshclam will use a fork() for OnErrorExecute and OnUpdateExecute 
when it's 
running as a daemon - as commandline it will still use system(). 

Comments?


/Per Jessen, Zürich


___
http://lurker.clamav.net/list/clamav-devel.html


Re: [Clamav-devel] proposed patch - fork() instead of system() for OnError/UpdateExecute

2005-02-25 Thread Laurent Wacrenier
Le Ven 25 fév 12:50:46 2005, Per Jessen écrit:
 I posted this on the user-lists - 
 
 Here is a patch for clamav-0.83: 
 http://jessen.ch/files/patch-clamav-0.83-freshclam-with-fork
 
 
 With this, freshclam will use a fork() for OnErrorExecute and OnUpdateExecute 
 when it's 
 running as a daemon - as commandline it will still use system(). 
 
 Comments?

What's the trouble with system() ?

- The system shell may not be /bin/sh everywhere.
- You should check if fork() returns -1
- You should wait for the child pid instead of any child
  and loop on waitpid().
- As waitpid() is called once with the WNOHANG flags,
  you may have some zombie process, or if a bogus child never exits,
  you will have tons of childs and your process table will be full.
- I'm unsure if freshclam use mutex threads. If it does,
  it may be safer to handle them in a pthread_atfork() callback
  if you want use them when the exec() fails.

___
http://lurker.clamav.net/list/clamav-devel.html