I have a Python script, which runs as a daemon, which uses subprocess to get output from /usr/bin/host. This script runs fine in Ubuntu 18.04 and 20.04 but starting 22.04 the subprocess dies with SIGABRT. Example code to reproduce the issue:
import subprocess
import daemon
from lockfile.pidlockfile import PIDLockFile
def log(msg):
with open("/tmp/outfile","a") as outfile:
outfile.write(msg+'\n')
def test(msg):
log(msg)
try:
output = subprocess.check_output(['/usr/bin/host', '-t', 'srv', '_ldap._tcp.local.hospital.com'], encoding="utf-8")
except Exception as e:
log(str(e))
return
log(output)
return
test("single run")
with daemon.DaemonContext(pidfile=PIDLockFile("/tmp/test.pid")):
test("run as daemon")
log("All done")
On Ubuntu 18.04 and 20.04 the output looks like:
single run
_ldap._tcp.local.hospital.com has SRV record 0 100 636 ad02.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 389 ad02.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 389 ad01.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 636 ad01.local.hospital.com.
run as daemon
_ldap._tcp.local.hospital.com has SRV record 0 100 636 ad02.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 389 ad02.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 389 ad01.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 636 ad01.local.hospital.com.
All done
On Ubuntu 22.04 I get:
single run
_ldap._tcp.local.hospital.com has SRV record 0 100 636 ad02.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 389 ad01.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 389 ad02.local.hospital.com.
_ldap._tcp.local.hospital.com has SRV record 0 100 636 ad01.local.hospital.com.
run as daemon
Command '['/usr/bin/host', '-t', 'srv', '_ldap._tcp.local.hospital.com']' died with <Signals.SIGABRT: 6>.
All done
I tried multiple PC's running 22.04 and got the same result everywhere. Why would the subprocess.check_output give different results running as daemon or not?
Note: I also tried subprocess.Popen and subprocess.run but that does not make any difference.