Пример #1
0
int argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite)
{
	int i;

	/* if the provided array is NULL, then the arg cannot be present,
	 * so just go ahead and append
	 */
	if (NULL == *argv) {
		return argv_append_nosize(argv, arg);
	}

	/* see if this arg is already present in the array */
	for (i=0; NULL != (*argv)[i]; i++) {
		if (0 == strcmp(arg, (*argv)[i])) {
			/* already exists - are we authorized to overwrite? */
			if (overwrite) {
				free((*argv)[i]);
				(*argv)[i] = strdup(arg);
			}
			return RT_SUCCESS;
		}
	}

	/* we get here if the arg is not in the array - so add it */
	return argv_append_nosize(argv, arg);
}
Пример #2
0
/*
 * allocate resources for a job.
 *
 * The job will consist of at least one app, e.g., "allocate
 * jobid=100 return=all timeout=10:app=0 np=5 N=2
 * node_list=vm2,vm3 flag=mandatory:app=1 N=2".
 *
 * IN:
 * 	new_fd: send allocation result to socket_fd
 * 	msg: resource requirement cmd
 */
extern void allocate_job_op(slurm_fd_t new_fd, const char *msg)
{
	char orte_jobid[16] = "";
	char return_flag[16] = "";
	size_t job_timeout = 15; /* if not specified, by default */

	char send_buf[SIZE];
	char **app_argv = NULL, **tmp_app_argv;
	size_t app_timeout;
	uint32_t app_count = 1;
	char app_resp_msg[SIZE];
	char **all_resp_msg_argv = NULL, **tmp_all_resp_msg_argv;

	app_argv = argv_split(msg, ':');
	/* app_count dose not include the first part (job info) */
	app_count = argv_count(app_argv) - 1;
	/* app_argv will be freed */
	tmp_app_argv = app_argv;
	while (*tmp_app_argv) {
		if (strstr(*tmp_app_argv, "allocate")) {
			_parse_job_params(*tmp_app_argv, orte_jobid,
								return_flag, &job_timeout);
		} else if (strstr(*tmp_app_argv, "app")) {
			app_timeout = job_timeout / app_count;

			_allocate_app_op(*tmp_app_argv, app_timeout, app_resp_msg);

			if (0 == strcmp(return_flag, "all")
					&& 0 != strlen(app_resp_msg)) {
				argv_append_nosize(&all_resp_msg_argv, app_resp_msg);
			} else if (0 != strlen(app_resp_msg)) {
				/* if return_flag != "all",
				 * each app's allocation will be sent individually */
				sprintf(send_buf, "jobid=%s:%s", orte_jobid, app_resp_msg);
				info("BBB: send to client: %s", send_buf);
				send_reply(new_fd, send_buf);
			}
		}
		tmp_app_argv++;
	}
	/* free app_argv */
	argv_free(app_argv);

	if (0 == strcmp(return_flag, "all")) {
		sprintf(send_buf, "jobid=%s", orte_jobid);
		/* all_resp_msg_argv will be freed */
		tmp_all_resp_msg_argv = all_resp_msg_argv;
		while (*tmp_all_resp_msg_argv) {
			sprintf(send_buf, "%s:%s", send_buf, *tmp_all_resp_msg_argv);
			tmp_all_resp_msg_argv++;
		}
		/* free all_resp_msg_argv */
		argv_free(all_resp_msg_argv);

		info("BBB: send to client: %s", send_buf);
		send_reply(new_fd, send_buf);
	}
}
Пример #3
0
/*
 * Append a string to the end of a new or existing argv array.
 */
int argv_append(int *argc, char ***argv, const char *arg)
{
	int rc;

	/* add the new element */
	if (RT_SUCCESS != (rc = argv_append_nosize(argv, arg))) {
		return rc;
	}

	*argc = argv_count(*argv);

	return RT_SUCCESS;
}