PDA

View Full Version : Qt app. DNS resolution fails when started on system startup using upstart



SimpleQtDev
24th May 2010, 03:45
Hi all,

I have currently using Ubuntu Linux 10.04 LTS (x86-64), using Qt from Ubuntu's software distribution (Qt v4.6.2).

I have an application that needs to start on system startup. So I am using Ubuntu's upstart to start the the application.

This application performs a DNS resolution (hostname to IP) which is failing if started using upstart, but works once I run the application on Terminal when I log in; I've made sure the upstart job starts on Ubuntu's Run Level 2.

The specific Qt API I am using is QHostInfo::fromName. The specific error (obtained via QHostInfo.error() and QHostInfo.errorString() instance methods) is Host not found.

I thought it was a Ubuntu's run level problem, so I try to issue a dig command in the upstart job to see if that works; dig works fine, just my app. doesn't.

Another strange thing. Even if the DNS resolution works (when I run it on Terminal after logging in), the error message from QHostInfo is Unknown error

I have attached the Qt Creator project with the section of app. in question (binary to be placed in /usr/local/bin for this upstart script). As well I've attached my Ubuntu upstart script (to be placed in /etc/init and its I/O streams directed to /var/log/qthostnameres/log.log - a file which should be created beforehand).

I've also attempted to run the app. as a non-admin. user using su but get the same error result.

Any past experiences, solutions, suggestions? Have I done something really silly here?

Thanks.

norobro
25th May 2010, 05:17
Works like a charm on my Debian Sid box. I have been putting off migrating to a dependency based boot system for no apparent reason, so I decided to take the plunge and test your app at the same time.
From log.log

DEBUG from main method - Hostname to resolve is "www.google.com"
DEBUG from HostnameResolver::Dns2ip - fromName result: "Unknown error"
DEBUG from HostnameResolver::Dns2ip - Number of IP addresses: "4"
"0" - "72.14.204.104"
"1" - "72.14.204.147"
"2" - "72.14.204.99"
"3" - "72.14.204.103"
www.google.com:72.14.204.104

Regarding the "Unknown error", from the docs:
QString QHostInfo::errorString () const
If the lookup failed, this function returns a human readable description of the error; otherwise "Unknown error" is returned.QHostInfo::error() returns 0 which is "QHostInfo::NoError".