コード例 #1
0
ファイル: test_ident.c プロジェクト: SnookEE/nvc
END_TEST

START_TEST(test_read_write)
{
   ident_t i1, i2, i3;
   i1 = ident_new("goobar");
   i2 = ident_new("foo");
   i3 = ident_new("foo");

   fbuf_t *f = fbuf_open("test.ident", FBUF_OUT);
   fail_if(f == NULL);

   ident_wr_ctx_t wctx = ident_write_begin(f);

   ident_write(i1, wctx);
   ident_write(i2, wctx);
   ident_write(i3, wctx);

   ident_write_end(wctx);

   fbuf_close(f);

   f = fbuf_open("test.ident", FBUF_IN);
   fail_if(f == NULL);

   ident_rd_ctx_t rctx = ident_read_begin(f);

   ident_t j1, j2, j3;
   j1 = ident_read(rctx);
   j2 = ident_read(rctx);
   j3 = ident_read(rctx);

   ident_read_end(rctx);

   fail_unless(i1 == j1);
   fail_unless(i2 == j2);
   fail_unless(i3 == j3);

   fail_unless(j2 == j3);

   fbuf_close(f);

   remove("test.ident");
}
コード例 #2
0
ファイル: group.c プロジェクト: nickg/nvc
static void group_write_netdb(tree_t top, group_nets_ctx_t *ctx)
{
   char *name = xasprintf("_%s.netdb", istr(tree_ident(top)));

   fbuf_t *f = lib_fbuf_open(lib_work(), name, FBUF_OUT);
   if (f == NULL)
      fatal("failed to create net database file %s", name);

   free(name);

   for (group_t *it = ctx->groups; it != NULL; it = it->next) {
      write_u32(it->gid, f);
      write_u32(it->first, f);
      write_u32(it->length, f);
   }
   write_u32(GROUPID_INVALID, f);

   fbuf_close(f);
}
コード例 #3
0
ファイル: jsio.c プロジェクト: atifs/juise
/*
 * Kill the child process associated with this session.
 */
void
js_session_terminate (js_session_t *jsp)
{
    pid_t pid = jsp->js_pid;
    int count = 0, rc, sig, status;
    js_boolean_t exited = FALSE;

    if (pid > 0) {

	sig = SIGTERM; /* First try graceful kill */

	do {

	    kill(pid, sig);

	    /* Give some time for process to exit. */
	    usleep(1000);

	    do {
		rc = waitpid(pid, &status, WNOHANG);
	    } while (rc < 0 && errno == EINTR);

	    /* 
	     * Check whether the process is still around.
	     *
	     * If the process is around try sending SIGKILL
	     */
	    if (kill(pid, 0)) {
		exited = TRUE; 
		break;
	    }

	    count++;
	    sig = SIGKILL;

	} while (count < 2);

	if (!exited) {
	    /* not able to kill the child process, trace it */
	    jsio_trace("not able to kill child process %d", pid);
	} else {
	    /* trace whether the process exited succesfully or not */
	    jsio_trace("CHLD process %d terminated %s", pid,
		  (WIFEXITED(status) && !WEXITSTATUS(status)) ? 
		  "successfully" : "with failure");
	}
    }

    if (jsp->js_askpassfd > 0)
	close(jsp->js_askpassfd);

    fbuf_close(jsp->js_fbuf);

    close(jsp->js_stdin);
    close(jsp->js_stdout);
    close(jsp->js_stderr);
    fclose(jsp->js_fpout);

    if (jsp->js_hello)
	xmlFreeNode(jsp->js_hello);

    free(jsp->js_creds);
    free(jsp);
}