Example #1
0
int bproc_nodeset_add(struct bproc_node_set_t *ns, struct bproc_node_info_t *n)
{
	if (bproc_nodeset_grow(ns, ns->size + 1))
		return -1;
	ns->node[ns->size++] = *n;
	return 0;
}
Example #2
0
int bproc_nodeset_append(struct bproc_node_set_t *a, struct bproc_node_set_t *b)
{
	int i;
	if (bproc_nodeset_grow(a, a->size + b->size))
		return -1;
	for (i = 0; i < b->size; i++)
		a->node[a->size++] = b->node[i];
	return 0;
}
Example #3
0
int bproc_nodelist_(struct bproc_node_set_t *ns, int fd) {
    int r;
    struct stat statbuf;
    struct pollfd pfd;

    pfd.fd = fd;
    pfd.events = POLLIN;

    /* There's some wackiness possible here.  The machine state might
       change while we're reading the status file.  To guard against
       this, we do a read and then check to see if a change has
       occurred.

       This might be a bit paranoid.
    */

    bproc_nodeset_init(ns, 0);	/* make this safe to use grow */

 again:
    if (fstat(fd, &statbuf))
	return -1;

    if (bproc_nodeset_grow(ns, statbuf.st_size / sizeof(*ns->node))) {
	bproc_nodeset_free(ns);	/* we may have allocated stuff earlier */
	return -1;
    }

    lseek(fd, 0, SEEK_SET);
    r = read(fd, ns->node, statbuf.st_size);
    if (r == -1) {
	bproc_nodeset_free(ns);
	return -1;
    }
    if (r != statbuf.st_size)
	goto again;

    /* explicitly check for changes */
    poll(&pfd, 1, 0);
    if (pfd.revents & POLLIN)
	goto again;

    ns->size = statbuf.st_size / sizeof(*ns->node);
    return ns->size;
}