static void
device_added_cb (NMManager *manager, NMDevice *other, gpointer user_data)
{
	NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (user_data);
	NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);

	if (!priv->companion && check_companion (self, other)) {
		nm_device_state_changed (NM_DEVICE (self),
		                         NM_DEVICE_STATE_DISCONNECTED,
		                         NM_DEVICE_STATE_REASON_NONE);
		nm_device_remove_pending_action (NM_DEVICE (self), "waiting for companion", TRUE);
	}
}
static void
find_companion (NMDeviceOlpcMesh *self)
{
	NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
	const GSList *list;

	if (priv->companion)
		return;

	nm_device_add_pending_action (NM_DEVICE (self), "waiting for companion", TRUE);

	/* Try to find the companion if it's already known to the NMManager */
	for (list = nm_manager_get_devices (nm_manager_get ()); list ; list = g_slist_next (list)) {
		if (check_companion (self, NM_DEVICE (list->data))) {
			nm_device_queue_state (NM_DEVICE (self),
			                       NM_DEVICE_STATE_DISCONNECTED,
			                       NM_DEVICE_STATE_REASON_NONE);
			nm_device_remove_pending_action (NM_DEVICE (self), "waiting for companion", TRUE);
			break;
		}
	}
}
Beispiel #3
0
/*
 * manual --
 *	Search the manuals for the pages.
 */
static int
manual(const char *page, TAG *tag, glob_t *pg)
{
	ENTRY *ep, *e_sufp, *e_tag;
	TAG *missp, *sufp;
	int anyfound, cnt, found;
	char *p, buf[MAXPATHLEN];

	anyfound = 0;
	buf[0] = '*';

	/* Expand the search path. */
	if (f_all != f_where) {
		e_tag = tag == NULL ? NULL : TAILQ_FIRST(&tag->list);
		while (e_tag != NULL) {
			if (glob(e_tag->s, GLOB_BRACE | GLOB_NOSORT,
			    NULL, pg)) {
				/* No GLOB_NOMATCH here due to {arch,}. */
				warn("globbing directories");
				(void)cleanup(0);
				exit(1);
			}
			for (cnt = 0; cnt < pg->gl_pathc; cnt++) {
				if ((ep = malloc(sizeof(ENTRY))) == NULL ||
				    (ep->s = strdup(pg->gl_pathv[cnt])) ==
						NULL) {
					warn(NULL);
					(void)cleanup(0);
					exit(1);
				}
				TAILQ_INSERT_BEFORE(e_tag, ep, q);
			}
			ep = e_tag;
			e_tag = TAILQ_NEXT(e_tag, q);
			free(ep->s);
			TAILQ_REMOVE(&tag->list, ep, q);
			free(ep);
			globfree(pg);
			pg->gl_pathc = 0;
		}
	}

	/* For each element in the list... */
	e_tag = tag == NULL ? NULL : TAILQ_FIRST(&tag->list);
	for (; e_tag != NULL; e_tag = TAILQ_NEXT(e_tag, q)) {
		(void)snprintf(buf, sizeof(buf), "%s/%s.*", e_tag->s, page);
		switch (glob(buf, GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT,
		    NULL, pg)) {
		case (0):
			break;
		case (GLOB_NOMATCH):
			continue;
		default:
			warn("globbing files");
			(void)cleanup(0);
			exit(1);
		}
		if (pg->gl_matchc == 0)
			continue;

		/* Find out if it's really a man page. */
		for (cnt = pg->gl_pathc - pg->gl_matchc;
		    cnt < pg->gl_pathc; ++cnt) {

			if (!f_all || !f_where) {
				check_companion(pg->gl_pathv + cnt, tag);
				if (*pg->gl_pathv[cnt] == '\0')
					continue;
			}

			/*
			 * Try the _suffix key words first.
			 *
			 * XXX
			 * Older versions of man.conf didn't have the suffix
			 * key words, it was assumed that everything was a .0.
			 * We just test for .0 first, it's fast and probably
			 * going to hit.
			 */
			(void)snprintf(buf, sizeof(buf), "*/%s.0", page);
			if (!fnmatch(buf, pg->gl_pathv[cnt], 0))
				goto next;

			e_sufp = (sufp = getlist("_suffix")) == NULL ?
			    NULL : TAILQ_FIRST(&sufp->list);
			for (found = 0;
			    e_sufp != NULL; e_sufp = TAILQ_NEXT(e_sufp, q)) {
				(void)snprintf(buf,
				     sizeof(buf), "*/%s%s", page, e_sufp->s);
				if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
					found = 1;
					break;
				}
			}
			if (found)
				goto next;

			/* Try the _build key words next. */
			e_sufp = (sufp = getlist("_build")) == NULL ?
			    NULL : TAILQ_FIRST(&sufp->list);
			for (found = 0;
			    e_sufp != NULL; e_sufp = TAILQ_NEXT(e_sufp, q)) {
				for (p = e_sufp->s;
				    *p != '\0' && !isspace(*p); ++p);
				if (*p == '\0')
					continue;
				*p = '\0';
				(void)snprintf(buf,
				     sizeof(buf), "*/%s%s", page, e_sufp->s);
				if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
					if (!f_where)
						build_page(p + 1,
						    &pg->gl_pathv[cnt]);
					*p = ' ';
					found = 1;
					break;
				}
				*p = ' ';
			}
			if (found) {
next:				anyfound = 1;
				if (!f_all && !f_where) {
					/* Delete any other matches. */
					while (++cnt< pg->gl_pathc)
						pg->gl_pathv[cnt] = "";
					break;
				}
				continue;
			}

			/* It's not a man page, forget about it. */
			pg->gl_pathv[cnt] = "";
		}

		if (anyfound && !f_all && !f_where)
			break;
	}

	/* If not found, enter onto the missing list. */
	if (!anyfound) {
		sigset_t osigs;

		sigprocmask(SIG_BLOCK, &blocksigs, &osigs);

		if ((missp = getlist("_missing")) == NULL)
			missp = addlist("_missing");
		if ((ep = malloc(sizeof(ENTRY))) == NULL ||
		    (ep->s = strdup(page)) == NULL) {
			warn(NULL);
			(void)cleanup(0);
			exit(1);
		}
		TAILQ_INSERT_TAIL(&missp->list, ep, q);
		sigprocmask(SIG_SETMASK, &osigs, NULL);
	}
	return (anyfound);
}