Esempio n. 1
0
void initLeuart(void)
{
  static uint8_t leu_raw_tx_buf[300];
  static uint8_t leu_raw_rx_buf[300];

  leu_tx_buf = init_buf(leu_raw_tx_buf, sizeof(leu_raw_tx_buf));
  leu_rx_buf = init_buf(leu_raw_rx_buf, sizeof(leu_raw_rx_buf));

  CMU_ClockEnable(cmuClock_CORELE, true);
  CMU_ClockEnable(cmuClock_GPIO, true);
  CMU_ClockEnable(cmuClock_LEUART0, true);

  LEUART_Reset(LEUART0);
  LEUART_Init(LEUART0, &leuart0Init);
  LEUART0->ROUTE = LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN | LEUART_ROUTE_LOCATION_LOC0;

  /* Enable GPIO for LEUART0. RX is on D5 */
  GPIO_PinModeSet(gpioPortD,            /* Port */
                  5,                    /* Port number */
                  gpioModeInputPull,    /* Pin mode is set to input only, with pull direction given bellow */
                  1);                   /* Pull direction is set to pull-up */

  /* Enable GPIO for LEUART0. TX is on D4 */
  GPIO_PinModeSet(gpioPortD,                /* GPIO port */
                  4,                        /* GPIO port number */
                  gpioModePushPull,         /* Pin mode is set to push pull */
                  1);                       /* High idle state */

  LEUART0->IEN = LEUART_IF_RXDATAV;  // enable RX interrupt
  NVIC_EnableIRQ(LEUART0_IRQn);
}
Esempio n. 2
0
/*
 * pack_all_front_end - dump all front_end node information for all nodes
 *	in machine independent form (for network transmission)
 * OUT buffer_ptr - pointer to the stored data
 * OUT buffer_size - set to size of the buffer in bytes
 * IN protocol_version - slurm protocol version of client
 * NOTE: the caller must xfree the buffer at *buffer_ptr
 * NOTE: READ lock_slurmctld config before entry
 */
extern void pack_all_front_end(char **buffer_ptr, int *buffer_size, uid_t uid,
			       uint16_t protocol_version)
{
	time_t now = time(NULL);
	uint32_t nodes_packed = 0;
	Buf buffer;
#ifdef HAVE_FRONT_END
	uint32_t tmp_offset;
	front_end_record_t *front_end_ptr;
	int i;

	buffer_ptr[0] = NULL;
	*buffer_size = 0;

	buffer = init_buf(BUF_SIZE * 2);
	nodes_packed = 0;

	if (protocol_version >= SLURM_2_5_PROTOCOL_VERSION) {
		/* write header: count and time */
		pack32(nodes_packed, buffer);
		pack_time(now, buffer);

		/* write records */
		for (i = 0, front_end_ptr = front_end_nodes;
		     i < front_end_node_cnt; i++, front_end_ptr++) {
			xassert(front_end_ptr->magic == FRONT_END_MAGIC);
			_pack_front_end(front_end_ptr, buffer,
					protocol_version);
			nodes_packed++;
		}
	} else {
		error("pack_all_front_end: Unsupported slurm version %u",
		      protocol_version);
	}

	tmp_offset = get_buf_offset (buffer);
	set_buf_offset(buffer, 0);
	pack32(nodes_packed, buffer);
	set_buf_offset(buffer, tmp_offset);

	*buffer_size = get_buf_offset(buffer);
	buffer_ptr[0] = xfer_buf_data(buffer);
#else
	buffer_ptr[0] = NULL;
	*buffer_size = 0;
	buffer = init_buf(64);
	pack32(nodes_packed, buffer);
	pack_time(now, buffer);
	*buffer_size = get_buf_offset(buffer);
	buffer_ptr[0] = xfer_buf_data(buffer);
#endif
}
Esempio n. 3
0
END_TEST

START_TEST(pack_1702_coord_rec)
{
	int rc;

	slurmdb_coord_rec_t *pack_cr = xmalloc(sizeof(slurmdb_coord_rec_t));
	pack_cr->direct                = 12;
	pack_cr->name                  = xstrdup("Gottlob Frege");

	Buf buf = init_buf(1024);
	slurmdb_pack_coord_rec(pack_cr, SLURM_17_02_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_coord_rec_t *unpack_cr;
	rc = slurmdb_unpack_coord_rec((void **)&unpack_cr, SLURM_17_02_PROTOCOL_VERSION, buf);
	ck_assert(rc                        == SLURM_SUCCESS);
	ck_assert_str_eq(pack_cr->name,        unpack_cr->name);
	ck_assert(pack_cr->direct           == unpack_cr->direct);

	free_buf(buf);
	slurmdb_destroy_coord_rec(pack_cr);
	slurmdb_destroy_coord_rec(unpack_cr);
}
Esempio n. 4
0
int main(){
	int m;
	init_buf();
	while(1){
		m = scan();
		if(m == M_ENDOFFILE) break;
		switch(m){
			case M_ID:
				printf("Identifier : [%s]\n",yytext);
				break;
			case M_NUM:
				printf("Number : [%s]\n",yytext);
				break;
			case M_SPC:
				printf("Space : [%s]\n",yytext);
				break;
			case M_NL:
				printf("NL\n");
				break;
			case M_INT:
				printf("INT : [%s]\n",yytext);
				break;
			case M_IF:
				printf("IF : [%s]\n",yytext);
				break;
			default:
				printf("lexical error : [%s]\n",yytext);
				break;
		}
	}
	return 0;
}
Esempio n. 5
0
END_TEST

START_TEST(pack_1702_clus_res_rec)
{
	int rc;

	slurmdb_clus_res_rec_t *pack_crr = xmalloc(sizeof(slurmdb_clus_res_rec_t));
	pack_crr->percent_allowed = 12;
	pack_crr->cluster         = xstrdup("Diogenes");

	Buf buf = init_buf(1024);
	slurmdb_pack_clus_res_rec(pack_crr, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_clus_res_rec_t *unpack_crr;
	rc = slurmdb_unpack_clus_res_rec((void **)&unpack_crr, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                        == SLURM_SUCCESS);
	ck_assert(pack_crr->percent_allowed == unpack_crr->percent_allowed);
	ck_assert_str_eq(pack_crr->cluster, unpack_crr->cluster);

	free_buf(buf);
	slurmdb_destroy_clus_res_rec(pack_crr);
	slurmdb_destroy_clus_res_rec(unpack_crr);
}
Esempio n. 6
0
END_TEST



START_TEST(pack_1702_null_clus_res_rec)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_clus_res_rec_t pack_crr = {0};

	slurmdb_pack_clus_res_rec(NULL, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_clus_res_rec_t *unpack_crr;
	rc = slurmdb_unpack_clus_res_rec((void **)&unpack_crr, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc               == SLURM_SUCCESS);
	ck_assert(pack_crr.cluster == unpack_crr->cluster);

	/* when given a NULL pointer, the pack function sets percent_allowed to
	 * NO_VAL16, not 0. */
	ck_assert(NO_VAL16         == unpack_crr->percent_allowed);

	free_buf(buf);
	slurmdb_destroy_clus_res_rec(unpack_crr);
}
Esempio n. 7
0
extern Buf slurm_persist_msg_pack(slurm_persist_conn_t *persist_conn,
				  persist_msg_t *req_msg)
{
	Buf buffer;

	xassert(persist_conn);

	if (persist_conn->flags & PERSIST_FLAG_DBD)
		buffer = pack_slurmdbd_msg((slurmdbd_msg_t *)req_msg,
					   persist_conn->version);
	else {
		slurm_msg_t msg;

		slurm_msg_t_init(&msg);

		msg.data      = req_msg->data;
		msg.data_size = req_msg->data_size;
		msg.msg_type  = req_msg->msg_type;
		msg.protocol_version = persist_conn->version;

		buffer = init_buf(BUF_SIZE);

		pack16(req_msg->msg_type, buffer);
		if (pack_msg(&msg, buffer) != SLURM_SUCCESS) {
			free_buf(buffer);
			return NULL;
                }
	}

	return buffer;
}
Esempio n. 8
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Set up the expected error numbers for -e option */
	TEST_EXP_ENOS(exp_enos);

	TEST_PAUSE;

	/*
	 * Create a temporary directory and cd into it.
	 * This helps to ensure that a unique msgkey is created.
	 * See ../lib/libipc.c for more information.
	 */
	tst_tmpdir();

	msgkey = getipckey();

	/* create a message queue with read/write permission */
	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
		tst_brkm(TBROK, cleanup, "Can't create message queue");
	}

	/* initialize the message buffer */
	init_buf(&msg_buf, MSGTYPE, MSGSIZE);

	/* write messages to the queue until it is full */
	while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
		msg_buf.mtype += 1;
	}
}
Esempio n. 9
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{
    /* capture signals in our own handler */
    tst_sig(FORK, sighandler, cleanup);

    TEST_PAUSE;

    /*
     * Create a temporary directory and cd into it.
     * This helps to ensure that a unique msgkey is created.
     * See ../lib/libipc.c for more information.
     */
    tst_tmpdir();

    msgkey = getipckey();

    /* create a message queue with read/write permission */
    if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
        tst_brkm(TBROK, cleanup, "Can't create message queue");
    }

    /* initialize the message buffer */
    init_buf(&msg_buf, MSGTYPE, MSGSIZE);

    /* write messages to the queue until it is full */
    while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
        msg_buf.mtype += 1;
    }
}
Esempio n. 10
0
static void _save_dbd_state(void)
{
	char *dbd_fname;
	Buf buffer;
	int fd, rc, wrote = 0;
	uint16_t msg_type;
	uint32_t offset;

	dbd_fname = slurm_get_state_save_location();
	xstrcat(dbd_fname, "/dbd.messages");
	(void) unlink(dbd_fname);	/* clear save state */
	fd = open(dbd_fname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
	if (fd < 0) {
		error("slurmdbd: Creating state save file %s", dbd_fname);
	} else if (agent_list && list_count(agent_list)) {
		char curr_ver_str[10];
		snprintf(curr_ver_str, sizeof(curr_ver_str),
			 "VER%d", SLURM_PROTOCOL_VERSION);
		buffer = init_buf(strlen(curr_ver_str));
		packstr(curr_ver_str, buffer);
		rc = _save_dbd_rec(fd, buffer);
		free_buf(buffer);
		if (rc != SLURM_SUCCESS)
			goto end_it;

		while ((buffer = list_dequeue(agent_list))) {
			/*
			 * We do not want to store registration messages. If an
			 * admin puts in an incorrect cluster name we can get a
			 * deadlock unless they add the bogus cluster name to
			 * the accounting system.
			 */
			offset = get_buf_offset(buffer);
			if (offset < 2) {
				free_buf(buffer);
				continue;
			}
			set_buf_offset(buffer, 0);
			(void) unpack16(&msg_type, buffer);  /* checked by offset */
			set_buf_offset(buffer, offset);
			if (msg_type == DBD_REGISTER_CTLD) {
				free_buf(buffer);
				continue;
			}

			rc = _save_dbd_rec(fd, buffer);
			free_buf(buffer);
			if (rc != SLURM_SUCCESS)
				break;
			wrote++;
		}
	}

end_it:
	if (fd >= 0) {
		verbose("slurmdbd: saved %d pending RPCs", wrote);
		(void) close(fd);
	}
	xfree(dbd_fname);
}
Esempio n. 11
0
END_TEST

START_TEST(pack_1702_rec_null_ptrs)
{
	slurmdb_user_rec_t pack_rec = {0};
	pack_rec.admin_level   = 1;
	pack_rec.uid           = 12345;

	Buf buf = init_buf(1024);
	slurmdb_pack_user_rec(&pack_rec, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_user_rec_t *unpack_rec;
	int rc = slurmdb_unpack_user_rec((void **)&unpack_rec, SLURM_MIN_PROTOCOL_VERSION, buf);

	ck_assert_int_eq(rc, SLURM_SUCCESS);
	ck_assert_uint_eq(pack_rec.admin_level, unpack_rec->admin_level);
	ck_assert(pack_rec.assoc_list    == unpack_rec->assoc_list);
	ck_assert(pack_rec.coord_accts   == unpack_rec->coord_accts);
	ck_assert(pack_rec.wckey_list    == unpack_rec->wckey_list);
	ck_assert(pack_rec.default_acct  == unpack_rec->default_acct);
	ck_assert(pack_rec.default_wckey == unpack_rec->default_wckey);
	ck_assert(pack_rec.name          == unpack_rec->name);
	ck_assert(pack_rec.old_name      == unpack_rec->old_name);
	ck_assert_uint_eq(pack_rec.uid,  unpack_rec->uid);

	free_buf(buf);
	slurmdb_destroy_user_rec(unpack_rec);

}
Esempio n. 12
0
File: msgrcv01.c Progetto: GOEUM/ltp
/*
 * do_child()
 */
void do_child(void)
{
	int retval = 0;

	TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));

	if (TEST_RETURN == -1) {
		retval = 1;
		tst_resm(TFAIL, "%s call failed - errno = %d : %s",
			 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
	} else {
		if (STD_FUNCTIONAL_TEST) {
			/*
			 * Build a new message and compare it
			 * with the one received.
			 */
			init_buf(&cmp_buf, MSGTYPE, MSGSIZE);

			if (strcmp(rcv_buf.mtext, cmp_buf.mtext) == 0) {
				tst_resm(TPASS,
					 "message received = " "message sent");
			} else {
				retval = 1;
				tst_resm(TFAIL,
					 "message received != " "message sent");
			}
		} else {
			tst_resm(TPASS, "call succeeded");
		}
	}
	exit(retval);
}
Esempio n. 13
0
extern int
name_unpublish_up(char *name)
{
	Buf buf = NULL, resp_buf = NULL;
	uint32_t size, tmp_32;
	int rc;

	buf = init_buf(1024);
	pack16((uint16_t)TREE_CMD_NAME_UNPUBLISH, buf);
	packstr(name, buf);
	size = get_buf_offset(buf);

	rc = tree_msg_to_srun_with_resp(size, get_buf_data(buf), &resp_buf);
	free_buf(buf);

	if (rc == SLURM_SUCCESS) {
		safe_unpack32(&tmp_32, resp_buf);
		rc = (int) tmp_32;
	}

unpack_error:
	if (resp_buf)
		free_buf(resp_buf);
	
	return rc;
}
Esempio n. 14
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void
setup(void)
{
	/* capture signals */
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Set up the expected error numbers for -e option */
	TEST_EXP_ENOS(exp_enos);

	/* Pause if that option was specified */
	TEST_PAUSE;

	/*
	 * Create a temporary directory and cd into it.
	 * This helps to ensure that a unique msgkey is created.
	 * See ../lib/libipc.c for more information.
	 */
	tst_tmpdir();

	msgkey = getipckey();

	/* create a message queue with read/write permission */
	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
		tst_brkm(TBROK, cleanup, "Can't create message queue");
	}

	/* initialize a buffer */
	init_buf(&snd_buf, MSGTYPE, MSGSIZE);

	/* put the message on the queue */
	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
		tst_brkm(TBROK, cleanup, "Can't enqueue message");
	}
}
Esempio n. 15
0
File: io_hdr.c Progetto: A1ve5/slurm
int
io_init_msg_write_to_fd(int fd, struct slurm_io_init_msg *msg)
{
	Buf buf;
	void *ptr;
	int n;

	xassert(msg);

	debug2("Entering io_init_msg_write_to_fd");
	msg->version = IO_PROTOCOL_VERSION;
	buf = init_buf(io_init_msg_packed_size());
	debug2("  msg->nodeid = %d", msg->nodeid);
	io_init_msg_pack(msg, buf);

	ptr = get_buf_data(buf);
again:
	if ((n = write(fd, ptr, io_init_msg_packed_size())) < 0) {
		if (errno == EINTR)
			goto again;
		free_buf(buf);
		return SLURM_ERROR;
	}
	if (n != io_init_msg_packed_size()) {
		error("io init msg write too small");
		free_buf(buf);
		return SLURM_ERROR;
	}

	free_buf(buf);
	debug2("Leaving  io_init_msg_write_to_fd");
	return SLURM_SUCCESS;
}
Esempio n. 16
0
static int	ft_get_next_line(int const fd, char **line)
{
	int				ret;
	static t_struct *gnl = NULL;

	init_buf(&gnl, line);
	while (gnl->buf2 || (ret = read(fd, gnl->buf, BUFF_SIZE)))
	{
		if (gnl->buf2)
		{
			*line = ft_fill_line(gnl->buf2 + 1, *line);
			if ((gnl->buf2 = ft_strchr(gnl->buf2 + 1, '\n')) == NULL)
			{
				if ((ret = read(fd, gnl->buf, BUFF_SIZE)) == 0)
					return (0);
			}
			else
				return (1);
		}
		if (ret == -1)
			return (-1);
		gnl->buf[ret] = '\0';
		*line = ft_fill_line(gnl->buf, *line);
		if ((gnl->buf2 = ft_strchr(gnl->buf, '\n')) != NULL)
			return (1);
	}
	return ((ret || **line) ? 1 : 0);
}
Esempio n. 17
0
static ERL_NIF_TERM element_to(ErlNifEnv* env, int argc,
			       const ERL_NIF_TERM argv[],
			       int as_string)
{
  ErlNifBinary output;
  ERL_NIF_TERM result;
  struct buf *rbuf;

  if (argc == 1) {
    rbuf = init_buf(env);
    if (make_element(env, rbuf, argv[0])) {
      if (as_string) {
	(rbuf->b)[rbuf->len] = 0;
	result = enif_make_string(env, (char *) rbuf->b, ERL_NIF_LATIN1);
	destroy_buf(env, rbuf);
	return result;
      }	else {
	if (ENIF_ALLOC_BINARY(rbuf->len, &output)) {
	  memcpy(output.data, rbuf->b, rbuf->len);
	  result = enif_make_binary(env, &output);
	  destroy_buf(env, rbuf);
	  return result;
	};
      };
    };
    destroy_buf(env, rbuf);
  };
  
  return enif_make_badarg(env);
}
	logstreambuf::logstreambuf() throw() :
			_logfd( STDOUT_FILENO ), _continue( false ),
			_priority( priority::debug ), _mask( 1 ) {

		// initialise buffer space
		init_buf();

	}
Esempio n. 19
0
static bool init_stream(MyStream *v,
			PaStreamParameters *in, PaStreamParameters *out,
			long size)
{
  memset(v, 0, sizeof(MyStream));
  if (in) {
    long bufsize = round_pow2(Pa_GetSampleSize(in->sampleFormat)*
			      in->channelCount*size);
    if (!init_buf(&v->in_buf, &v->in_data, bufsize))
      return false;
  }
  if (out) {
    long bufsize = round_pow2(Pa_GetSampleSize(out->sampleFormat)*
			      out->channelCount*size);
    if (!init_buf(&v->out_buf, &v->out_data, bufsize)) {
      if (in) fini_buf(&v->in_buf, &v->in_data);
      return false;
    }
#if 0
    {
      /* fake a full write buffer */
      long bytes = MyRingBuffer_GetWriteAvailable(&v->out_buf);
      MyRingBuffer_AdvanceWriteIndex(&v->out_buf, bytes);
    }
#endif
  }
  v->time = 0.0;
#ifdef TIMER_KLUDGE
  v->delta = 0.0;
#endif
  pthread_mutex_init(&v->data_mutex, NULL);
  if (in) {
    pthread_mutex_init(&v->in_mutex, NULL);
    pthread_cond_init(&v->in_cond, NULL);
  }
  if (out) {
    pthread_mutex_init(&v->out_mutex, NULL);
    pthread_cond_init(&v->out_cond, NULL);
  }
  if (current) current->prev = v;
  v->prev = NULL;
  v->next = current;
  current = v;
  return true;
}
Esempio n. 20
0
END_TEST

START_TEST(pack_1702_assoc_usage)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_assoc_usage_t *pack_au = xmalloc(sizeof(slurmdb_assoc_usage_t));

	pack_au->children_list          = NULL;
	pack_au->grp_used_tres          = NULL;
	pack_au->grp_used_tres_run_secs = NULL;
	pack_au->grp_used_wall          = 77;
	pack_au->fs_factor              = 0;
	pack_au->level_shares           = 0;
	pack_au->parent_assoc_ptr       = NULL;
	pack_au->fs_assoc_ptr           = NULL;
	pack_au->shares_norm            = 0;
	pack_au->tres_cnt               = 0;
	pack_au->usage_efctv            = 123123;
	pack_au->usage_norm             = 4857;
	pack_au->usage_raw              = 4747;
	pack_au->usage_tres_raw         = NULL;
	pack_au->used_jobs              = 234;
	pack_au->used_submit_jobs       = 433;
	pack_au->level_fs               = 3333;
	pack_au->valid_qos              = NULL;

	slurmdb_pack_assoc_usage(pack_au, SLURM_17_02_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_assoc_usage_t *unpack_au;
	rc = slurmdb_unpack_assoc_usage((void **)&unpack_au, SLURM_17_02_PROTOCOL_VERSION, buf);
	ck_assert(rc                              == SLURM_SUCCESS);
	ck_assert(pack_au->children_list          == unpack_au->children_list);
	ck_assert(pack_au->grp_used_tres          == unpack_au->grp_used_tres);
	ck_assert(pack_au->grp_used_tres_run_secs == unpack_au->grp_used_tres_run_secs);
	ck_assert(pack_au->grp_used_wall          == unpack_au->grp_used_wall);
	ck_assert(pack_au->fs_factor              == unpack_au->fs_factor);
	ck_assert(pack_au->level_shares           == unpack_au->level_shares);
	ck_assert(pack_au->parent_assoc_ptr       == unpack_au->parent_assoc_ptr);
	ck_assert(pack_au->fs_assoc_ptr           == unpack_au->fs_assoc_ptr);
	ck_assert(pack_au->shares_norm            == unpack_au->shares_norm);
	ck_assert(pack_au->tres_cnt               == unpack_au->tres_cnt);
	ck_assert(pack_au->usage_efctv            == unpack_au->usage_efctv);
	ck_assert(pack_au->usage_norm             == unpack_au->usage_norm);
	ck_assert(pack_au->usage_raw              == unpack_au->usage_raw);
	ck_assert(pack_au->usage_tres_raw         == unpack_au->usage_tres_raw);
	ck_assert(pack_au->used_jobs              == unpack_au->used_jobs);
	ck_assert(pack_au->used_submit_jobs       == unpack_au->used_submit_jobs);
	ck_assert(pack_au->level_fs               == unpack_au->level_fs);
	ck_assert(pack_au->valid_qos              == unpack_au->valid_qos);

	free_buf(buf);
	slurmdb_destroy_assoc_usage(pack_au);
	slurmdb_destroy_assoc_usage(unpack_au);
}
Esempio n. 21
0
int main(){
	init_buf();
	init_idtable();
	struct T_t *tree = parse();
	fprintf(stderr,"OK\n");
	check(tree);
	codegen(tree);
	return 0;
}
Esempio n. 22
0
/*
 * do_child_uclinux() - capture signals, initialize buffer, then run do_child()
 */
void do_child_uclinux(void)
{
    /* initialize the message buffer */
    init_buf(&msg_buf, MSGTYPE, MSGSIZE);

    tst_sig(FORK, sighandler, cleanup);

    do_child();
}
Esempio n. 23
0
static ERL_NIF_TERM unescape_attr(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary input;
    ERL_NIF_TERM  output;
    struct buf *rbuf;
    int i;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if (!enif_inspect_binary(env, argv[0], &input)) {
        return enif_make_badarg(env);
    }

    rbuf = init_buf(env, EXML_ATTR_BUF_SIZE);

    for (i = 0; i < input.size; i++) {
        if (input.data[i] == '&') {
            if (match_tag(input, i+1, "amp;", 4)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '&');
                i += 4;
            } else if (match_tag(input, i+1, "apos;", 5)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '\'');
                i += 5;
            } else if (match_tag(input, i+1, "lt;", 3)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '<');
                i += 3;
            } else if (match_tag(input, i+1, "gt;", 3)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '>');
                i += 3;
            } else if (match_tag(input, i+1, "quot;", 5)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '"');
                i += 5;
            } else if (match_tag(input, i+1, "#x9;", 4)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '\t');
                i += 4;
            } else if (match_tag(input, i+1, "#xA;", 4)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '\n');
                i += 4;
            } else if (match_tag(input, i+1, "#xD;", 4)) {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, '\r');
                i += 4;
            } else {
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, input.data[i]);
            }
        } else {
            buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, input.data[i]);
        }
    }

    unsigned char* data = enif_make_new_binary(env, rbuf->len, &output);
    memcpy((char*)data, rbuf->b, rbuf->len);
    destroy_buf(env, rbuf);
    return output;
}
Esempio n. 24
0
END_TEST


START_TEST(pack_1702_null_assoc_rec)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_assoc_rec_t pack_ar = {0};

	slurmdb_pack_assoc_rec(NULL, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_assoc_rec_t *unpack_ar;
	rc = slurmdb_unpack_assoc_rec((void **)&unpack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                     	 == SLURM_SUCCESS);
	ck_assert(pack_ar.accounting_list	 == unpack_ar->accounting_list);
	ck_assert(pack_ar.acct           	 == unpack_ar->acct);
	ck_assert(pack_ar.assoc_next     	 == unpack_ar->assoc_next);
	ck_assert(pack_ar.assoc_next_id  	 == unpack_ar->assoc_next_id);
	ck_assert(pack_ar.cluster        	 == unpack_ar->cluster);
	ck_assert(NO_VAL                 	 == unpack_ar->def_qos_id);
	ck_assert(NO_VAL                 	 == unpack_ar->grp_jobs);
	ck_assert(NO_VAL                	 == unpack_ar->grp_submit_jobs);
	ck_assert(pack_ar.grp_tres       	 == unpack_ar->grp_tres);
	ck_assert(pack_ar.grp_tres_ctld  	 == unpack_ar->grp_tres_ctld);
	ck_assert(pack_ar.grp_tres_run_mins      == unpack_ar->grp_tres_run_mins);
	ck_assert(NO_VAL                         == unpack_ar->grp_wall);
	ck_assert(pack_ar.id                     == unpack_ar->id);
	ck_assert(pack_ar.is_def                 == unpack_ar->is_def);
	ck_assert(pack_ar.lft                    == unpack_ar->lft);
	ck_assert(NO_VAL                         == unpack_ar->max_jobs);
	ck_assert(NO_VAL                         == unpack_ar->max_submit_jobs);
	ck_assert(pack_ar.max_tres_mins_pj       == unpack_ar->max_tres_mins_pj);
	ck_assert(pack_ar.max_tres_mins_ctld     == unpack_ar->max_tres_mins_ctld);
	ck_assert(pack_ar.max_tres_run_mins      == unpack_ar->max_tres_run_mins);
	ck_assert(pack_ar.max_tres_run_mins_ctld == unpack_ar->max_tres_run_mins_ctld);
	ck_assert(pack_ar.max_tres_pj            == unpack_ar->max_tres_pj);
	ck_assert(pack_ar.max_tres_ctld          == unpack_ar->max_tres_ctld);
	ck_assert(pack_ar.max_tres_pn            == unpack_ar->max_tres_pn);
	ck_assert(pack_ar.max_tres_pn_ctld       == unpack_ar->max_tres_pn_ctld);
	ck_assert(NO_VAL                         == unpack_ar->max_wall_pj);
	ck_assert(pack_ar.parent_acct            == unpack_ar->parent_acct);
	ck_assert(pack_ar.parent_id              == unpack_ar->parent_id);
	ck_assert(pack_ar.partition              == unpack_ar->partition);
	ck_assert(pack_ar.qos_list               == unpack_ar->qos_list);
	ck_assert(pack_ar.rgt                    == unpack_ar->rgt);
	ck_assert(NO_VAL                         == unpack_ar->shares_raw);
	ck_assert(pack_ar.uid                    == unpack_ar->uid);
	ck_assert(pack_ar.usage                  == unpack_ar->usage);
	ck_assert(pack_ar.user                   == unpack_ar->user);

	free_buf(buf);
	slurmdb_destroy_assoc_rec(unpack_ar);
}
Esempio n. 25
0
static ERL_NIF_TERM escape_attr(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary input;
    ERL_NIF_TERM output;
    struct buf *rbuf;
    int i;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if (!enif_inspect_binary(env, argv[0], &input)) {
        return enif_make_badarg(env);
    }

    rbuf = init_buf(env, EXML_ATTR_BUF_SIZE);

    for (i = 0; i < input.size; i++) {
        switch (input.data[i]) {
            case '&':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&amp;", 5);
                break;
            case '<':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&lt;", 4);
                break;
            case '>':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&gt;", 4);
                break;
            case '"':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&quot;", 6);
                break;
            case '\'':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&apos;", 6);
                break;
            case '\t':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&#x9;", 5);
                break;
            case '\n':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&#xA;", 5);
                break;
            case '\r':
                buf_add_str(env, EXML_ATTR_BUF_SIZE, rbuf, "&#xD;", 5);
                break;
            default:
                buf_add_char(env, EXML_ATTR_BUF_SIZE, rbuf, input.data[i]);
                break;
        };
    };

    unsigned char *data = enif_make_new_binary(env, rbuf->len, &output);
    memcpy(data, rbuf->b, rbuf->len);
    destroy_buf(env, rbuf);
    return output;
}
Esempio n. 26
0
/*
 * save_cred_state - save the current credential list to a file
 * IN list - list of credentials
 * RET int - zero or error code
 */
int save_cred_state(slurm_cred_ctx_t ctx)
{
	char *old_file, *new_file, *reg_file;
	int cred_fd = -1, error_code = SLURM_SUCCESS, rc;
	Buf buffer = NULL;
	static pthread_mutex_t state_mutex = PTHREAD_MUTEX_INITIALIZER;

	old_file = xstrdup(conf->spooldir);
	xstrcat(old_file, "/cred_state.old");
	reg_file = xstrdup(conf->spooldir);
	xstrcat(reg_file, "/cred_state");
	new_file = xstrdup(conf->spooldir);
	xstrcat(new_file, "/cred_state.new");

	slurm_mutex_lock(&state_mutex);
	if ((cred_fd = creat(new_file, 0600)) < 0) {
		error("creat(%s): %m", new_file);
		if (errno == ENOSPC)
			_drain_node("SlurmdSpoolDir is full");
		error_code = errno;
		goto cleanup;
	}
	buffer = init_buf(1024);
	slurm_cred_ctx_pack(ctx, buffer);
	rc = write(cred_fd, get_buf_data(buffer), get_buf_offset(buffer));
	if (rc != get_buf_offset(buffer)) {
		error("write %s error %m", new_file);
		(void) unlink(new_file);
		if ((rc < 0) && (errno == ENOSPC))
			_drain_node("SlurmdSpoolDir is full");
		error_code = errno;
		goto cleanup;
	}
	(void) unlink(old_file);
	if (link(reg_file, old_file))
		debug4("unable to create link for %s -> %s: %m",
		       reg_file, old_file);
	(void) unlink(reg_file);
	if (link(new_file, reg_file))
		debug4("unable to create link for %s -> %s: %m",
		       new_file, reg_file);
	(void) unlink(new_file);

cleanup:
	slurm_mutex_unlock(&state_mutex);
	xfree(old_file);
	xfree(reg_file);
	xfree(new_file);
	if (buffer)
		free_buf(buffer);
	if (cred_fd > 0)
		close(cred_fd);
	return error_code;
}
Esempio n. 27
0
/*
 *
 * Returns SLURM_SUCCESS if successful.  On error returns SLURM_ERROR
 * and sets errno.
 */
int
stepd_completion(int fd, uint16_t protocol_version, step_complete_msg_t *sent)
{
	int req = REQUEST_STEP_COMPLETION_V2;
	int rc;
	int errnum = 0;
	Buf buffer;
	int len = 0;

	buffer = init_buf(0);

	debug("Entering stepd_completion for %u.%u, range_first = %d, range_last = %d",
	      sent->job_id, sent->job_step_id,
	      sent->range_first, sent->range_last);

	if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
		safe_write(fd, &req, sizeof(int));
		safe_write(fd, &sent->range_first, sizeof(int));
		safe_write(fd, &sent->range_last, sizeof(int));
		safe_write(fd, &sent->step_rc, sizeof(int));

		/*
		 * We must not use setinfo over a pipe with slurmstepd here
		 * Indeed, slurmd does a large use of getinfo over a pipe
		 * with slurmstepd and doing the reverse can result in
		 * a deadlock scenario with slurmstepd :
		 * slurmd(lockforread,write)/slurmstepd(write,lockforread)
		 * Do pack/unpack instead to be sure of independances of
		 * slurmd and slurmstepd
		 */
		jobacctinfo_pack(sent->jobacct, protocol_version,
				 PROTOCOL_TYPE_SLURM, buffer);
		len = get_buf_offset(buffer);
		safe_write(fd, &len, sizeof(int));
		safe_write(fd, get_buf_data(buffer), len);
		free_buf(buffer);

		/* Receive the return code and errno */
		safe_read(fd, &rc, sizeof(int));
		safe_read(fd, &errnum, sizeof(int));
	} else {
		error("%s: bad protocol version %hu",
		      __func__, protocol_version);
		rc = SLURM_ERROR;
	}

	errno = errnum;
	return rc;

rwfail:
	FREE_NULL_BUFFER(buffer);
	return -1;
}
Esempio n. 28
0
int main(int argc, char **argv){
  int i, me, target;
  unsigned int size;
  double t;
  MPI_Status status;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &me);
  target = 1 - me;

  init_buf(send_buf, me);
  init_buf(recv_buf, target);

  if(me==0) print_items();

  for(size=1;size<MAX_SIZE+1;size*=2){
    MPI_Barrier(MPI_COMM_WORLD);
    for(i=0;i<LOOP+WARMUP;i++){
      if(WARMUP == i)
	t = wtime();

      if(me == 0){
	MPI_Send(send_buf, size, MPI_CHAR, target, 9, MPI_COMM_WORLD);
	MPI_Recv(recv_buf, size, MPI_CHAR, target, 5, MPI_COMM_WORLD, &status);
      } 
      else {
	MPI_Recv(recv_buf, size, MPI_CHAR, target, 9, MPI_COMM_WORLD, &status);
	MPI_Send(send_buf, size, MPI_CHAR, target, 5, MPI_COMM_WORLD);
      } 
    }

    MPI_Barrier(MPI_COMM_WORLD);
    t = wtime() - t;
    if(me == 0)
      print_results(size, t);
  }

  MPI_Finalize();
  return 0;
}
Esempio n. 29
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{
	key_t msgkey2;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Set up the expected error numbers for -e option */
	TEST_EXP_ENOS(exp_enos);

	TEST_PAUSE;

	/* Switch to nobody user for correct error code collection */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}
	ltpuser = getpwnam(nobody_uid);
	if (setuid(ltpuser->pw_uid) == -1) {
		tst_resm(TINFO, "setuid failed to "
			 "to set the effective uid to %d", ltpuser->pw_uid);
		perror("setuid");
	}

	/*
	 * Create a temporary directory and cd into it.
	 * This helps to ensure that a unique msgkey is created.
	 * See ../lib/libipc.c for more information.
	 */
	tst_tmpdir();

	msgkey = getipckey();

	/* Get an new IPC resource key. */
	msgkey2 = getipckey();

	/* create a message queue with read/write permission */
	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
		tst_brkm(TBROK, cleanup, "Can't create message queue #1");
	}

	/* initialize a message buffer */
	init_buf(&snd_buf, MSGTYPE, MSGSIZE);

	/* put it on msq_q_1 */
	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, IPC_NOWAIT) == -1) {
		tst_brkm(TBROK, cleanup, "Couldn't put message on queue");
	}

	/* create a message queue without read/write permission */
	if ((msg_q_2 = msgget(msgkey2, IPC_CREAT | IPC_EXCL)) == -1) {
		tst_brkm(TBROK, cleanup, "Can't create message queue #2");
	}
}
Esempio n. 30
0
/*
 * switch functions for global state save/restore
 */
int switch_p_libstate_save(char *dir_name)
{
#ifdef HAVE_NATIVE_CRAY
    Buf buffer;
    char *file_name;
    int ret = SLURM_SUCCESS;
    int state_fd;

    xassert(dir_name != NULL);

    if (debug_flags & DEBUG_FLAG_SWITCH)
        CRAY_INFO("save to %s", dir_name);

    buffer = init_buf(SWITCH_BUF_SIZE);
    _state_write_buf(buffer);
    file_name = xstrdup(dir_name);
    xstrcat(file_name, "/switch_cray_state");
    (void) unlink(file_name);
    state_fd = creat(file_name, 0600);
    if (state_fd < 0) {
        CRAY_ERR("Can't save state, error creating file %s %m",
                 file_name);
        ret = SLURM_ERROR;
    } else {
        char  *buf = get_buf_data(buffer);
        size_t len = get_buf_offset(buffer);
        while (1) {
            int wrote = write(state_fd, buf, len);
            if ((wrote < 0) && (errno == EINTR))
                continue;
            if (wrote == 0)
                break;
            if (wrote < 0) {
                CRAY_ERR("Can't save switch state: %m");
                ret = SLURM_ERROR;
                break;
            }
            buf += wrote;
            len -= wrote;
        }
        close(state_fd);
    }
    xfree(file_name);

    if (buffer)
        free_buf(buffer);

    return ret;
#else
    return SLURM_SUCCESS;
#endif
}