-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 09 Jun 2004 18:52:16 +0300, Shachar Shemesh <[EMAIL PROTECTED]> wrote: > > I'm trying to provide a library call that will run a ping to a server. > The catch is that it needs to be done as a non-root user, and I would > like to avoid any solution that involves any SUID or root running > processes beyond what is already there. That leaves me, pretty much, "ping". > > The catch is that I get a timeout value, and I'm asked to abort if the > operation is not complete within that time (and report status). > The code I'm using is doing the following (pseudo code warning): > block sigchld > fork > (child - execve ping -c 1 -n -q hostname) > pselect for timeout or sigchld > kill INT the ping > waitpid to get status. > > Now here's the thing. Sometimes, I can see that the ping returned fairly > immediately, but the full timeout was spent. I suspect that, due to the > fact pselect is not a system call in Linux, ping has indeed finished > before the pselect, and the signal got lost. Does anyone have any > alternative solutions to implement what I'm doing here?
Caution: untested suggestion. You can use alarm(2) in the child process before `exec'ing the ping. Then it either will finish normally (exit 0) or will fail for any reason (including SIGALRM). In this way, you can use blocking `waitpid' in the parent process. If you try my suggestion, please report here. Ehud. - -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ GnuPG: 98EA398D <http://www.keyserver.net/> Better Safe Than Sorry -----BEGIN PGP SIGNATURE----- Comment: use http://www.keyserver.net/ to get my key (and others) iD8DBQFAxzhOLFvTvpjqOY0RArabAJ9iou6EvalHqMyra4Av/MkKsbCnrQCfYVnb vWKutl3XTrNW/v37LGF1jYE= =s+VT -----END PGP SIGNATURE----- ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
