Пример #1
0
struct wok_module *
mod_load(const char *path, const char *opts, char *errbuf,
    size_t errlen)
{
	int (*loadf)(struct pscfs *);
	struct wok_module *wm;
	void *h;
	int rc;

	h = dlopen(path, RTLD_NOW);
	if (h == NULL) {
		snprintf(errbuf, LINE_MAX, "%s\n", dlerror()); 
		fprintf(stderr, errbuf);
		return (NULL);
	}

	loadf = dlsym(h, "pscfs_module_load");
	if (loadf == NULL) {
		dlclose(h);
		snprintf(errbuf, LINE_MAX,
		    "symbol pscfs_module_load undefined.\n");
		fprintf(stderr, errbuf);
		return (NULL);
	}

	wm = PSCALLOC(sizeof(*wm));
	wm->wm_path = pfl_strdup(path);
	wm->wm_handle = h;
	wm->wm_opts = pfl_strdup(opts);
	wm->wm_module.pf_private = wm;
	pflfs_module_init(&wm->wm_module, opts);
	rc = loadf(&wm->wm_module);

	/*
	 * XXX XXX XXX
	 * This is a complete hack but this flush somehow avoids a bunch
	 * of zeroes from ending up in the log...
	 * XXX XXX XXX
	 */
	fflush(stderr);

	if (rc) {
		wm->wm_module.pf_handle_destroy = NULL;
		pflfs_module_destroy(&wm->wm_module);

		dlclose(h);
		PSCFREE(wm->wm_path);
		PSCFREE(wm);
		psclog_warnx("module failed to load: rc=%d module=%s",
		    rc, path);
		strlcpy(errbuf, strerror(rc), errlen);
		return (NULL);
	}
	return (wm);
}
Пример #2
0
void
pushfile(struct psc_dynarray *da, char *fn,
    void (*f)(struct psc_dynarray *, char *, int), int arg)
{
	char *p, buf[BUFSIZ];
	FILE *fp;

	fp = fopen(fn, "r");
	if (fp == NULL)
		psync_fatal("%s", fn);
	while (fgets(buf, sizeof(buf), fp)) {
		p = pfl_strdup(buf);
		f(da, p, arg);
	}
	if (ferror(fp))
		psync_fatal("%s", fn);
	fclose(fp);
}
Пример #3
0
void
pfl_register_errno(int code, const char *str)
{
	struct pfl_errno *e;
	uint64_t q;

	q = code;
	e = psc_hashtbl_search(&pfl_errno_hashtbl, &q);
	if (e) {
		pfl_assert(e->code == q);
		pfl_assert(strcmp(e->str, str) == 0);
		return;
	}

	e = PSCALLOC(sizeof(*e));
	e->code = q;
	e->str = pfl_strdup(str);
	psc_hashent_init(&pfl_errno_hashtbl, e);
	psc_hashtbl_add_item(&pfl_errno_hashtbl, e);
}