extern int sbatch_set_first_avail_cluster(job_desc_msg_t *req)
{
   //printf("cao: src/sbatch/multi_cluster.c:  sbatch_set_first_avail_cluster(job_desc_msg_t *req)\n");
	int rc = SLURM_SUCCESS;
	ListIterator itr;
	local_cluster_rec_t *local_cluster = NULL;
	char buf[64];
	bool host_set = false;
	List ret_list = NULL;

	/* return if we only have 1 or less clusters here */
	if (!opt.clusters || !list_count(opt.clusters)) {
		return rc;
	} else if (list_count(opt.clusters) == 1) {
		working_cluster_rec = list_peek(opt.clusters);
		return rc;
	}

	if ((req->alloc_node == NULL) &&
	    (gethostname_short(buf, sizeof(buf)) == 0)) {
		req->alloc_node = buf;
		host_set = true;
	}

	ret_list = list_create(_destroy_local_cluster_rec);
	itr = list_iterator_create(opt.clusters);
	while ((working_cluster_rec = list_next(itr))) {
		if ((local_cluster = _job_will_run(req)))
			list_append(ret_list, local_cluster);
		else
			error("Problem with submit to cluster %s: %m",
			      working_cluster_rec->name);
	}
	list_iterator_destroy(itr);

	if (host_set)
		req->alloc_node = NULL;

	if (!list_count(ret_list)) {
		error("Can't run on any of the clusters given");
		rc = SLURM_ERROR;
		goto end_it;
	}

	/* sort the list so the first spot is on top */
	local_cluster_name = slurm_get_cluster_name();
	list_sort(ret_list, (ListCmpF)_sort_local_cluster);
	xfree(local_cluster_name);
	local_cluster = list_peek(ret_list);

	/* set up the working cluster and be done */
	working_cluster_rec = local_cluster->cluster_rec;
end_it:
	list_destroy(ret_list);

	return rc;
}
示例#2
0
END_TEST

START_TEST(pack_1702_account_rec)
{
	int rc;

	slurmdb_account_rec_t *pack_ar = xmalloc(sizeof(slurmdb_account_rec_t));
	pack_ar->description           = xstrdup("default_acct");
	pack_ar->name                  = xstrdup("default_name");
	pack_ar->organization          = xstrdup("default_organization");
	pack_ar->assoc_list            = list_create(slurmdb_destroy_assoc_rec);
	pack_ar->coordinators          = list_create(slurmdb_destroy_coord_rec);
	slurmdb_coord_rec_t * j = xmalloc(sizeof(slurmdb_coord_rec_t));
	slurmdb_assoc_rec_t * k = xmalloc(sizeof(slurmdb_assoc_rec_t));

	k->lft    = 88;
	j->name   = xstrdup("Bertrand Russell");
	j->direct = 5;

	list_append(pack_ar->coordinators, (void *)j);
	list_append(pack_ar->assoc_list,   (void *)k);

	Buf buf = init_buf(1024);
	slurmdb_pack_account_rec(pack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_account_rec_t *unpack_ar;
	rc = slurmdb_unpack_account_rec((void **)&unpack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                              == SLURM_SUCCESS);
	ck_assert_str_eq(pack_ar->description ,      unpack_ar->description);
	ck_assert_str_eq(pack_ar->name        ,      unpack_ar->name);
	ck_assert_str_eq(pack_ar->organization,      unpack_ar->organization);
	ck_assert(list_count(pack_ar->assoc_list) == list_count(unpack_ar->assoc_list));

	slurmdb_assoc_rec_t bar          = *(slurmdb_assoc_rec_t *)list_peek(pack_ar->assoc_list);
	slurmdb_assoc_rec_t aar          = *(slurmdb_assoc_rec_t *)list_peek(unpack_ar->assoc_list);
	slurmdb_coord_rec_t bc           = *(slurmdb_coord_rec_t *)list_peek(pack_ar->coordinators);
	slurmdb_coord_rec_t ac           = *(slurmdb_coord_rec_t *)list_peek(unpack_ar->coordinators);

	ck_assert_str_eq(bc.name,            ac.name);
	ck_assert(bc.direct              == ac.direct);
	ck_assert(bar.lft                == aar.lft);

	free_buf(buf);
	slurmdb_destroy_account_rec(pack_ar);
	slurmdb_destroy_account_rec(unpack_ar);
}
示例#3
0
static void serial_set_fds(SERIAL_DEVICE* serial)
{
    fd_set* fds;
    IRP* irp;
    SERIAL_TTY* tty;

    DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps));

    tty = serial->tty;
    irp = (IRP*)list_peek(serial->pending_irps);
    while (irp)
    {
        fds = NULL;

        switch (irp->MajorFunction)
        {
        case IRP_MJ_WRITE:
            fds = &serial->write_fds;
            break;

        case IRP_MJ_READ:
            fds = &serial->read_fds;
            break;
        }

        if (fds && (tty->fd >= 0))
        {
            FD_SET(tty->fd, fds);
            serial->nfds = MAX(serial->nfds, tty->fd);
        }
        irp = (IRP*)list_next(serial->pending_irps, irp);
    }
}
示例#4
0
文件: nfsfs.c 项目: dafyddcrosby/L4OS
/* check if the specified request is at the start of the list and should run */
static
int
check_request(NFS_BaseRequest *rq) {
	if (list_null(NfsRequests)) {
		dprintf(0, "!!! nfsfs: check_request NfsRequest list is null !!!\n");
		return run_request(rq);
	}

	/* Check at head of queue */
	NFS_BaseRequest *brq = (NFS_BaseRequest *) list_peek(NfsRequests);
	if (brq != rq) {
		return 0;
	}

	return run_request((NFS_BaseRequest *) list_peek(NfsRequests));
}
示例#5
0
文件: wtsvc.c 项目: railmeat/FreeRDP
boolean WTSVirtualChannelRead(
    /* __in */  void* hChannelHandle,
    /* __in */  uint32 TimeOut,
    /* __out */ uint8* Buffer,
    /* __in */  uint32 BufferSize,
    /* __out */ uint32* pBytesRead)
{
    wts_data_item* item;
    rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;

    item = (wts_data_item*) list_peek(channel->receive_queue);
    if (item == NULL)
    {
        wait_obj_clear(channel->receive_event);
        *pBytesRead = 0;
        return true;
    }
    *pBytesRead = item->length;
    if (item->length > BufferSize)
        return false;

    /* remove the first element (same as what we just peek) */
    freerdp_mutex_lock(channel->mutex);
    list_dequeue(channel->receive_queue);
    if (list_size(channel->receive_queue) == 0)
        wait_obj_clear(channel->receive_event);
    freerdp_mutex_unlock(channel->mutex);

    memcpy(Buffer, item->buffer, item->length);
    wts_data_item_free(item) ;

    return true;
}
示例#6
0
static int perform_monitor_cmd(req_t *req, server_conf_t *conf)
{
/*  Performs the MONITOR command, placing the client in a
 *    "read-only" session with a single console.
 *  Returns 0 if the command succeeds, or -1 on error.
 */
    obj_t *client;
    obj_t *console;

    assert(req->sd >= 0);
    assert(req->command == CONMAN_CMD_MONITOR);
    assert(list_count(req->consoles) == 1);

    log_msg(LOG_INFO, "Client <%s@%s:%d> issued monitor command",
        req->user, req->fqdn, req->port);

    if (send_rsp(req, CONMAN_ERR_NONE, NULL) < 0)
        return(-1);
    client = create_client_obj(conf, req);
    console = list_peek(req->consoles);
    assert(is_console_obj(console));
    link_objs(console, client);
    check_console_state(console, client);
    return(0);
}
static char *_set_running_job_str(List job_list, bool compact)
{
	int cnt = list_count(job_list);
	block_job_info_t *block_job;

	if (!cnt) {
		return xstrdup("-");
	} else if (cnt == 1) {
		block_job = list_peek(job_list);
		return xstrdup_printf("%u", block_job->job_id);
	} else if (compact)
		return xstrdup("multiple");
	else {
		char *tmp_char = NULL;
		ListIterator itr = list_iterator_create(job_list);
		while ((block_job = list_next(itr))) {
			if (tmp_char)
				xstrcat(tmp_char, " ");
			xstrfmtcat(tmp_char, "%u", block_job->job_id);
		}
		return tmp_char;
	}

	return NULL;
}
示例#8
0
static void __serial_check_fds(SERIAL_DEVICE* serial)
{
    IRP* irp;
    IRP* prev;
    SERIAL_TTY* tty;
    uint32 result = 0;

    memset(&serial->tv, 0, sizeof(struct timeval));
    tty = serial->tty;

    /* scan every pending */
    irp = list_peek(serial->pending_irps);
    while (irp)
    {
        DEBUG_SVC("MajorFunction %u", irp->MajorFunction);

        switch (irp->MajorFunction)
        {
        case IRP_MJ_READ:
            if (FD_ISSET(tty->fd, &serial->read_fds))
            {
                irp->IoStatus = STATUS_SUCCESS;
                serial_process_irp_read(serial, irp);
            }
            break;

        case IRP_MJ_WRITE:
            if (FD_ISSET(tty->fd, &serial->write_fds))
            {
                irp->IoStatus = STATUS_SUCCESS;
                serial_process_irp_write(serial, irp);
            }
            break;

        case IRP_MJ_DEVICE_CONTROL:
            if (serial_tty_get_event(tty, &result))
            {
                DEBUG_SVC("got event result %u", result);

                irp->IoStatus = STATUS_SUCCESS;
                stream_write_uint32(irp->output, result);
                irp->Complete(irp);
            }
            break;

        default:
            DEBUG_SVC("no request found");
            break;
        }

        prev = irp;
        irp = (IRP*)list_next(serial->pending_irps, irp);
        if (prev->IoStatus == STATUS_SUCCESS)
        {
            list_remove(serial->pending_irps, prev);
            wait_obj_set(serial->in_event);
        }
    }
}
示例#9
0
文件: nfsfs.c 项目: dafyddcrosby/L4OS
/* Run request at head of queue */
static
int
run_head_request(void) {
	if (list_null(NfsRequests)) {
		return 0;
	}
	return run_request((NFS_BaseRequest *) list_peek(NfsRequests));
}
示例#10
0
static int _isdefault(int cond_set, List acct_list, List assoc_list)
{
    int rc = 0;
    ListIterator itr = NULL;
    ListIterator itr2 = NULL;
    char *acct;
    char *output = NULL;
    slurmdb_association_rec_t *assoc = NULL;

    if (!acct_list || !list_count(acct_list)
            || !assoc_list || !list_count(assoc_list))
        return rc;

    /* Since not all plugins have been converted to the new style
       of default accounts we have to handle those that aren't.
       If the plugin have been converted all the associations here
       will have is_def set.
    */
    assoc = list_peek(assoc_list);
    if (!assoc->is_def)
        return _isdefault_old(acct_list);

    itr = list_iterator_create(acct_list);
    itr2 = list_iterator_create(assoc_list);
    while ((acct = list_next(itr))) {
        while ((assoc = list_next(itr2))) {
            char tmp[1000];
            /* The pgsql plugin doesn't have the idea of
               only_defs, so thre query could return all
               the associations, even without defaults. */
            if (cond_set == 1) {
                if (strcasecmp(acct, assoc->acct))
                    continue;
            } else {
                snprintf(tmp, 1000, " A = %s ", assoc->acct);
                if (!strstr(acct, tmp))
                    continue;
            }
            snprintf(tmp, 1000, "C = %-10s A = %-20s U = %-9s\n",
                     assoc->cluster, assoc->acct, assoc->user);
            if (output && strstr(output, tmp))
                continue;

            xstrcat(output, tmp);
            rc = 1;
        }
        list_iterator_reset(itr2);
    }
    list_iterator_destroy(itr);
    list_iterator_destroy(itr2);
    if (output) {
        fprintf(stderr," Users listed below have these "
                "as their Default Accounts.\n%s", output);
        xfree(output);
    }
    return rc;
}
示例#11
0
static rdpPrintJob* urdp_pdf_find_printjob(rdpPrinter* printer, uint32 id) {
	rdpPrintJob* printjob = (rdpPrintJob*) list_peek(((urdpPdfPrinter*) printer)->jobs);
	while (printjob) {
		if (printjob->id == id)
			return printjob;

		printjob = (rdpPrintJob*) list_next(((urdpPdfPrinter*) printer)->jobs, printjob);
	}
	return NULL;
}
示例#12
0
文件: List.c 项目: kr094/c
node_t list_seek(list_t list, int index) {
	int i;
	if(index < 0)
		return NULL;

	list_start(list);
	for(i = 1; i != index; list_next(list), i++);

	return list_peek(list);
}
extern int as_mysql_fix_runaway_jobs(mysql_conn_t *mysql_conn, uint32_t uid,
				     List runaway_jobs)
{
	char *query = NULL, *job_ids = NULL;
	slurmdb_job_rec_t *job = NULL;
	ListIterator iter = NULL;
	int rc = SLURM_SUCCESS;
	slurmdb_job_rec_t *first_job;

	list_sort(runaway_jobs, _job_sort_by_start_time);
	first_job = list_peek(runaway_jobs);

	if (check_connection(mysql_conn) != SLURM_SUCCESS)
		return ESLURM_DB_CONNECTION;

	if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_OPERATOR)) {
		slurmdb_user_rec_t user;

		memset(&user, 0, sizeof(slurmdb_user_rec_t));
		user.uid = uid;

		if (!is_user_any_coord(mysql_conn, &user)) {
			error("Only admins/operators/coordinators "
			      "can fix runaway jobs");
			return ESLURM_ACCESS_DENIED;
		}
	}

	iter = list_iterator_create(runaway_jobs);
	while ((job = list_next(iter))) {
		xstrfmtcat(job_ids, "%s%d", ((job_ids) ? "," : ""), job->jobid);
	}

	query = xstrdup_printf("UPDATE \"%s_%s\" SET time_end="
			       "GREATEST(time_start, time_eligible, time_submit), "
			       "state=%d WHERE id_job IN (%s);",
			       mysql_conn->cluster_name, job_table,
			       JOB_COMPLETE, job_ids);

	if (debug_flags & DEBUG_FLAG_DB_QUERY)
		DB_DEBUG(mysql_conn->conn, "query\n%s", query);
	mysql_db_query(mysql_conn, query);
	xfree(query);
	xfree(job_ids);

	/* Set rollup to the the last day of the previous month of the first
	 * runaway job */
	rc = _first_job_roll_up(mysql_conn, first_job->start);
	if (rc != SLURM_SUCCESS) {
		error("Failed to fix runaway jobs");
		return SLURM_ERROR;
	}

	return rc;
}
示例#14
0
static void serial_abort_single_io(SERIAL_DEVICE* serial, UINT32 file_id, UINT32 abort_io, UINT32 io_status)
{
	UINT32 major;
	IRP* irp = NULL;
	SERIAL_TTY* tty;

	DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps));

	tty = serial->tty;
	if(!tty)
	{
		DEBUG_WARN("tty = %p", tty);
		return;
	}

	switch (abort_io)
	{
		case SERIAL_ABORT_IO_NONE:
			major = 0;
			break;

		case SERIAL_ABORT_IO_READ:
			major = IRP_MJ_READ;
			break;

		case SERIAL_ABORT_IO_WRITE:
			major = IRP_MJ_WRITE;
			break;

		default:
			DEBUG_SVC("unexpected abort_io code %d", abort_io);
			return;
	}

	irp = (IRP*) list_peek(serial->pending_irps);

	while (irp)
	{
		if (irp->FileId != file_id || irp->MajorFunction != major)
		{
			irp = (IRP*) list_next(serial->pending_irps, irp);
			continue;
		}

		/* Process a SINGLE FileId and MajorFunction */
		list_remove(serial->pending_irps, irp);
		irp->IoStatus = io_status;
		Stream_Write_UINT32(irp->output, 0);
		irp->Complete(irp);

		break;
	}

	DEBUG_SVC("[out] pending size %d", list_size(serial->pending_irps));
}
示例#15
0
struct tree_node *dequeue(Queue queue) {
	assert(!list_is_empty(queue));

	struct list_node *node = list_peek(queue);
	list_delete(node);

	struct tree_node *ret = node->data;
	free(node);

	return ret;
}
示例#16
0
文件: List.c 项目: kr094/c
node_t list_next(list_t list) {
	if(!list->head)
		return list_clean(list);

	if(!list->curr->next) {
		list->curr = NULL;
	} else {
		list->curr = list->curr->next;
	}

	return list_peek(list);
}
示例#17
0
文件: List.c 项目: kr094/c
node_t list_prev(list_t list) {
	if(!list->head)
		return list_clean(list);

	if(!list->curr->prev) {
		list->curr = NULL;
	} else {
		list->curr = list->curr->prev;
	}

	return list_peek(list);
}
示例#18
0
/* Add clusters to be removed if "setting" a federation to a specific set of
 * clusters or clearing all clusters.
 *
 * IN cluster_list: list of slurmdb_cluster_rec_t's with cluster names set that
 *                  are to be "set" on the federation the federation.
 * IN federation: name of the federation that is being added/modified.
 */
static int _add_clusters_to_remove(List cluster_list, const char *federation)
{
	List        db_list = NULL;
	ListIterator db_itr = NULL;
	slurmdb_federation_cond_t db_cond;
	slurmdb_federation_rec_t *db_rec = NULL;
	slurmdb_cluster_rec_t    *db_cluster = NULL;

	slurmdb_init_federation_cond(&db_cond, 0);
	db_cond.federation_list = list_create(slurm_destroy_char);
	list_append(db_cond.federation_list, xstrdup(federation));

	db_list = acct_storage_g_get_federations(db_conn, my_uid, &db_cond);
	if (!db_list || !list_count(db_list)) {
		fprintf(stderr, " Problem getting federations "
			"from database. Contact your admin.\n");
		return SLURM_ERROR;
	}
	FREE_NULL_LIST(db_cond.federation_list);
	db_rec = list_peek(db_list);
	db_itr = list_iterator_create(db_rec->cluster_list);
	while ((db_cluster = list_next(db_itr))) {
		bool found_cluster = false;
		slurmdb_cluster_rec_t *orig_cluster = NULL;
		ListIterator orig_itr = list_iterator_create(cluster_list);

		/* Figure out if cluster in cluster_list is already on the
		 * federation. If if is, don't add to list to remove */
		while ((orig_cluster = list_next(orig_itr))) {
			char *db_name = db_cluster->name;
			if (*db_name == '+' || *db_name == '-')
				++db_name;
			if (!xstrcmp(orig_cluster->name, db_name)) {
				found_cluster = true;
				break;
			}
		}
		list_iterator_destroy(orig_itr);
		if (found_cluster)
			continue;

		slurmdb_cluster_rec_t *cluster =
			xmalloc(sizeof(slurmdb_cluster_rec_t));
		slurmdb_init_cluster_rec(cluster, 0);
		cluster->name = xstrdup_printf("-%s", db_cluster->name);
		list_append(cluster_list, cluster);
	}
	list_iterator_destroy(db_itr);
	FREE_NULL_LIST(db_list);

	return SLURM_SUCCESS;
}
示例#19
0
static void peek_positin_peekedIsOk(void **state)
{
    list_t *list = list_new();
    list_status_t *status;
    town tw, check;
    tw.place.x = 5;
    tw.place.y = 5;
    list_put(list, tw, 0);
    check  = list_peek(list, 0, status);
    assert_int_equal(check.place.x, tw.place.x);
    assert_int_equal(check.place.y, tw.place.y);
    list_delete(list);
}
示例#20
0
static int perform_connect_cmd(req_t *req, server_conf_t *conf)
{
/*  Performs the CONNECT command.  If a single console is specified,
 *    the client is placed in a "read-write" session with that console.
 *    Otherwise, the client is placed in a "write-only" broadcast session
 *    affecting multiple consoles.
 *  Returns 0 if the command succeeds, or -1 on error.
 */
    obj_t *client;
    obj_t *console;
    ListIterator i;

    assert(req->sd >= 0);
    assert(req->command == CONMAN_CMD_CONNECT);

    log_msg(LOG_INFO, "Client <%s@%s:%d> issued connect command",
        req->user, req->fqdn, req->port);

    if (send_rsp(req, CONMAN_ERR_NONE, NULL) < 0)
        return(-1);
    client = create_client_obj(conf, req);

    if (list_count(req->consoles) == 1) {
        /*
         *  Unicast connection (R/W).
         */
        console = list_peek(req->consoles);
        assert(is_console_obj(console));
        link_objs(client, console);
        link_objs(console, client);
        check_console_state(console, client);
    }
    else {
        /*
         *  Broadcast connection (W/O).
         */
        i = list_iterator_create(req->consoles);
        while ((console = list_next(i))) {
            assert(is_console_obj(console));
            link_objs(client, console);
            check_console_state(console, client);
        }
        list_iterator_destroy(i);
    }
    return(0);
}
示例#21
0
cons_t *do_macros(cons_t *rprog, dict_t **scope) {
	dict_t *symbol;
	value_t val;
	cons_t *stack = NULL;

	while (rprog != NULL) {
		val = list_peek(rprog);
		if (symbol_p(val) && macro_p(unwrap_symbol(val))) {
			symbol = unwrap_symbol(val);
			unwrap_native(value(symbol))(&stack, scope);
		} else {
			list_push(&stack, val);
		}
		rprog = list_next(rprog);
	}

	return stack;
}
示例#22
0
static void serial_check_for_events(SERIAL_DEVICE* serial)
{
	IRP* irp = NULL;
	IRP* prev;
	UINT32 result = 0;
	SERIAL_TTY* tty;

	tty = serial->tty;
	if(!tty)
	{
		DEBUG_WARN("tty = %p", tty);
		return;
	}

	DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps));

	irp = (IRP*) list_peek(serial->pending_irps);

	while (irp)
	{
		prev = NULL;

		if (irp->MajorFunction == IRP_MJ_DEVICE_CONTROL)
		{
			if (serial_tty_get_event(tty, &result))
			{
				DEBUG_SVC("got event result %u", result);

				irp->IoStatus = STATUS_SUCCESS;
				Stream_Write_UINT32(irp->output, result);
				irp->Complete(irp);

				prev = irp;
				irp = (IRP*) list_next(serial->pending_irps, irp);
				list_remove(serial->pending_irps, prev);
			}
		}

		if (!prev)
			irp = (IRP*) list_next(serial->pending_irps, irp);
	}

	DEBUG_SVC("[out] pending size %d", list_size(serial->pending_irps));
}
示例#23
0
static void *timejob_thread(void *arg)
{
	struct timejob *tj;
	struct timeval tv;
	struct timespec timeout;
	int sec;
	
	setpriority(PRIO_PROCESS, getpid(), 10);
	pthread_mutex_lock(&timejob_mutex);
	while (timejob_run && pthread_kill(main_thread_id, 0) == 0) {
		tj = list_peek(&timejob_list);
		if (tj) {
			gettimeofday(&tv, NULL);
			if (tv.tv_sec > tj->j_ts.tv_sec ||
			    (tv.tv_sec == tj->j_ts.tv_sec && tv.tv_usec * 1000 >= tj->j_ts.tv_nsec)) {
				timejob_curr = tj;
				list_pop(&timejob_list);
				pthread_mutex_unlock(&timejob_mutex);
				sec = timejob_curr->j_func(timejob_curr->j_arg,
							   timejob_curr->j_arg_sec);
				pthread_mutex_lock(&timejob_mutex);
				if (sec) {
					gettimeofday(&tv, NULL);
					tj->j_ts.tv_sec = tv.tv_sec + sec;
					tj->j_ts.tv_nsec = tv.tv_usec * 1000;
					__register(tj);
				}
				timejob_curr = NULL;
				pthread_cond_signal(&timejob_curr_cond);
			} else {
				/* copy timeout as the struct can be removed from the list */
				timeout = tj->j_ts;
				pthread_cond_timedwait(&timejob_cond, &timejob_mutex, &timeout);
			}
		} else {
			pthread_cond_wait(&timejob_cond, &timejob_mutex);
		}
	}
	timejob_run = 2;
	pthread_cond_signal(&timejob_run_cond);
	pthread_mutex_unlock(&timejob_mutex);
	return NULL;
}
示例#24
0
文件: squeue.c 项目: VURM/slurm
int
main (int argc, char *argv[])
{
	log_options_t opts = LOG_OPTS_STDERR_ONLY ;
	int error_code = SLURM_SUCCESS;

	log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_USER, NULL);
	parse_command_line( argc, argv );
	if (params.verbose) {
		opts.stderr_level += params.verbose;
		log_alter(opts, SYSLOG_FACILITY_USER, NULL);
	}
	max_line_size = _get_window_width( );

	if (params.clusters)
		working_cluster_rec = list_peek(params.clusters);

	while (1) {
		if ((!params.no_header) &&
		    (params.iterate || params.verbose || params.long_list))
			_print_date ();

		if (!params.clusters) {
			if (_get_info(false))
				error_code = 1;
		} else if (_multi_cluster(params.clusters) != 0)
			error_code = 1;

		if ( params.iterate ) {
			printf( "\n");
			sleep( params.iterate );
		}
		else
			break;
	}

	if ( error_code != SLURM_SUCCESS )
		exit (error_code);
	else
		exit (0);
}
示例#25
0
/* process the linked list of data that has queued to be sent */
static void rdpsnd_process_interval(rdpSvcPlugin* plugin)
{
	rdpsndPlugin* rdpsnd = (rdpsndPlugin*)plugin;
	struct data_out_item* item;
	uint32 cur_time;

	while (list_size(rdpsnd->data_out_list) > 0)
	{
		item = (struct data_out_item*)list_peek(rdpsnd->data_out_list) ;
		cur_time = get_mstime();
		if (!item || cur_time <= item->out_timestamp)
			break;

		item = (struct data_out_item*)list_dequeue(rdpsnd->data_out_list);
		svc_plugin_send(plugin, item->data_out);
		xfree(item);

		DEBUG_SVC("processed data_out");
	}

	if (rdpsnd->is_open && rdpsnd->close_timestamp > 0)
	{
		cur_time = get_mstime();
		if (cur_time > rdpsnd->close_timestamp)
		{
			if (rdpsnd->device)
				IFCALL(rdpsnd->device->Close, rdpsnd->device);
			rdpsnd->is_open = false;
			rdpsnd->close_timestamp = 0;

			DEBUG_SVC("processed close");
		}
	}

	if (list_size(rdpsnd->data_out_list) == 0 && !rdpsnd->is_open)
	{
		rdpsnd->plugin.interval_ms = 0;
	}
}
示例#26
0
BOOL WTSVirtualChannelRead(
	/* __in */  void* hChannelHandle,
	/* __in */  UINT32 TimeOut,
	/* __out */ BYTE* Buffer,
	/* __in */  UINT32 BufferSize,
	/* __out */ UINT32* pBytesRead)
{
	wts_data_item* item;
	rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;

	item = (wts_data_item*) list_peek(channel->receive_queue);

	if (item == NULL)
	{
		ResetEvent(channel->receive_event);
		*pBytesRead = 0;
		return TRUE;
	}

	*pBytesRead = item->length;

	if (item->length > BufferSize)
		return FALSE;

	/* remove the first element (same as what we just peek) */
	WaitForSingleObject(channel->mutex, INFINITE);
	list_dequeue(channel->receive_queue);

	if (list_size(channel->receive_queue) == 0)
		ResetEvent(channel->receive_event);

	ReleaseMutex(channel->mutex);

	CopyMemory(Buffer, item->buffer, item->length);
	wts_data_item_free(item) ;

	return TRUE;
}
示例#27
0
文件: srun.c 项目: supermanue/slurm
static void _setup_job_env(srun_job_t *job, List srun_job_list, bool got_alloc)
{
	ListIterator opt_iter, job_iter;
	opt_t *opt_local;

	if (srun_job_list) {
		srun_job_t *first_job = list_peek(srun_job_list);
		if (!opt_list) {
			if (first_job)
				fini_srun(first_job, got_alloc, &global_rc, 0);
			fatal("%s: have srun_job_list, but no opt_list",
			      __func__);
		}
		job_iter  = list_iterator_create(srun_job_list);
		opt_iter  = list_iterator_create(opt_list);
		while ((opt_local = (opt_t *) list_next(opt_iter))) {
			job = (srun_job_t *) list_next(job_iter);
			if (!job) {
				if (first_job) {
					fini_srun(first_job, got_alloc,
						  &global_rc, 0);
				}
				fatal("%s: job allocation count does not match request count (%d != %d)",
				      __func__, list_count(srun_job_list),
				      list_count(opt_list));
			}
			_setup_one_job_env(opt_local, job, got_alloc);
		}
		list_iterator_destroy(job_iter);
		list_iterator_destroy(opt_iter);
	} else if (job) {
		_setup_one_job_env(&opt, job, got_alloc);
	} else {
		fatal("%s: No job information", __func__);
	}
}
示例#28
0
static void __serial_check_fds(SERIAL_DEVICE* serial)
{
	IRP* irp;
	IRP* prev;
	SERIAL_TTY* tty;
	UINT32 result = 0;
	BOOL irp_completed = FALSE;

	ZeroMemory(&serial->tv, sizeof(struct timeval));
	tty = serial->tty;
	if(!tty)
	{
		DEBUG_WARN("tty = %p", tty);
		return;
	}

	/* scan every pending */
	irp = list_peek(serial->pending_irps);

	while (irp)
	{
		DEBUG_SVC("MajorFunction %u", irp->MajorFunction);

		switch (irp->MajorFunction)
		{
			case IRP_MJ_READ:
				if (FD_ISSET(tty->fd, &serial->read_fds))
				{
					irp->IoStatus = STATUS_SUCCESS;
					serial_process_irp_read(serial, irp);
					irp_completed = TRUE;
				}
				break;

			case IRP_MJ_WRITE:
				if (FD_ISSET(tty->fd, &serial->write_fds))
				{
					irp->IoStatus = STATUS_SUCCESS;
					serial_process_irp_write(serial, irp);
					irp_completed = TRUE;
				}
				break;

			case IRP_MJ_DEVICE_CONTROL:
				if (serial_tty_get_event(tty, &result))
				{
					DEBUG_SVC("got event result %u", result);

					irp->IoStatus = STATUS_SUCCESS;
					Stream_Write_UINT32(irp->output, result);
					irp->Complete(irp);
					irp_completed = TRUE;
				}
				break;

			default:
				DEBUG_SVC("no request found");
				break;
		}

		prev = irp;
		irp = (IRP*) list_next(serial->pending_irps, irp);

		if (irp_completed || (prev->IoStatus == STATUS_SUCCESS))
			list_remove(serial->pending_irps, prev);
	}
}
示例#29
0
文件: opts.c 项目: Xarthisius/slurm
/*
 * parse_command_line, fill in params data structure with data
 */
extern void parse_command_line(int argc, char *argv[])
{
	int first = 1;
	int opt_char;
	int option_index;
	uid_t some_uid;
	long tmp_l;
	static struct option long_options[] = {
		{"primary_slurmctld_failure",           no_argument, 0, 'a'},
		{"primary_slurmctld_resumed_operation", no_argument, 0, 'A'},
		{"primary_slurmctld_resumed_control",   no_argument, 0, 'b'},
		{"backup_slurmctld_failure",            no_argument, 0, 'B'},
		{"backup_slurmctld_resumed_operation",  no_argument, 0, 'c'},
		{"backup_slurmctld_assumed_control",    no_argument, 0, 'C'},
		{"down",                                no_argument, 0, 'd'},
		{"drained",                             no_argument, 0, 'D'},
		{"primary_slurmctld_acct_buffer_full",  no_argument, 0, 'e'},
		{"fini",                                no_argument, 0, 'f'},
		{"fail",                                no_argument, 0, 'F'},
		{"primary_slurmdbd_failure",            no_argument, 0, 'g'},
		{"primary_slurmdbd_resumed_operation",  no_argument, 0, 'G'},
		{"primary_database_failure",            no_argument, 0, 'h'},
		{"primary_database_resumed_operation",  no_argument, 0, 'H'},
		{"id",                            required_argument, 0, 'i'},
		{"idle",                                no_argument, 0, 'I'},
		{"jobid",                         required_argument, 0, 'j'},
		{"cluster",                       required_argument, 0, 'M'},
		{"clusters",                      required_argument, 0, 'M'},
		{"node",                          optional_argument, 0, 'n'},
		{"offset",                        required_argument, 0, 'o'},
		{"program",                       required_argument, 0, 'p'},
		{"quiet",                               no_argument, 0, 'Q'},
		{"reconfig",                            no_argument, 0, 'r'},
		{"time",                                no_argument, 0, 't'},
		{"up",                                  no_argument, 0, 'u'},
		{"verbose",                             no_argument, 0, 'v'},
		{"version",                             no_argument, 0, 'V'},
		{"block_err", no_argument,       0, OPT_LONG_BLOCK_ERR},
		{"clear",     no_argument,       0, OPT_LONG_CLEAR},
		{"flags",     required_argument, 0, OPT_LONG_FLAGS},
		{"front_end", no_argument,       0, OPT_LONG_FRONT_END},
		{"get",       no_argument,       0, OPT_LONG_GET},
		{"help",      no_argument,       0, OPT_LONG_HELP},
		{"set",       no_argument,       0, OPT_LONG_SET},
		{"usage",     no_argument,       0, OPT_LONG_USAGE},
		{"user",      required_argument, 0, OPT_LONG_USER},
		{NULL,        0,                 0, 0}
	};

	_init_options();

	optind = 0;
	while ((opt_char = getopt_long(argc, argv,
				       "aAbBcCdDeFfgGhHi:Ij:M:n::o:p:QrtuvV",
				       long_options, &option_index)) != -1) {
		switch (opt_char) {
		case (int)'?':
			if (first) {
				first = 0;
				fprintf(stderr, "Try \"strigger --help\" for "
					"more information\n");
			}
			exit(1);
			break;
		case (int)'a':
			params.pri_ctld_fail = true;
			break;
		case (int)'A':
			params.pri_ctld_res_op = true;
			break;
		case (int)'b':
			params.pri_ctld_res_ctrl = true;
			break;
		case (int)'B':
			params.bu_ctld_fail = true;
			break;
		case (int)'c':
			params.bu_ctld_res_op = true;
			break;
		case (int)'C':
			params.bu_ctld_as_ctrl = true;
			break;
		case (int)'d':
			params.node_down = true;
			break;
		case (int)'D':
			params.node_drained = true;
			break;
		case (int)'e':
			params.pri_ctld_acct_buffer_full = true;
			break;
		case (int)'f':
			params.job_fini = true;
			break;
		case (int)'F':
			params.node_fail = true;
			break;
		case (int)'g':
			params.pri_dbd_fail = true;
			break;
		case (int)'G':
			params.pri_dbd_res_op = true;
			break;
		case (int)'h':
			params.pri_db_fail = true;
			break;
		case (int)'H':
			params.pri_db_res_op = true;
			break;
		case (int)'i':
			params.trigger_id = atoi(optarg);
			break;
		case (int)'I':
			params.node_idle = true;
			break;
		case (int)'j':
			tmp_l = atol(optarg);
			if (tmp_l <= 0) {
				error("Invalid jobid %s", optarg);
				exit(1);
			}
			params.job_id = tmp_l;
			break;
		case (int) 'M':
			if (params.clusters)
				list_destroy(params.clusters);
			if (!(params.clusters =
			      slurmdb_get_info_cluster(optarg))) {
				error("'%s' can't be reached now, "
				      "or it is an invalid entry for "
				      "--cluster.  Use 'sacctmgr --list "
				      "cluster' to see available clusters.",
				      optarg);
				exit(1);
			}
			working_cluster_rec = list_peek(params.clusters);
			break;
		case (int)'n':
			xfree(params.node_id);
			if (optarg)
				params.node_id = xstrdup(optarg);
			else
				params.node_id = xstrdup("*");
			break;
		case (int)'o':
			params.offset = atoi(optarg);
			break;
		case (int)'p':
			xfree(params.program);
			params.program = xstrdup(optarg);
			break;
		case (int)'Q':
			params.quiet = true;
			break;
		case (int)'r':
			params.reconfig = true;
			break;
		case (int)'t':
			params.time_limit = true;
			break;
		case (int)'u':
			params.node_up = true;
			break;
		case (int) 'v':
			params.verbose++;
			break;
		case (int) 'V':
			print_slurm_version();
			exit(0);
		case (int) OPT_LONG_BLOCK_ERR:
			params.block_err = true;
			break;
		case (int) OPT_LONG_HELP:
			_help();
			exit(0);
		case (int) OPT_LONG_USAGE:
			_usage();
			exit(0);
		case (int) OPT_LONG_CLEAR:
			params.mode_clear = true;
			break;
		case (int) OPT_LONG_FLAGS:
			if (!strncasecmp(optarg, "perm", 4))
				params.flags = TRIGGER_FLAG_PERM;
			else {
				error("Invalid flags %s", optarg);
				exit(1);
			}
			break;
		case (int) OPT_LONG_FRONT_END:
			params.front_end = true;
			break;
		case (int) OPT_LONG_GET:
			params.mode_get = true;
			break;
		case (int) OPT_LONG_SET:
			params.mode_set = true;
			break;
		case (int) OPT_LONG_USER:
			if ( uid_from_string( optarg, &some_uid ) != 0 ) {
				error("Invalid user %s", optarg);
				exit(1);
			}
			params.user_id = (uint32_t) some_uid;
			break;
		}
	}

	if (params.verbose)
		_print_options();
	_validate_options();
}
示例#30
0
extern int sacctmgr_dump_cluster (int argc, char **argv)
{
	slurmdb_user_cond_t user_cond;
	slurmdb_user_rec_t *user = NULL;
	slurmdb_hierarchical_rec_t *slurmdb_hierarchical_rec = NULL;
	slurmdb_assoc_rec_t *assoc = NULL;
	slurmdb_assoc_cond_t assoc_cond;
	List assoc_list = NULL;
	List acct_list = NULL;
	List user_list = NULL;
	List slurmdb_hierarchical_rec_list = NULL;
	char *cluster_name = NULL;
	char *file_name = NULL;
	char *user_name = NULL;
	char *line = NULL;
	int i, command_len = 0;
	FILE *fd = NULL;
	char *class_str = NULL;

	for (i = 0; i < argc; i++) {
		int end = parse_option_end(argv[i]);

		if (!end)
			command_len = strlen(argv[i]);
		else {
			command_len = end - 1;
			if (argv[i][end] == '=') {
				end++;
			}
		}
		if (!end || !strncasecmp(argv[i], "Cluster",
					 MAX(command_len, 1))) {
			if (cluster_name) {
				exit_code = 1;
				fprintf(stderr,
					" Can only do one cluster at a time.  "
					"Already doing %s\n", cluster_name);
				continue;
			}
			cluster_name = xstrdup(argv[i]+end);
		} else if (!strncasecmp(argv[i], "File",
					MAX(command_len, 1))) {
			if (file_name) {
				exit_code = 1;
				fprintf(stderr,
					" File name already set to %s\n",
					file_name);
				continue;
			}
			file_name = xstrdup(argv[i]+end);
		} else {
			exit_code = 1;
			fprintf(stderr, " Unknown option: %s\n", argv[i]);
		}
	}

	if (!cluster_name) {
		exit_code = 1;
		fprintf(stderr, " We need a cluster to dump.\n");
		xfree(file_name);
		return SLURM_ERROR;
	} else {
		List temp_list = NULL;
		slurmdb_cluster_cond_t cluster_cond;
		slurmdb_cluster_rec_t *cluster_rec = NULL;

		slurmdb_init_cluster_cond(&cluster_cond, 0);
		cluster_cond.cluster_list = list_create(NULL);
		list_push(cluster_cond.cluster_list, cluster_name);

		temp_list = acct_storage_g_get_clusters(db_conn, my_uid,
							&cluster_cond);
		FREE_NULL_LIST(cluster_cond.cluster_list);
		if (!temp_list) {
			exit_code = 1;
			fprintf(stderr,
				" Problem getting clusters from database.  "
				"Contact your admin.\n");
			xfree(cluster_name);
			xfree(file_name);
			return SLURM_ERROR;
		}

		cluster_rec = list_peek(temp_list);
		if (!cluster_rec) {
			exit_code = 1;
			fprintf(stderr, " Cluster %s doesn't exist.\n",
				cluster_name);
			xfree(cluster_name);
			xfree(file_name);
			FREE_NULL_LIST(temp_list);
			return SLURM_ERROR;
		}
		class_str = get_classification_str(cluster_rec->classification);
		FREE_NULL_LIST(temp_list);
	}

	if (!file_name) {
		file_name = xstrdup_printf("./%s.cfg", cluster_name);
		printf(" No filename given, using %s.\n", file_name);
	}

	memset(&user_cond, 0, sizeof(slurmdb_user_cond_t));
	user_cond.with_coords = 1;
	user_cond.with_wckeys = 1;
	user_cond.with_assocs = 1;

	memset(&assoc_cond, 0, sizeof(slurmdb_assoc_cond_t));
	assoc_cond.without_parent_limits = 1;
	assoc_cond.with_raw_qos = 1;
	assoc_cond.cluster_list = list_create(NULL);
	list_append(assoc_cond.cluster_list, cluster_name);
	/* this is needed for getting the correct wckeys */
	user_cond.assoc_cond = &assoc_cond;

	user_list = acct_storage_g_get_users(db_conn, my_uid, &user_cond);
	/* If not running with the DBD assoc_cond.user_list can be set,
	 * which will mess other things up.
	 */
	if (assoc_cond.user_list) {
		FREE_NULL_LIST(assoc_cond.user_list);
		assoc_cond.user_list = NULL;
	}

	/* make sure this person running is an admin */
	user_name = uid_to_string_cached(my_uid);
	if (!(user = sacctmgr_find_user_from_list(user_list, user_name))) {
		exit_code = 1;
		fprintf(stderr, " Your uid (%u) is not in the "
			"accounting system, can't dump cluster.\n", my_uid);
		FREE_NULL_LIST(assoc_cond.cluster_list);
		xfree(cluster_name);
		xfree(file_name);
		FREE_NULL_LIST(user_list);
		return SLURM_ERROR;

	} else {
		if (my_uid != slurm_get_slurm_user_id() && my_uid != 0
		    && user->admin_level < SLURMDB_ADMIN_SUPER_USER) {
			exit_code = 1;
			fprintf(stderr, " Your user does not have sufficient "
				"privileges to dump clusters.\n");
			FREE_NULL_LIST(assoc_cond.cluster_list);
			xfree(cluster_name);
			xfree(file_name);
			FREE_NULL_LIST(user_list);
			return SLURM_ERROR;
		}
	}
	xfree(user_name);

	/* assoc_cond is set up above */
	assoc_list = acct_storage_g_get_assocs(db_conn, my_uid,
						     &assoc_cond);
	FREE_NULL_LIST(assoc_cond.cluster_list);
	if (!assoc_list) {
		exit_code = 1;
		fprintf(stderr, " Problem with query.\n");
		xfree(cluster_name);
		xfree(file_name);
		return SLURM_ERROR;
	} else if (!list_count(assoc_list)) {
		exit_code = 1;
		fprintf(stderr, " Cluster %s returned nothing.\n",
			cluster_name);
		FREE_NULL_LIST(assoc_list);
		xfree(cluster_name);
		xfree(file_name);
		return SLURM_ERROR;
	}

	slurmdb_hierarchical_rec_list = slurmdb_get_acct_hierarchical_rec_list(
		assoc_list);

	acct_list = acct_storage_g_get_accounts(db_conn, my_uid, NULL);

	if ((fd = fopen(file_name,"w")) == NULL) {
		fprintf(stderr, "Can't open file %s, %s\n", file_name,
			slurm_strerror(errno));
		FREE_NULL_LIST(acct_list);
		FREE_NULL_LIST(assoc_list);
		xfree(cluster_name);
		xfree(file_name);
		FREE_NULL_LIST(slurmdb_hierarchical_rec_list);
		return SLURM_ERROR;
	}

	/* Add header */
	if (fprintf(fd,
		    "# To edit this file start with a cluster line "
		    "for the new cluster\n"
		    "# Cluster - 'cluster_name':MaxNodesPerJob=50\n"
		    "# Followed by Accounts you want in this fashion "
		    "(root is created by default)...\n"
		    "# Parent - 'root'\n"
		    "# Account - 'cs':MaxNodesPerJob=5:MaxJobs=4:"
		    "MaxTRESMins=cpu=20:FairShare=399:"
		    "MaxWallDuration=40:Description='Computer Science':"
		    "Organization='LC'\n"
		    "# Any of the options after a ':' can be left out and "
		    "they can be in any order.\n"
		    "# If you want to add any sub accounts just list the "
		    "Parent THAT HAS ALREADY \n"
		    "# BEEN CREATED before the account line in this "
		    "fashion...\n"
		    "# Parent - 'cs'\n"
		    "# Account - 'test':MaxNodesPerJob=1:MaxJobs=1:"
		    "MaxTRESMins=cpu=1:FairShare=1:"
		    "MaxWallDuration=1:"
		    "Description='Test Account':Organization='Test'\n"
		    "# To add users to a account add a line like this after a "
		    "Parent - 'line'\n"
		    "# User - 'lipari':MaxNodesPerJob=2:MaxJobs=3:"
		    "MaxTRESMins=cpu=4:FairShare=1:"
		    "MaxWallDurationPerJob=1\n") < 0) {
		exit_code = 1;
		fprintf(stderr, "Can't write to file");
		FREE_NULL_LIST(acct_list);
		FREE_NULL_LIST(assoc_list);
		xfree(cluster_name);
		xfree(file_name);
		FREE_NULL_LIST(slurmdb_hierarchical_rec_list);
		return SLURM_ERROR;
	}

	line = xstrdup_printf("Cluster - '%s'", cluster_name);

	if (class_str)
		xstrfmtcat(line, ":Classification='%s'", class_str);

	slurmdb_hierarchical_rec = list_peek(slurmdb_hierarchical_rec_list);
	assoc = slurmdb_hierarchical_rec->assoc;
	if (xstrcmp(assoc->acct, "root")) {
		fprintf(stderr, "Root association not on the top it was %s\n",
			assoc->acct);
	} else
		print_file_add_limits_to_line(&line, assoc);

	if (fprintf(fd, "%s\n", line) < 0) {
		exit_code = 1;
		fprintf(stderr, " Can't write to file");
		FREE_NULL_LIST(acct_list);
		FREE_NULL_LIST(assoc_list);
		xfree(cluster_name);
		xfree(file_name);
		xfree(line);
		FREE_NULL_LIST(slurmdb_hierarchical_rec_list);
		return SLURM_ERROR;
	}
	info("%s", line);
	xfree(line);

	print_file_slurmdb_hierarchical_rec_list(
		fd, slurmdb_hierarchical_rec_list, user_list, acct_list);

	FREE_NULL_LIST(acct_list);
	FREE_NULL_LIST(assoc_list);
	xfree(cluster_name);
	xfree(file_name);
	FREE_NULL_LIST(slurmdb_hierarchical_rec_list);
	fclose(fd);

	return SLURM_SUCCESS;
}