int main(int argc, char **argv) { int inotify_fd; if (signal (SIGINT, signal_handler) == SIG_IGN) { signal (SIGINT, SIG_IGN); } inotify_fd = open_inotify_fd (); if (inotify_fd > 0) { queue_t q; q = queue_create(128); int wd; int index; wd = 0; printf("\n"); for (index = 1; (index < argc) && (wd >= 0); index++) { wd = watch_dir (inotify_fd, argv[index], IN_ALL_EVENTS); } if (wd > 0) { process_inotify_events (q, inotify_fd); } printf ("\nTerminating\n"); close_inotify_fd (inotify_fd); queue_destroy (q); } return 0; }
int main (int argc, char **argv) { /* This is the file descriptor for the inotify watch */ int inotify_fd; keep_running = 1; /* 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); } /* First we open the inotify dev entry */ inotify_fd = open_inotify_fd (); if (inotify_fd > 0) { /* We will need a place to enqueue inotify events, this is needed because if you do not read events fast enough, you will miss them. This queue is probably too small if you are monitoring something like a directory with a lot of files and the directory is deleted. */ queue_t q; q = queue_create (128); /* This is the watch descriptor returned for each item we are watching. A real application might keep these for some use in the application. This sample only makes sure that none of the watch descriptors is less than 0. */ int wd; /* Watch all events (IN_ALL_EVENTS) for the directories and files passed in as arguments. Read the article for why you might want to alter this for more efficient inotify use in your app. */ int index; wd = 0; printf("\n"); for (index = 1; (index < argc) && (wd >= 0); index++) { wd = watch_dir (inotify_fd, argv[index], IN_ALL_EVENTS); /*wd = watch_dir (inotify_fd, argv[index], IN_ALL_EVENTS & ~(IN_CLOSE | IN_OPEN) ); */ } if (wd > 0) { /* Wait for events and process them until a termination condition is detected */ process_inotify_events (q, inotify_fd); } printf ("\nTerminating\n"); /* Finish up by closing the fd, destroying the queue, and returning a proper code */ close_inotify_fd (inotify_fd); queue_destroy (q); } return 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; }
int inotifyStart() { int inotify_fd; int i; //Folders allfolderlist; keep_running = 1; need_restart_inotify = 0; add_new_watch_item = 0; /* First we open the inotify dev entry */ inotify_fd = open_inotify_fd (); if (inotify_fd > 0) { queue_t q; q = queue_create (128); int wd; wd = 0; memset(&allfolderlist,0,sizeof(Folders)); //printf("list num is %d\n",pathlist.number); for( i = 0 ; i < pathlist.number; i++) { //printf("list is %s\n",pathlist.folderlist[i].name); get_all_folders(pathlist.folderlist[i].name,&allfolderlist,allfolderlist.number); } //for( i = 0 ; i < number; i++)uploadFile //strcpy(allfolderlist.folderlist[0].name,dirname); //allfolderlist.number = 1; printf("\n"); for( i = 0; (i<allfolderlist.number) && (wd >= 0);i++) { wd = watch_dir (inotify_fd, allfolderlist.folderlist[i].name, IN_ALL_EVENTS); //printf("minitor path is %s\n",allfolderlist.folderlist[i].name); } if (wd > 0) { process_inotify_events (q, inotify_fd); } printf ("\nTerminating\n"); close_inotify_fd (inotify_fd); queue_destroy (q); if(need_restart_inotify == 1) inotifyStart(); } return 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; }
static int inotify_test(void) { int inotify_fd; DIR *director_watch; struct dirent *de; inotify_fd = open_inotify_fd(); if (inotify_fd > 0) { /* We will need a place to enqueue inotify events, this is needed because if you do not read events fast enough, you will miss them. This queue is probably too small if you are monitoring something like a directory with a lot of files and the directory is deleted. */ queue_t q; q = queue_create(128); /* This is the watch descriptor returned for each item we are watching. A real application might keep these for some use in the application. This sample only makes sure that none of the watch descriptors is less than 0. */ /* Watch all events (IN_ALL_EVENTS) for the directories and files passed in as arguments. Read the article for why you might want to alter this for more efficient inotify use in your app. */ int index; wd = 0; printf("\n"); /* for (index = 1; (index < argc) && wd >= 0); index++) { */ /* wd = watch_dir(inotify_fd, argv[index], IN_ALL_EVENTS); */ /* } */ director_watch = opendir(WATCH_PATH); if (director_watch == 0) return; while((de = readdir(director_watch)) != 0) { if(bad_name(de->d_name)) continue; snprintf(busname, sizeof busname, "%s/%s", WATCH_PATH, de->d_name); int wd = watch_dir(inotify_fd, busname, IN_DELETE | IN_CREATE); if (wd > 0){ LOG("chiplua add %s", busname); } process_inotify_events(q, inotify_fd); } return 0; } /* wd = watch_dir(inotify_fd, WATCH_PATH, IN_DELETE | IN_CREATE); */ /* if (wd > 0) { */ /* /\* Wait for events and process them until a */ /* temination condition is detected. */ /* *\/ */ /* process_inotify_events(q, inotify_fd); */ /* } */ /* printf("\nTerminating\n"); */ /* /\* Finish up by closing the fd, destroying the queue, */ /* and returning a proper code. */ /* *\/ */ /* close_inotify_fd(inotify_fd); */ /*queue_destroy(q); */ }