console owner not catching SIGINT's on 0.5.0?

Garrett Cooper yanegomi at gmail.com
Tue Aug 25 18:56:47 BST 2009


Hi Casey and Scott,

    I'm trying to do the following on 0.5.0 (because we haven't
migrated to anything later than that), and it doesn't function as
expected (even though we have a jobfile that does in fact function as
expected with console output).
    Standalone execution (in typescript format):

Script started on Mon Aug 24 17:33:45 2009
[172:~]$ ./sigintcatcher.py owner^M
[owner] This is SPARTA!^M
Hit CTRL-C now!^M
Tonight we dine at Jeffrey's!^M
[172:~]$
Script done on Mon Aug 24 17:33:56 2009

    Job based execution:

[172:~]$ start console_owner
[172:~]$ [owner] This is SPARTA!
Hit CTRL-C now!

[172:~]$ # Hits enter a few times
[172:~]$
[172:~]$
[172:~]$
[172:~]$ status console_owner
console_owner running
[172:~]$ # Hits enter a few more times
[172:~]$
[172:~]$
[172:~]$
[172:~]$
[172:~]$
[172:~]$
[172:~]$
[172:~]$ # Input hangs here, and CTRL-C emulates return carriages
('\r'), instead of actually being intercepted and sent to the python
script's signal handler.
[172:~]$ # Nothing is printed out in /var/log/messages in relation to
SIGINT, jobs exiting, etc.

    Please see the attached script and jobfile, and let me know
whether or not this functions on a later version of upstart (and hence
whether or not it's a valid bug that we need to track internally). I
wouldn't be entirely surprised if it's because our terminal
distribution is crippled. I've already gotten frustrated with
development over this and have made zero headway on this issue, but if
it's a valid bug with our product I'll hound the developers until it's
fixed.
    Anyhow, please let me know whether or not your results are
successful, on 0.6.x and 0.5.x if possible. Testing on x86 is fine
even though our architecture under test is PPC.
Thanks!
-Garrett

# /etc/init/jobs.d/console_owner:
console owner
script
    sleep 5
    /root/sigintcatcher.py owner
end script

# /root/sigintcatcher.py:

#!/usr/bin/python

import os, signal, sys, time

def sparta(signum, frame):
    print "Tonight we dine at Jeffrey's!"
    sys.exit(130) # 128 + 2 (SIGINT)

def ttystuck(signum, frame):
    sys.exit("Couldn't open tty in a timely manner")

if len(sys.argv) != 2:
    sys.exit(1)

ctype = sys.argv[1]

if ctype == 'owner':
    signal.signal(signal.SIGINT, sparta)

if ctype != 'none':
    signal.signal(signal.SIGALRM, ttystuck)
    signal.alarm(5)
    # This will bomb out if console == none.
    #fd = os.open('/dev/ttyS0', os.O_RDWR)
    signal.alarm(0)
    print "[%s] This is SPARTA!" % ctype
    if ctype == 'owner':
        raw_input("Hit CTRL-C now!\n")
else:
    try:
        time.sleep(30)
    except KeyboardInterrupt:
        pass



More information about the upstart-devel mailing list