Ejemplo n.º 1
0
/*
 * Add an item to a dynamic array unless it already exists in the array.
 * @pda: dynamic array to add to.
 * @item: element to add.
 * Returns 1 if already existent, -1 on failure, or zero on
 * nonexistence.
 */
int
psc_dynarray_add_ifdne(struct psc_dynarray *pda, void *item)
{
	if (psc_dynarray_exists(pda, item))
		return (1);
	return (psc_dynarray_add(pda, item));
}
Ejemplo n.º 2
0
void
psc_subsys_register(int ssid, const char *name)
{
	struct psc_subsys *ss;
	char *p, buf[BUFSIZ];
	int nss;

	nss = psc_dynarray_len(&psc_subsystems);
	ss = psc_alloc(sizeof(*ss), PAF_NOLOG);
	ss->pss_name = name;

	snprintf(buf, sizeof(buf), "PSC_LOG_LEVEL_%s", name);
	p = getenv(buf);
	if (p) {
		ss->pss_loglevel = psc_loglevel_fromstr(p);
		if (ss->pss_loglevel == PNLOGLEVELS)
			psc_fatalx("invalid %s value", name);
	} else {
		ss->pss_loglevel = psc_log_getlevel_global();
		if (ssid == PSS_TMP)
			ss->pss_loglevel = PLL_DEBUG;
	}

	snprintf(buf, sizeof(buf), "PSC_SYSLOG_%s", name);
	if (getenv(buf) || getenv("PSC_SYSLOG")) {
		static int init;

		if (!init) {
			extern const char *__progname;
			const char *ident = __progname;

			init = 1;
			p = getenv("PFL_SYSLOG_IDENT"); 
			if (p) {
				static char idbuf[32];

				ident = idbuf;
				(void)FMTSTR(idbuf, sizeof(idbuf), p,
				    FMTSTRCASE('n', "s", __progname)
				);
			}
			openlog(ident, LOG_CONS | LOG_NDELAY | LOG_PID,
			    LOG_DAEMON);
		}

		pfl_syslog = psc_realloc(pfl_syslog,
		    sizeof(*pfl_syslog) * (nss + 1), PAF_NOLOG);
		pfl_syslog[nss] = 1;
	}

	if (ssid != nss)
		psc_fatalx("bad ID %d for subsys %s [want %d], "
		    "check order", ssid, name, nss);
	psc_dynarray_add(&psc_subsystems, ss);
}
Ejemplo n.º 3
0
/*
 * Duplicate items in one dynarray to another.
 * @pda: dynamic array to copy to.
 * @src: dynamic array to copy from.
 */
int
psc_dynarray_concat(struct psc_dynarray *pda,
    const struct psc_dynarray *src)
{
	int rc, i;

	for (i = 0; i < psc_dynarray_len(src); i++) {
		rc = psc_dynarray_add(pda, psc_dynarray_getpos(src, i));
		if (rc)
			return (rc);
	}
	return (0);
}
Ejemplo n.º 4
0
int
main(int argc, char *argv[])
{
	char c, *p, *noncanon_mp, *cmd, *path_env, dir[PATH_MAX];
	struct pscfs_args args = PSCFS_ARGS_INIT(0, NULL);
	struct psc_dynarray startup_cmds = DYNARRAY_INIT;
	const char *progpath = argv[0];
	int rc, i, unmount_first = 0;

	pfl_init();

	pscfs_addarg(&args, "");		/* progname/argv[0] */
	pscfs_addarg(&args, "-o");
	pscfs_addarg(&args, STD_MOUNT_OPTIONS);

	p = getenv("CTL_SOCK_FILE");
	if (p)
		ctlsockfn = p;

	while ((c = getopt(argc, argv, "dL:o:S:U")) != -1)
		switch (c) {
		case 'd':
			pscfs_addarg(&args, "-odebug");
			break;
		case 'L':
			psc_dynarray_add(&startup_cmds, optarg);
			break;
		case 'o':
			if (!opt_lookup(optarg)) {
				pscfs_addarg(&args, "-o");
				pscfs_addarg(&args, optarg);
			}
			break;
		case 'S':
			ctlsockfn = optarg;
			break;
		case 'U':
			unmount_first = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;
	if (argc != 1)
		usage();

	pscthr_init(PFL_THRT_FSMGR, NULL, 0, "fsmgrthr");

	noncanon_mp = argv[0];
	if (unmount_first)
		unmount(noncanon_mp);

	/* canonicalize mount path */
	if (realpath(noncanon_mp, mountpoint) == NULL)
		psc_fatal("realpath %s", noncanon_mp);

	pscfs_mount(mountpoint, &args);
	pscfs_freeargs(&args);

	ctlthr_spawn();

	pfl_opstimerthr_spawn(PFL_THRT_OPSTIMER, "opstimerthr");
	pfl_workq_init(128, 1024, 1024);
	pfl_wkthr_spawn(PFL_THRT_WORKER, 4, 0, "wkthr%d");

	pscfs_entry_timeout = 8.;
	pscfs_attr_timeout = 8.;

	/*
	 * Here, $p = (directory this daemon binary resides in).
	 * Now we add the following to $PATH:
	 *
	 *   1) $p
	 *   2) $p/../wokctl (for developers)
	 */
	pfl_dirname(progpath, dir);
	p = getenv("PATH");
	rc = pfl_asprintf(&path_env, "%s:%s/../wokctl%s%s", dir, dir,
	    p ? ":" : "", p ? p : "");
	psc_assert(rc != -1);
	setenv("PATH", path_env, 1);

	/*
 	 * If wokctl (see file wokctl.c) misbehaves because it is given 
 	 * a wrong arugment, it is hard to debug from our end because 
 	 * we won't be receiving anything useful via the socket. This 
 	 * should be changed to a native call someday.
 	 *
 	 * If the client does not come up, double/triple checkout 
 	 * the name of your slash2 shared library. I wish I can
 	 * add more verbose debugging information.
 	 */
	DYNARRAY_FOREACH(cmd, i, &startup_cmds)
		pfl_systemf("wokctl -S %s %s", ctlsockfn, cmd);

	exit(pscfs_main(32, ""));
}
Ejemplo n.º 5
0
void
visit(__unusedx void *data, struct pfl_odt_receipt *r,
    void *arg)
{
	char buf[LINE_MAX], *p = data;
	struct pfl_odt **t = arg;
	static int shown_hdr;
	union {
		int	*d;
		int64_t	*q;
		void	*p;
	} u;
	size_t i;

	if (num_free) {
		struct pfl_odt_receipt *rdup;

		rdup = PSCALLOC(sizeof(*rdup));
		memcpy(rdup, r, sizeof(*r));
		psc_dynarray_add(&rcpts, rdup);
		num_free--;
	}

	if (!show)
		return;

	if (!shown_hdr) {
		struct pfl_odt_hdr *h;

		h = (*t)->odt_hdr;
		printf("nelems\t%u\n", h->odth_nelems);
		printf("elemsz\t%u\n", h->odth_objsz);
		printf("%7s %16s data\n", "slot", "crc");
		shown_hdr = 1;
	}

	printf("%7zd %16"PRIx64" ", r->odtr_elem, r->odtr_crc);

	if (fmt) {
		(void)FMTSTR(buf, sizeof(buf), fmt,
		    FMTSTRCASE('d', "d",	(u.p = p, p += sizeof(int),	*u.d))
		    FMTSTRCASE('u', "u",	(u.p = p, p += sizeof(int),	*u.d))
		    FMTSTRCASE('x', "x",	(u.p = p, p += sizeof(int),	*u.d))
		    FMTSTRCASE('q', PRId64,	(u.p = p, p += sizeof(int64_t),	*u.q))
		    FMTSTRCASE('Q', PRIu64,	(u.p = p, p += sizeof(int64_t),	*u.q))
		    FMTSTRCASE('X', PRIx64,	(u.p = p, p += sizeof(int64_t),	*u.q))
		);
		printf("%s\n", buf);
		return;
	}

	/*
	 * If the first 10 characters aren't ASCII, don't display as
	 * such.
	 */
	for (i = 0, p = data; i < 10 && p; i++, p++)
		if (!isspace(*p) && !isgraph(*p))
			goto skip;
	if (i != 10)
		goto skip;
	printf("%s\n", (char *)data);
	return;

 skip:
	for (i = 0, p = data; i < elem_size; p++, i++)
		printf("%02x", *p);
	printf("\n");
}