Ejemplo n.º 1
0
int main(int argc, const char** argv)
{

    parsed_options_t parsed_options;

    try {
        parse_options(argc, argv, parsed_options);

        /* Validate the command. */
        validate_cmd(parsed_options);

        ib_util_initialize();

        send_cmd(parsed_options);

        ib_util_shutdown();
    }
    catch (const IronBee::error& err) {
        IronBee::convert_exception();
        return 1;
    }
    catch (const  std::exception& err) {
        std::cerr<< "Error: " << err.what() << std::endl;
        return 1;
    }

    return 0;
}
Ejemplo n.º 2
0
/*
 * Function: main
 * Description: main function calls functions for intialization and 
 * command verification, excution and finalization
*/
int main(int argc, char *argv[])
{
	int ret = 0;
	WIMAX_API_RET wmxStatus;
	
	parsed_cmd out_cmd;

	//checking user priviledge
	//Disabled permission checking so non-root can run it
	//      if (geteuid() != (uid_t) 0) {
	//              fprintf(stderr,
	//                      "ERROR: You do not possess sufficient privileges to perform this action.\n");
	//              return 1;
	//      }

	// validate user command
	if (validate_cmd(argc, argv, &out_cmd) != 0) {
		wimaxcu_main_help();
		return 1;
	}
	// If user requested to diplay the help
	if (out_cmd.cmd == CMD_HELP) {
		wimaxcu_main_help();
		return 0;
	}
	memset(&gbl_device_id, 0, sizeof(WIMAX_API_DEVICE_ID));
	// Request for READ_WRITE Permissions
	// TODO: Kalyan Can we request for permissions based on the command?
	// For example for status Read permission is sufficient.
	gbl_device_id.privilege = WIMAX_API_PRIVILEGE_READ_WRITE;

	//Signal to handle Ctrl+C
	signal(SIGINT, wimaxcu_stop_signal_handler);
	signal(SIGTERM, wimaxcu_stop_signal_handler);

	// Initialize the SDK (CommonAPI)
	wmxStatus = wimaxcu_initialize(&gbl_device_id);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		printf("ERROR: Make sure WiMAX Network Service is running.\n");
		return 1;
	}
	// Kalyan 5.0.09 merge
	// This delay will allow the Initialize to init everything in its threads
	// sleep(1);
	// Execute the command
	ret = cmd_handler(&gbl_device_id, &out_cmd);
	// Finalize the SDK
	wimaxcu_finalize(&gbl_device_id);

	return ret;
}
Ejemplo n.º 3
0
/***************************************************************************************
Function 	: handle_cmd_ln_intr
Description	: It starts with user input parsing, analysing and calling the specific execution
				function.
****************************************************************************************/
void handle_cmd_ln_intr(char input[])
{
	bool quit = 0;
	bool status;
	int index=0;
	char input1[MAX_CMD_SIZE];
	char *str_tok;
	{

		input[strlen(input)-1]='\0';
		for(index=0;index<MAX_CMD_LN_VAR;index++)
		{
			cmd_arg_var[index] = malloc(MAX_CMD_SIZE);
			memset(cmd_arg_var[index],0,MAX_CMD_SIZE);
		}
		str_tok = strtok (input," ");
		index = 0;

		while (str_tok != NULL)
		{
			strcpy(cmd_arg_var[index],str_tok);
			str_tok = strtok (NULL, " ");
			index++;
		}
		index=0;
		while(cmd_arg_var[0][index])
		{
			cmd_arg_var[0][index] = toupper(cmd_arg_var[0][index]);
			index++;
		}
		index = 0;
		status = validate_cmd(cmd_arg_var);
		if(status)
			cmd_line_execute(cmd_arg_var);
		else
			printf("Not a valid TCP Command!\n");
	}
}
Ejemplo n.º 4
0
//!
//! Main entry point of the application
//!
//! @param[in] argc the number of parameter passed on the command line
//! @param[in] argv the list of arguments
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int main(int argc, char *argv[])
{
    int i = 0;
    int ret = EUCA_OK;
    int nparams = 0;
    int ncmds = 0;
    char *eq = NULL;
    char *key = NULL;
    char *val = NULL;
    char euca_root[] = "";
    char argv_str[4096] = "";
    char *cmd_name = NULL;
    char pid_file[EUCA_MAX_PATH] = "";
    FILE *fp = NULL;
    pid_t pid = 0;
    artifact *root = NULL;
    blobstore *work_bs = NULL;
    blobstore *cache_bs = NULL;
    imager_param *cmd_params = NULL;

    log_fp_set(stderr); // imager logs to stderr so image data can be piped to stdout
    set_debug(print_debug);

    // initialize globals
    artifacts_map = map_create(10);

    // use $EUCALYPTUS env var if available
    euca_home = getenv(EUCALYPTUS_ENV_VAR_NAME);
    if (!euca_home) {
        euca_home = euca_root;
    }
    // save the command line into a buffer so it's easier to rerun it by hand
    argv_str[0] = '\0';
    for (i = 0; i < argc; i++) {
        strncat(argv_str, "\"", sizeof(argv_str) - strlen(argv_str) - 1);
        strncat(argv_str, argv[i], sizeof(argv_str) - strlen(argv_str) - 1);
        strncat(argv_str, "\" ", sizeof(argv_str) - strlen(argv_str) - 1);
    }

    // initialize dependencies
    if (vmdk_init() == EUCA_OK) {
        vddk_available = TRUE;
    }

    // parse command-line parameters
    while (*(++argv)) {
        eq = strstr(*argv, "=");       // all params have '='s
        if (eq == NULL) {              // it's a command
            // process previous command, if any
            if (validate_cmd(ncmds, cmd_name, cmd_params, *argv) != NULL)
                ncmds++;               // increment only if there was a previous command

            if (ncmds + 1 > MAX_REQS)
                err("too many commands (max is %d)", MAX_REQS);

            cmd_name = *argv;
            cmd_params = NULL;
            nparams = 0;
        } else {                       // this is a parameter
            if (strlen(eq) == 1)
                usage("parameters must have non-empty values");
            *eq = '\0';                // split key from value
            if (strlen(*argv) == 1)
                usage("parameters must have non-empty names");

            key = *argv;
            val = eq + 1;
            if (key == NULL || val == NULL)
                usage("syntax error in parameters");

            if (key[0] == '-')
                key++;                 // skip '-' if any

            if (key[0] == '-')
                key++;                 // skip second '-' if any

            if (cmd_name == NULL) {    // without a preceding command => global parameter
                set_global_parameter(key, val);
                continue;
            }

            if (cmd_params == NULL) {
                cmd_params = calloc(MAX_PARAMS + 1, sizeof(imager_param));  // +1 for terminating NULL
                if (!cmd_params)
                    err("calloc failed");
            }

            if (nparams + 1 > MAX_PARAMS)
                err("too many parameters (max is %d)", MAX_PARAMS);
            cmd_params[nparams].key = key;
            cmd_params[nparams].val = val;
            nparams++;
        }
    }

    if (validate_cmd(ncmds, cmd_name, cmd_params, *argv) != NULL)   // validate last command
        ncmds++;

    LOGINFO("verified all parameters for %d command(s)\n", ncmds);
    if (print_argv) {
        LOGDEBUG("argv[]: %s\n", argv_str);
    }
    // record PID, which may be used by VB to kill the imager process (e.g., in cancelBundling)
    pid = getpid();
    sprintf(pid_file, "%s/imager.pid", get_work_dir());
    if ((fp = fopen(pid_file, "w")) == NULL) {
        err("could not create pid file");
    } else {
        fprintf(fp, "%d", pid);
        fclose(fp);
    }

    // invoke the requirements checkers in the same order as on command line,
    // constructing the artifact tree originating at 'root'
    for (i = 0; i < ncmds; i++) {
        if (reqs[i].cmd->requirements != NULL) {
            art_set_instanceId(reqs[i].cmd->name);  // for logging
            if ((root = reqs[i].cmd->requirements(&reqs[i], root)) == NULL) // pass results of earlier checkers to later checkers
                err("failed while verifying requirements");
        }
    }

    // it is OK for root to be NULL at this point

    // see if work blobstore will be needed at any stage
    // and open or create the work blobstore
    if (root && tree_uses_blobstore(root)) {
        // set the function that will catch blobstore errors
        blobstore_set_error_function(&bs_errors);

        if (ensure_directories_exist(get_work_dir(), 0, NULL, NULL, BLOBSTORE_DIRECTORY_PERM) == -1)
            err("failed to open or create work directory %s", get_work_dir());

        work_bs = blobstore_open(get_work_dir(), get_work_limit() / 512, BLOBSTORE_FLAG_CREAT, BLOBSTORE_FORMAT_FILES, BLOBSTORE_REVOCATION_NONE, BLOBSTORE_SNAPSHOT_ANY);
        if (work_bs == NULL) {
            err("failed to open work blobstore: %s", blobstore_get_error_str(blobstore_get_error()));
        }
        // no point in fscking the work blobstore as it was just created
    }
    // see if cache blobstore will be needed at any stage
    if (root && tree_uses_cache(root)) {
        if (ensure_directories_exist(get_cache_dir(), 0, NULL, NULL, BLOBSTORE_DIRECTORY_PERM) == -1)
            err("failed to open or create cache directory %s", get_cache_dir());
        cache_bs = blobstore_open(get_cache_dir(), get_cache_limit() / 512, BLOBSTORE_FLAG_CREAT, BLOBSTORE_FORMAT_DIRECTORY, BLOBSTORE_REVOCATION_LRU, BLOBSTORE_SNAPSHOT_ANY);
        if (cache_bs == NULL) {
            blobstore_close(work_bs);
            err("failed to open cache blobstore: %s\n", blobstore_get_error_str(blobstore_get_error()));
        }

        if (blobstore_fsck(cache_bs, NULL)) //! @TODO: verify checksums?
            err("cache blobstore failed integrity check: %s", blobstore_get_error_str(blobstore_get_error()));

        if (stat_blobstore(get_cache_dir(), cache_bs))
            err("blobstore is unreadable");
    }
    // implement the artifact tree
    ret = EUCA_OK;
    if (root) {
        art_set_instanceId("imager");  // for logging
        ret = art_implement_tree(root, work_bs, cache_bs, NULL, INSTANCE_PREP_TIMEOUT_USEC);    // do all the work!
    }
    // invoke the cleaners for each command to tidy up disk space and memory allocations
    for (i = 0; i < ncmds; i++) {
        if (reqs[i].cmd->cleanup != NULL) {
            art_set_instanceId(reqs[i].cmd->name);  // for logging
            reqs[i].cmd->cleanup(&reqs[i], (i == (ncmds - 1)) ? (TRUE) : (FALSE));
        }
    }

    // free the artifact tree
    if (root) {
        if (tree_uses_blobstore(root)) {
            if (blobstore_fsck(work_bs, stale_blob_examiner)) { // will remove all blobs
                LOGWARN("failed to clean up work space: %s\n", blobstore_get_error_str(blobstore_get_error()));
            }
        }
        art_free(root);
    }
    clean_work_dir(work_bs);

    // indicate completion
    LOGINFO("imager done (exit code=%d)\n", ret);

    exit(ret);
}