Beispiel #1
0
/*
   main function
 */
int main(int argc, char** argv){
	int numCPU;
	int fdDevice = 0;
	struct blk_user_trace_setup buts;
	struct list_head *shark_boss = NULL;
	struct list_head *p;
	int buts_stat = BUTS_STAT_NONE;
	int ret;

	strcpy(outPath,"dioshark.output");

	DBGOUT("sysconf() entry \n");
	// get the number of cpus
	numCPU = sysconf(_SC_NPROCESSORS_ONLN);
	DBGOUT("set_signalHandler() entry \n");
	// set signal handler function
	set_signalHandler();

	// handle args
	if( !parse_args(argc, argv) ) {
		fprintf(stderr, "dio-shark argument error.\n");
		goto out;
	}

	DBGOUT("openfile_device() entry \n");
	// open device file	
	fdDevice = openfile_device(devPath);
	if(fdDevice < 0)
	{
		fprintf(stderr, "openfile_device() failed: %d/%s\n", errno, strerror(errno));
		goto out;
	}
	DBGOUT("setup_buts() entry \n");
	// setup blk_user_trace_setup
	setup_buts(&buts);
	DBGOUT("ioctl-BLKTRACESETUP entry \n");
	// device controller setup
	ret = ioctl(fdDevice, BLKTRACESETUP, &buts);
	if(ret < 0)
	{
		fprintf(stderr, "ioctl-BLKTRACESETUP failed: %d/%s\n", errno, strerror(errno));
		goto out;
	}
	buts_stat = BUTS_STAT_SETUPED;
	strcpy(devName,buts.name);
	DBGOUT("create_list_head() entry \n");
	// create list head for creating threads
	shark_boss = create_list_head();
	DBGOUT("loose_sharks() entry \n");
	// initialize barrier variable
	pthread_barrier_init(&g_barrier, NULL, numCPU + 1);

	// create threads
	ret = loose_sharks(shark_boss, numCPU);
	if(ret == (int)false)
	{
		fprintf(stderr, "loose_sharks() failed: %d/%s\n", errno, strerror(errno));
		goto out;
	}
	DBGOUT("wait_open_debugfs() entry \n");
	// wait until open debug file
	wait_open_debugfs();
	DBGOUT("ioctl-BLKTRACESTART entry \n");
	// device controller start
	ret = ioctl(fdDevice, BLKTRACESTART);
	if(ret < 0)
	{
		fprintf(stdout, "ioctl-BLKTRACESTART failed: %d/%s\n", errno, strerror(errno));
		goto out;
	}
	buts_stat = BUTS_STAT_STARTED;
	DBGOUT("wait_comeback_shark() entry \n");
	// wait until all thread terminate
	wait_comeback_shark(shark_boss);
out:

	DBGOUT("buts_stat = %d \n", buts_stat);
	// device controller stop
	if(buts_stat != BUTS_STAT_NONE)
	{
		ret = ioctl(fdDevice, BLKTRACESTOP);
		if(ret < 0)
		{
			fprintf(stdout, "ioctl-BLKTRACESTOP failed: %d/%s\n", errno, strerror(errno));
		}

		ret = ioctl(fdDevice, BLKTRACETEARDOWN);
		if(ret < 0)
		{
			fprintf(stdout, "ioctl-BLKTRACEDOWN failed: %d/%s\n", errno, strerror(errno));
		}
	}

	// fasten sharks that loosed
	if(!list_empty(shark_boss))
	{
		fasten_sharks(shark_boss);
	}

	// destroy list head
	if(shark_boss != NULL)
	{
		free(shark_boss);
	}

	// close device file
	if(fdDevice != 0)
	{
		close(fdDevice);
	}

	// put signal handler
	put_signalHandler();

	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    //base_path = argv[1];

    //initConfig2(CONFIG_GER_PATH);


    /*
    if(argc < 2)
    {
        printf("usage: inotify path\n");
        return -1;
    }
    */


    //strcpy(base_path,"/tmp/Cloud");

    //printf("inotify base path is %s\n",base_path);

    //if(NULL == opendir(base_path))
    //mkdir(base_path,0777);

    //sprintf(inotify_path,"%s/%s",base_path,"inotify_file");

    //my_mkdir_r(inotify_path);

    //sprintf(moved_from_file,"%s/%s",inotify_path,"moved_from");
    //sprintf(moved_to_file,"%s/%s",inotify_path,"moved_to");

    //if(NULL == opendir(BASIC_PATH))
    //mkdir(BASIC_PATH,0777);

    //if(NULL == opendir(inotify_path))
       // mkdir(inotify_path,0777);

    //keep_running = 1;

    //pathlist.number = 0;          //add by alan

    //create allfolderlist !!!

    create_file_list = create_list_head();

    allfolderlist = (Folder *)malloc(sizeof(Folder));
    allfolderlist->name = NULL;
    allfolderlist->next = NULL;
    allfolderlist_tail = allfolderlist;
    //create pathlist !!!
    pathlist = (Folder *)malloc(sizeof(Folder));
    pathlist->name = NULL;
    pathlist->next = NULL;
    pathlist_tail = pathlist;

    inotify_fd = open_inotify_fd ();
    pthread_mutex_init(&mutex_allfolderlist, NULL);
    pthread_mutex_init(&mutex_inotify_fd, NULL);
    pthread_mutex_init(&mutex_pathlist, NULL);
    dragfolder_wd = 0;

    /* Set a ctrl-c signal handler */
    if (signal (SIGINT, signal_handler) == SIG_IGN)
    {
        /* Reset to SIG_IGN (ignore) if that was the prior state */
        signal (SIGINT, SIG_IGN);
    }

    pthread_t newthid1,newthid2;

    if( pthread_create(&newthid1,NULL,(void *)watch_socket,NULL) != 0)
    {
        printf("thread creation failder\n");
        exit(1);
    }

    if( pthread_create(&newthid2,NULL,(void *)watch_folder,NULL) != 0)
    {
        printf("thread creation failder\n");
        exit(1);
    }
    //sleep(1);

    pthread_join(newthid2,NULL);

    close_inotify_fd (inotify_fd);

    return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    exit_loop = 0;

    my_mkdir("/tmp/smartsync");
    my_mkdir("/tmp/smartsync/script");
    create_shell_file();

    //pre_event = -1;
    //pre_pre_event = -1;

    create_file_list = create_list_head();

    allfolderlist = (Folder *)malloc(sizeof(Folder));
    allfolderlist->name = NULL;
    allfolderlist->next = NULL;
    allfolderlist_tail = allfolderlist;
    //create pathlist !!!
    pathlist = (Folder *)malloc(sizeof(Folder));
    pathlist->name = NULL;
    pathlist->next = NULL;
    pathlist_tail = pathlist;

    inotify_fd = open_inotify_fd ();
    pthread_mutex_init(&mutex_allfolderlist, NULL);
    pthread_mutex_init(&mutex_inotify_fd, NULL);
    pthread_mutex_init(&mutex_pathlist, NULL);
    dragfolder_wd = 0;

    sigset_t bset,oset;
    pthread_t sig_thread;
    sigemptyset(&bset);
    sigaddset(&bset,SIGTERM);

    if( pthread_sigmask(SIG_BLOCK,&bset,&oset) == -1)
        printf("!! Set pthread mask failed\n");

    if( pthread_create(&sig_thread,NULL,(void *)sigmgr_thread,NULL) != 0)
    {
        printf("thread creation failder\n");
        exit(-1);
    }

    pthread_t newthid1,newthid2;

    if( pthread_create(&newthid1,NULL,(void *)watch_socket,NULL) != 0)
    {
        printf("thread creation failder\n");
        exit(1);
    }

    if( pthread_create(&newthid2,NULL,(void *)watch_folder,NULL) != 0)
    {
        printf("thread creation failder\n");
        exit(1);
    }
    //sleep(1);

    pthread_join(newthid2,NULL);

    close_inotify_fd (inotify_fd);

    return 0;
}