Example #1
0
void
ltrace_init(int argc, char **argv) {
	struct opt_p_t *opt_p_tmp;

	atexit(normal_exit);
	signal(SIGINT, signal_exit);	/* Detach processes when interrupted */
	signal(SIGTERM, signal_exit);	/*  ... or killed */

	argv = process_options(argc, argv);
	init_global_config();
	while (opt_F) {
		/* If filename begins with ~, expand it to the user's home */
		/* directory. This does not correctly handle ~yoda, but that */
		/* isn't as bad as it seems because the shell will normally */
		/* be doing the expansion for us; only the hardcoded */
		/* ~/.ltrace.conf should ever use this code. */
		if (opt_F->filename[0] == '~') {
			char path[PATH_MAX];
			char *home_dir = getenv("HOME");
			if (home_dir) {
				strncpy(path, home_dir, PATH_MAX - 1);
				path[PATH_MAX - 1] = '\0';
				strncat(path, opt_F->filename + 1,
						PATH_MAX - strlen(path) - 1);
				read_config_file(path);
			}
		} else {
			read_config_file(opt_F->filename);
		}

		struct opt_F_t *next = opt_F->next;
		if (opt_F->own_filename)
			free(opt_F->filename);
		free(opt_F);
		opt_F = next;
	}
	if (command) {
		/* Check that the binary ABI is supported before
		 * calling execute_program.  */
		struct ltelf lte = {};
		open_elf(&lte, command);
		do_close_elf(&lte);

		pid_t pid = execute_program(command, argv);
		struct Process *proc = open_program(command, pid);
		if (proc == NULL) {
			fprintf(stderr, "couldn't open program '%s': %s\n",
				command, strerror(errno));
			exit(EXIT_FAILURE);
		}

		trace_set_options(proc);
		continue_process(pid);
	}
	opt_p_tmp = opt_p;
	while (opt_p_tmp) {
		open_pid(opt_p_tmp->pid);
		opt_p_tmp = opt_p_tmp->next;
	}
}
Example #2
0
int main(int argc, char *argv[])
{
    char ch;
    if(argc < 2){
	fprintf(stderr,"Usage: ./link_mining -f ../conf/link_mining.xml");
	return 1;
    }
    int is_daemon = 1;
    global_conf_st *g_conf = NULL;
    g_conf = (global_conf_st *)calloc(sizeof(global_conf_st),1);
    set_default_conf(g_conf);
    while( -1 != (ch = getopt(argc,argv,"f:h:?:D"))){
	switch(ch){
	case 'f':
	    init_global_config(g_conf,optarg);
	    break;
	case 'D':
	    is_daemon = 0;
	    break;
	case 'h':
	case '?':
	default:
	    fprintf(stderr,"Usage ./link_ming -f ../conf/link_mining.xml");
	}
    }
    g_thread_init(NULL);
    signal(SIGINT,signal_handler);
    signal(SIGTERM,signal_handler);
    signal(SIGHUP,signal_handler);
    signal(SIGPIPE,SIG_IGN);
    if(is_daemon && (daemon(0,0) == -1)){
	jlog(L_ERR,"daemon error");
    }
    thread_init(g_conf);
    MSG_PROCESSING = 0;
    reload_dump(g_conf);
    pthread_t receive_ppid;
    receive_ppid = init_receive_thread(g_conf);
    int i;
    while(!is_shutdown){
	sleep(1);
    }
    save_dump(g_conf);
    pthread_join(receive_ppid,NULL);
    save_dump(g_conf);
    int len = 0;
    for(i = 0;i<g_conf->max_thread;i++){
	len = g_async_queue_length(threads[i].msg_queue);
	jlog(L_DEBUG,"(%d)len: %d",i,len);
	pthread_cancel(threads[i].ppid);
    }
    pthread_mutex_lock(&init_lock);
    while(init_count >0)
	pthread_cond_wait(&init_cond,&init_lock);
    pthread_mutex_unlock(&init_lock);

    global_conf_free(g_conf);
    return 0;
}
void
ltrace_init(int argc, char **argv)
{
	setlocale(LC_ALL, "");

	struct opt_p_t *opt_p_tmp;

	atexit(normal_exit);
	signal(SIGINT, signal_exit);	/* Detach processes when interrupted */
	signal(SIGTERM, signal_exit);	/*  ... or killed */

	argv = process_options(argc, argv);
	init_global_config();

	if (command) {
		/* Check that the binary ABI is supported before
		 * calling execute_program.  */
		{
			struct ltelf lte;
			if (ltelf_init(&lte, command) == 0)
				ltelf_destroy(&lte);
			else
				exit(EXIT_FAILURE);
		}

		pid_t pid = execute_program(command, argv);
		struct process *proc = open_program(command, pid);
		if (proc == NULL) {
			fprintf(stderr, "couldn't open program '%s': %s\n",
				command, strerror(errno));
			exit(EXIT_FAILURE);
		}

		trace_set_options(proc);
		continue_process(pid);
	}
	opt_p_tmp = opt_p;
	while (opt_p_tmp) {
		open_pid(opt_p_tmp->pid);
		opt_p_tmp = opt_p_tmp->next;
	}
}
Example #4
0
File: cli.c Project: jhbsz/cpe
  /***********************************************************************
 * Function Name : main
 * Description    : command line main function
 * comparing possibly non-NULL strings.
 * Input         : 
 * Output        : 
 * Return value  : 
 ***********************************************************************/
int main(int argc, char **argv)
{
    CLI *pCli;
    int telnet = 0;
    int status;
    //int eof;
    int logon = FALSE;
    char *accessMode;

    int fin = STD_IN;
    //Deleted by Mario Huang
    int fout = STD_OUT;
	int nvram_exist = 0;
    pCli = cliInit();
    cliIoDevSet(pCli, fin, fout);

    /* Disable int, trap and abort */
    init_signals();
    /* [email protected] */
    setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
    if ((accessMode = getenv("ACCESS_MODE")) != NULL)
    {
        if (!strcmp(accessMode, "telnet"))
            telnet = 1;
    }

	//check nvram work?
    nvram_exist = nvram_workable();
    if(!nvram_exist)
	{
		uiPrintf("System booting, please wait...");
		sleep(5);
	}

	while(!nvram_workable())
	{
		sleep(5);
	}

	//load config to ram
	init_global_config();

	//print config
	debug_global_config();
	
  login:

	do
    {
        logon = cliLoginRead(pCli, telnet);
		if(!logon)
			exit(0);
    }while(!logon);

    for (;;)
    {
        status = parser(pCli, fin, cmdTbl);
        if (status == CLI_PARSE_QUIT)
        {
            /*
             * CLI super user can exit to shell,
             * and others cannot but login again.
             * add by Tony 2008.3.12
             */
        	if (telnet || g_su)
                exit(0);
        	else
                goto login;
        }

		if (status == CLI_PARSE_ACCESS_LINUX)
		{
			break;
		}
		
        if ((tokenCount(pCli) > 2) || (status == CLI_PARSE_TOO_MANY))
        {
            uiPrintf("Too many parameters!\n");
        }
        else if (status == CLI_PARSE_TOO_FEW)
        {
            uiPrintf("Not enough parameters!\n");
        }
        else if (status == CLI_PARSE_INVALID_PARAMETER)
        {
            uiPrintf("Invalid parameter!\n");
        }
        else if (status == CLI_PARSE_INPUT_ERROR)
        {
            uiPrintf("Invalid input characters!\n");
        }
        else if (status == CLI_PARSE_NO_VALUE)
        {
            uiPrintf("No parameter specified!\n");
        }
//TODO:Modified by Mario Huang
        //else if ((tokenCount(pCli) >= 1) && (cTimeofZone == 0))
        else if (tokenCount(pCli) >= 1)
        {
            uiPrintf("Too many parameters!\n");
        }
    }

	//free config
	free_global_config();
	
    return 0;
}
Example #5
0
/*
	Parse json string to c data structure, and then store them in global config
*/
int do_parse_config(const char *json_str, unsigned int size)
{
    int ret = -1;
    char *json_str_cpy = NULL;
    const nx_json *js = NULL, *js_elem = NULL;

    if (json_str == NULL || size <= 0) {
        AC_ERROR("invalid parameters.");
        return -1;
    }

    json_str_cpy = malloc(sizeof(char) * (size + 1));
    if (json_str_cpy == NULL) {
        goto out;
    }
    bzero(json_str_cpy, size + 1);
    memcpy(json_str_cpy, json_str, size);
    js = nx_json_parse_utf8(json_str_cpy);
    if (js == NULL) {
        AC_ERROR("config parse failed.\n");
        goto out;
    }

    if (nx_json_verify(js) != 0) {
        AC_ERROR("nxjson verify failed.\n");
        goto out;
    }

    init_global_config();

    /*parse control set*/
    js_elem = nx_json_get(js, CONTROL_SET_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_control_set(js_elem, &s_config.control->set) == 0) {
            display_control_set(&s_config.control->set);
        }
    }

    /*parse audit set*/
    js_elem = nx_json_get(js, AUDIT_SET_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_audit_set(js_elem, &s_config.audit->set) == 0) {
            display_audit_set(&s_config.audit->set);
        }
    }

    /*parse control rule*/
    js_elem = nx_json_get(js, CONTROL_RULE_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_control_rule(js_elem, &s_config.control->rule) == 0) {
            display_control_rule(&s_config.control->rule);
        }
        else {
            goto out;
        }
    }

    /*parse audit rule*/
    js_elem = nx_json_get(js, AUDIT_RULE_KEY);
    if (js_elem->type != NX_JSON_NULL) {
        if (do_parse_audit_rule(js_elem, &s_config.audit->rule) == 0) {
            display_audit_rule(&s_config.audit->rule);
        }
        else {
            goto out;
        }
    }

    ret = 0;
out:
    if (js != NULL) {
        nx_json_free(js);
    }
    if (json_str_cpy) {
        free(json_str_cpy);
    }
    if (ret != 0) {
        free_global_config();
    }
    return ret;
}