Beispiel #1
0
static gboolean
dhcpcd_try_open(gpointer data)
{
	DHCPCD_CONNECTION *con;
	int fd;
	static int last_error;

	con = (DHCPCD_CONNECTION *)data;
	fd = dhcpcd_open(con, true);
	if (fd == -1) {
		if (errno == EACCES || errno == EPERM) {
			if ((fd = dhcpcd_open(con, false)) != -1)
				goto unprived;
		}
		if (errno != last_error) {
			g_critical("dhcpcd_open: %s", strerror(errno));
			last_error = errno;
		}
		return TRUE;
	}

unprived:
	if (!dhcpcd_watch(fd, dhcpcd_cb, con)) {
		dhcpcd_close(con);
		return TRUE;
	}

	/* Start listening to WPA events */
	dhcpcd_wpa_start(con);

	return FALSE;
}
void DhcpcdQt::tryOpen() {
	int fd = dhcpcd_open(con, true);
	static int last_error;

	if (fd == -1) {
		if (errno == EACCES || errno == EPERM) {
			if ((fd = dhcpcd_open(con, false)) != -1)
				goto unprived;
		}
		if (errno != last_error) {
		        last_error = errno;
			const char *errt = strerror(errno);
			qCritical("dhcpcd_open: %s", errt);
			trayIcon->setToolTip(
			    tr("Error connecting to dhcpcd: %1").arg(errt));
		}
		if (retryOpenTimer == NULL) {
			retryOpenTimer = new QTimer(this);
			connect(retryOpenTimer, SIGNAL(timeout()),
			    this, SLOT(tryOpen()));
			retryOpenTimer->start(DHCPCD_RETRYOPEN);
		}
		return;
	}

unprived:
	/* Start listening to WPA events */
	dhcpcd_wpa_start(con);

	if (retryOpenTimer) {
		retryOpenTimer->stop();
		retryOpenTimer->deleteLater();
		retryOpenTimer = NULL;
	}

	notifier = new QSocketNotifier(fd, QSocketNotifier::Read);
	connect(notifier, SIGNAL(activated(int)), this, SLOT(dispatch()));

	preferencesAction->setEnabled(dhcpcd_privileged(con));
}