Exemplo n.º 1
0
static status_t
nfs4_create(fs_volume* volume, fs_vnode* dir, const char* name, int openMode,
	int perms, void** _cookie, ino_t* _newVnodeID)
{
	FileSystem* fs = reinterpret_cast<FileSystem*>(volume->private_volume);

	OpenFileCookie* cookie = new OpenFileCookie(fs);
	if (cookie == NULL)
		return B_NO_MEMORY;
	*_cookie = cookie;

	VnodeToInode* vti = reinterpret_cast<VnodeToInode*>(dir->private_node);
	TRACE("volume = %p, dir = %" B_PRIi64 ", name = %s, openMode = %d,"	\
		" perms = %d", volume, vti->ID(), name, openMode, perms);

	VnodeToInodeLocker _(vti);
	Inode* inode = vti->Get();
	if (inode == NULL)
		return B_ENTRY_NOT_FOUND;

	MutexLocker createLocker(fs->CreateFileLock());

	OpenDelegationData data;
	status_t result = inode->Create(name, openMode, perms, cookie, &data,
		_newVnodeID);
	if (result != B_OK) {
		delete cookie;
		return result;
	}

	result = get_new_vnode(volume, *_newVnodeID, &vti);
	if (result != B_OK) {
		delete cookie;
		return result;
	}

	VnodeToInodeLocker _child(vti);
	Inode* child = vti->Get();
	if (child == NULL) {
		delete cookie;
		put_vnode(volume, *_newVnodeID);
		return B_ENTRY_NOT_FOUND;
	}

	child->SetOpenState(cookie->fOpenState);

	if (data.fType != OPEN_DELEGATE_NONE) {
		Delegation* delegation
			= new(std::nothrow) Delegation(data, child,
				cookie->fOpenState->fClientID);
		if (delegation != NULL) {
			delegation->fInfo = cookie->fOpenState->fInfo;
			delegation->fFileSystem = child->GetFileSystem();
			child->SetDelegation(delegation);
		}
	}

	TRACE("*cookie = %p, *newVnodeID = %" B_PRIi64, *_cookie, *_newVnodeID);
	return result;
}
Exemplo n.º 2
0
VsgPRTree2@t@Node *vsg_prtree2@t@node_key_lookup (VsgPRTree2@t@Node *node,
                                                  VsgPRTreeKey2@t@ key)
{
  vsgloc2 i;
  VsgPRTree2@t@Node *child = NULL;

  if (key.depth == 0 || PRTREE2@T@NODE_ISLEAF(node)) return node;

  i = vsg_prtree_key2@t@_child (&key);

  child = PRTREE2@T@NODE_CHILD(node, i);

  key.depth --;

  return vsg_prtree2@t@node_key_lookup (child, key);
}
Exemplo n.º 3
0
int ist_addlvl (ISTREE *ist, int & nbgen)
{                               /* --- add a level to item set tree */
  int    i, n;                  /* loop variable, counter */
  ISNODE **ndp;                 /* to traverse the nodes */
  ISNODE *node;                 /* new (reallocated) node */
  ISNODE **end;                 /* end of new level node list */
  ISNODE *cur;                  /* current node in new level */
  ISNODE *frst;                 /* first child of current node */
  ISNODE *last;                 /* last  child of current node */
  ISNODE **vec;                 /* child node vector */
  void   *p;                    /* temporary buffer */

  assert(ist);                  /* check the function arguments */

  /* --- enlarge level vector --- */
  if (ist->lvlcnt >= ist->lvlvsz) { /* if the level vector is full */
    n = ist->lvlvsz +BLKSIZE;   /* compute new vector size */
    p = realloc(ist->levels, n *sizeof(ISNODE*));
    if (!p) return -1;          /* enlarge the level vector */
    ist->levels = (ISNODE**)p;  /* and set the new vector */
    p = realloc(ist->buf,    n *sizeof(int));
    if (!p) return -1;          /* enlarge the buffer vector */
    ist->buf    = (int*)p;      /* and set the new vector */
    ist->lvlvsz = n;            /* set the new vector size */
  }                             /* (applies to buf and levels) */
  end  = ist->levels +ist->lvlcnt;
  *end = NULL;                  /* start a new tree level */

  /* --- add tree level --- */
  for (ndp = ist->levels +ist->lvlcnt -1; *ndp; ndp = &(*ndp)->succ) {
    frst = last = NULL;         /* traverse the deepest nodes */
    for (i = n = 0; i < (*ndp)->size; i++) {
      cur = _child(ist, *ndp, i, nbgen);
      if (!cur) continue;       /* create a child if necessary */
      if (cur == (void*)-1) { _cleanup(ist); return -1; }
      if (!frst) frst = cur;    /* note first and last child node */
      *end = last = cur;        /* add node at the end of the list */
      end  = &cur->succ; n++;   /* that contains the new level */
    }                           /* and advance end pointer */
    if (n <= 0) {               /* if no child node was created, */
      (*ndp)->chcnt = F_SKIP; continue; }       /* skip the node */
    node = *ndp;                /* decide on the node structure: */
    n = last->id -frst->id +1;  /* always add a pure child vector */
    i = (node->size -1) *sizeof(int) +n *sizeof(ISNODE*);
    node = (ISNODE*)realloc(node, sizeof(ISNODE) +i);
    if (!node) { _cleanup(ist); return -1; }
    node->chcnt = n;            /* add a child vector to the node */
    if ((node != *ndp) && node->parent) {
      last = node->parent;      /* adapt the ref. from the parent */
      vec  = (ISNODE**)(last->cnts +last->size);
      vec[(vec[0] != *ndp) ? node->id -vec[0]->id : 0] = node;
    }                           /* set the new child pointer */
    *ndp = node;                /* set new (reallocated) node */
    vec = (ISNODE**)(node->cnts +node->size);
    while (--n >= 0) vec[n] = NULL;
    i = frst->id;               /* get item identifier of first child */
    for (cur = frst; cur; cur = cur->succ) {
      vec[cur->id -i] = cur;    /* set the child node pointer */
      cur->parent     = node;   /* and the parent pointer */
    }                           /* in the new node */
  }
  if (!ist->levels[ist->lvlcnt])/* if no child has been added, */
    return 1;                   /* abort the function, otherwise */
  ist->lvlcnt++;                /* increment the level counter */
  ist->tacnt = 0;               /* clear the transaction counter and */
  ist->node  = NULL;            /* the item set node for rule extr. */
  _stskip(ist->levels[0]);      /* mark subtrees to be skipped */
  return 0;                     /* return 'ok' */
}  /* ist_addlvl() */
Exemplo n.º 4
0
int ist_addlvl (ISTREE *ist)
{                               /* --- add a level to item set tree */
	int      i, vsz;              /* loop variable, buffer */
	ISNODE   **plf;               /* to traverse the leaves */
	ISNODE   *leaf;               /* new (reallocated) leaf node */
	ISNODE   **end;               /* end of new level node list */
	ISNODE   *nnew;                /* current node in new level */
	ISNODE   *frst;               /* first child of current leaf */
	ISNODE   *last;               /* last  child of current leaf */
	ISNODE   **vec;               /* child node vector */
	double s_min;               /* minimal support of a set */
	double s_sub;               /* minimal support of a subset */
	void     *tmp;                /* temporary buffer */

	assert(ist && ist->levels && ist->path);  /* check arguments */

	/* --- enlarge level vector --- */
	if (ist->height >= ist->vecsize) {  /* if the level vector is full */
		vsz = ist->vecsize +BLKSIZE;/* compute new vector size */
		tmp = realloc(ist->levels, vsz*sizeof(ISNODE*));
		if (!tmp) return -1;        /* enlarge the level vector */
		ist->levels = (ISNODE**)tmp;/* and set the new vector */
		tmp = realloc(ist->path,   vsz *sizeof(int));
		if (!tmp) return -1;        /* enlarge the path vector */
		ist->path = (int*)tmp; ist->vecsize = vsz;
	}                             /* set new path vector and its size */
	end  = ist->levels +ist->height;
	*end = NULL;                  /* start a new tree level */

	/* --- add tree level --- */
	s_sub = ist->supp;
	if (s_sub < 1) s_sub = 1;     /* minimal support of a subset */
	if (ist->rsdef == IST_BOTH)   /* if rule supp. = body&head support */
		s_min = s_sub;              /* use the subset support */
	else {                        /* if rule supp. = body support */
		s_min = ist->supp *ist->setcnt;
		if (s_min < 1) s_min = 1;   /* use the full set support */
	}
	plf = ist->levels +ist->height -1;    /* traverse leaf nodes */
	for ( ; *plf; plf = &(*plf)->succ) {
		frst = last = NULL;         /* traverse counter vector */
		for (i = 0; i < (*plf)->size; i++) {
			nnew = _child(ist, *plf, (*plf)->offs +i, s_min, s_sub);
			if (!nnew) continue;       /* create a child, if necessary */
			if (nnew == (void*)-1) { _cleanup(ist); return -1; }
			if (!frst) frst = nnew;    /* note first and last child node */
			*end = last = nnew;        /* add node at the end of the list */
			end  = &nnew->succ;        /* that contains the new level */
		}                           /* and advance end pointer */
		if (!frst) continue;        /* if no child node created, continue */
		vsz  = ID(last) -ID(frst) +1;/* compute size of child node vector */
		leaf = (ISNODE*)realloc(*plf, sizeof(ISNODE)
														+ i*2*sizeof(float)
														+ (vsz)   *sizeof(ISNODE*));
		leaf->cnts=(float*)((char*)leaf+sizeof(ISNODE));
		leaf->occ_square = (float*)leaf->cnts+i;
		if (!leaf) { _cleanup(ist); return -1; }
		leaf->chcnt = vsz;          /* add a child node vector to the */
		/* current leaf and set its size */
		if (leaf->parent) {         /* if the current leaf has a parent */
			vec = (ISNODE**)(leaf->parent->cnts +2*leaf->parent->size);
			vec[(vec[0] != *plf) ? ID(leaf) -ID(vec[0]) : 0] = leaf;
		}                           /* adapt pointer from parent node */
		*plf = leaf;                /* set new (reallocated) leaf node */
		vec  = (ISNODE**)(leaf->cnts +2*leaf->size);
		for (i = vsz; --i >= 0; ) vec[i] = NULL;
		i = ID(frst);               /* get item identifier of first child */
		for (nnew = frst; nnew; nnew = nnew->succ) {
			vec[ID(nnew) -i] = nnew;    /* set child node pointers */
			nnew->parent     = leaf;   /* and adapt parent pointers */
		}
	}
	if (!ist->levels[ist->height])/* if no child added, */
		return 1;                   /* abort the function */
	ist->height++;                /* otherwise increment tree height */
	ist_clear(ist);               /* and clear the item set tree */
	return 0;                     /* return 'ok' */
}  /* ist_addlvl() */
Exemplo n.º 5
0
void
daemon_t::_parent(
) {

    // http://www.freedesktop.org/software/systemd/man/daemon.html

    pipe_t c_pipe( "child"  );
    pipe_t g_pipe( "grandchild" );

    // TODO: Reset signal handlers?
    // TODO: Reset signal mask?
    // TODO: Sanitize environment?

    pid_t pid = 0;

    ESYSCALL(
        "forking child",
        "fork",
        pid = fork(),
        pid >= 0,
        "child forked " << ( pid == 0 ? "(i am child)" : "(i am parent)" )
    );

    if ( pid == 0 ) {
        _child( c_pipe, g_pipe );
        return;     // TODO: Or exit?
    };

    c_pipe.writer().close();
    g_pipe.writer().close();

    int error = 0;

    ESYSCALL(
        "anti-zombying child",
        "waitpid",
        error = waitpid( pid, NULL, WNOHANG ),
        error != -1,
        "child anti-zombied"
    );

    // Wait until child finishes initialization.
    string_t c_reply = c_pipe.reader().read();
    string_t g_reply = g_pipe.reader().read();

    // Report errors, if any.
    if ( c_reply != ok || g_reply != ok ) {
        osstream_t errors;
        if ( c_reply != ok ) {
            errors << "Child: ";
            if ( c_reply.empty() ) {
                errors << "Died silently";
            } else {
                errors << split( "\n", c_reply );
            };
        }; // if
        if ( g_reply != ok ) {
            if ( ! errors.str().empty() ) {
                errors << "; ";
            };
            errors << "Grandchild: ";
            if ( g_reply.empty() ) {
                errors << "Died silently";
            } else {
                errors << split( "\n", g_reply );
            };
        }; // if
        ERR(
            1,
            "Daemon initialization failed: " << errors.str()
        );
    }; // if

    c_pipe.reader().close();
    g_pipe.reader().close();

}; // _parent
Exemplo n.º 6
0
const
size_t assemble(
		uint8_t *const bytecode,
		const size_t bytecode_sz,
		const char *const assembly,
		const size_t asm_sz)
{
	char path[PATH_MAX];
	snprintf(path, sizeof(path), "/tmp/rappel-input.XXXXXX");

	const int t = mkstemp(path);

	if (t == -1) {
		perror("mkstemp");
		exit(EXIT_FAILURE);
	}

	REQUIRE (unlink(path) == 0);

	dprintf(t, BITSTR);
	dprintf(t, "section .text vstart=%ld\n", options.start);

	write_data(t, (uint8_t *)assembly, asm_sz);

	int fildes[2];
	REQUIRE (pipe(fildes) == 0);

	const pid_t asm_pid = fork();

	if (asm_pid < 0) {
		perror("fork");
		exit(EXIT_FAILURE);
	} else if (asm_pid == 0) {
		_child(fildes, t);
		// Not reached
		abort();
	}

	verbose_printf("nasm is pid %d\n", asm_pid);

	REQUIRE (close(fildes[1]) == 0);

	mem_assign(bytecode, bytecode_sz, TRAP, TRAP_SZ);

	size_t sz = read_data(fildes[0], bytecode, bytecode_sz);

	if (sz >= bytecode_sz) {
		fprintf(stderr, "Too much bytecode to handle, exiting...\n");
		exit(EXIT_FAILURE);
	}

	int status;
	REQUIRE (waitpid(asm_pid, &status, 0) != -1);

	if (WIFSIGNALED(status))
		fprintf(stderr, "nasm exited with signal %d.\n", WTERMSIG(status));
	else if (WIFEXITED(status) && WEXITSTATUS(status))
		fprintf(stderr, "nasm exited %d.\n", WEXITSTATUS(status));

	REQUIRE (close(t) == 0);

	return sz;
}