[Twisted-Python] [andrea at cpushare.com: Re: error after launching cpushare client]

Andrea Arcangeli andrea at cpushare.com
Thu Aug 4 03:14:28 EDT 2005


On Thu, Aug 04, 2005 at 08:47:39AM +0300, Tommi Virtanen wrote:
> Andrea Arcangeli wrote:
> > Ok but then do you have an idea where the 139 comes from? I'd like to
> > understand what's going on, to me that 139 number comes out of the blue.
> 
> 139 == 128 + 11.
> 
> One way to set up the numbering is that exit codes are 0..127, signals
> etc. have hight bit set.
> 
> Naturally, all real access should go through the macros WIFEXITED etc,
> but that's how the number ranges are classically set up.

Ah, I think I got why he gets 139, that's because the core dumping was
enabled.

> >>Actual .status values are unportable, thus transferring them raw over
> >>the network is not a good idea.
> > 
> > status should be the same that waitpid returns, from the docs:
> > 
> > "return a tuple containing its pid and exit status indication: a 16-bit
> > number, whose low byte is the signal number that killed the process, and
> > whose high byte is the exit status (if the signal number is zero); the
> > high bit of the low byte is set if a core file was produced.
> > Availability: Unix."
> 
> I think you are reading about os.wait and twisted is using
> os.waitpid. Otherwise, the document is lying to you. The status _may_ be

Yes, the status is the same in wait and waitpid, and it's the same as
well in C (I doubt that python does any mangling of the C value).

> laid out like that on _some_ platform, but unless python does some
> readjustment, the only portable way to access it is WIFEXITED and
> friends.

It's not like I've an huge portability, because seccomp currently
only available on linux, but I'll follow your suggestion and I'll try to
make it more portable.

> cat >crash.c <<EOF
> int main(void) {
>   /* comment out the next line if you want a normal exit */
>   *(char*)0 = 42;
>   return 34;
> }
> EOF
> cat >run.py <<EOF
> #!/usr/bin/python
> import os
> 
> pid = os.fork()
> if pid:
>     # parent
>     pid, status = os.waitpid(pid, 0)
>     print pid, status
>     if os.WIFEXITED(status):
>         print 'exited', os.WEXITSTATUS(status)
>     elif os.WIFSIGNALED(status):
>         print 'signaled', os.WTERMSIG(status)
>         print 'coredump', os.WCOREDUMP(status)
>     elif os.WIFSTOPPED(status):
>         print 'stopped', os.WSTOPSIG(status)
>     elif os.WIFCONTINUED(status):
>         print 'continued'
>     else:
>         print 'unknown'
> else:
>     # child
>     os.execv('./a.out', ['a.out'])
>     raise RuntimeError, "exec failed"
> EOF
> chmod a+x run.py
> gcc -Wall crash.c
> ./run.py

Ok thanks a lot for the example.

> Exactly. If a process exits due to a signal, there is no exit code in
> the sense of calling _exit(2).

Ok, same as with C.




More information about the Twisted-Python mailing list