TNG / inet_aton
Edgar, Bob
bob.edgar at CommerzbankIB.com
Fri Jan 14 18:17:49 GMT 2000
This code is broken. You (the parent) are waiting for your own PID.
The if(fork()) is also broken. If the fork() fails, it returns -1
and sets errno for the reason.
switch(pid=fork()){
case 0: // child
case -1: // error
default: // parent
}
>From the Solaris man page:
If pid is equal to (pid_t)-1, status is requested for
any child process.
If pid is greater than (pid_t)0, it specifies the pro-
cess ID of the child process for which status is
requested.
If pid is equal to (pid_t)0 status is requested for any
child process whose process group ID is equal to that
of the calling process.
If pid is less than (pid_t)-1, status is requested for
any child process whose process group ID is equal to
the absolute value of pid.
bob
-----Original Message-----
From: Steve Langasek [mailto:vorlon at netexpress.net]
Sent: Friday, January 14, 2000 12:28 AM
To: Multiple recipients of list SAMBA-TECHNICAL
Subject: Re: TNG / inet_aton
On Fri, 14 Jan 2000, Luke Kenneth Casson Leighton wrote:
> can someone evaluate this, i have no idea if it's correct [the fork()
> bit].
I can't speak for Solaris, and I'm not sure what POSIX says about waitpid(),
but this would not be correct in the Linux implementation of waitpid().
Under
Linux, the first argument to waitpid() is typically the pid of the process
that you're waiting for (it can take other values with special meaning).
-Steve Langasek
postmodern programmer
> > One thing I did change in the code, which I *think* fixed a problem with
> > printing ... I noticed errors to the effect of "Running command
> > 'lpstat -o<queue>' returned -1". I traced this to the following bit of
> > lib/smbrun.c :
> > if ((pid=fork())) {
> > int status=0;
> > /* the parent just waits for the child to exit */
> > if (sys_waitpid(pid,&status,0) != pid) {
> > DEBUG(2,("waitpid(%d) :
%s\n",pid,strerror(errno)));
> > return -1;
> > }
> > return status;
> > }
> > Bearing in mind that I know nothing about fork()ing, I had a look at
this,
> > and waitpid(2), and decided that it was waiting on the wrong process -
it
> > should be waiting on *children* of the main process to exit, not
children
> > of the *child*. I changed it to:
> > if (sys_waitpid(getpid(),&status,0) != pid) {
> > and the error went away! And I could print! As I say, I'm not familiar
with
> > this sort of code, so I could be completely wrong, and just fluked
getting
> > the print jobs though :)
> > Anyway, I hope this helps ... the server is Solaris 7, and I'm using
SYSV
> > printing with "printcap name = lpstat".
More information about the samba-technical
mailing list