@@ -10,9 +10,7 @@ void monitoring(void) // 모니터링
10
10
FILE * fp ; // log.txt 파일 구조체
11
11
int old_list_cnt , new_list_cnt ; // 모니터링 디렉토리 파일 개수(기존, 신규)
12
12
file_node * old_list , * new_list ; // 모니터링 디렉토리 트리(기존, 신규)
13
- int is_first ;
14
13
int change_list_cnt ;
15
- time_t start_t ;
16
14
17
15
getcwd (pwd , BUFFER_SIZE );
18
16
sprintf (check_path , "%s/%s" , pwd , CHECK );
@@ -32,23 +30,13 @@ void monitoring(void) // 모니터링
32
30
// 프로세스 이름 변경
33
31
prctl (PR_SET_NAME , "ssu_mntr-daemon0円" , NULL , NULL , NULL );
34
32
35
- start_t = time (NULL );
36
- is_first = true;
33
+ old_list = make_list (check_path );
37
34
38
35
while (true) {
39
36
40
37
change_list_cnt = 0 ;
41
38
42
39
new_list = make_list (check_path ); // 현재 파일 목록 및 상태 저장
43
- new_list_cnt = count_file (new_list -> child ); // 현재 목록에 존재하는 파일 개수
44
- init_list_status (new_list -> child , UNCHCK ); // 현재 파일 목록 모니터링 상태 초기화
45
-
46
- if (is_first ) { // 최초 실행일 경우
47
- old_list = new_list ;
48
- old_list_cnt = new_list_cnt ;
49
- is_first = false;
50
- continue ;
51
- }
52
40
53
41
compare_list (new_list -> child , old_list -> child ); // 파일 목록 트리 비교
54
42
change_list_cnt = write_change_list (new_list -> child , change_list_cnt , CREATE ); // 생성된 파일 확인
@@ -59,12 +47,10 @@ void monitoring(void) // 모니터링
59
47
free_list (old_list );
60
48
61
49
old_list = new_list ;
62
- old_list_cnt = new_list_cnt ;
63
50
init_list_status (old_list -> child , UNCHCK );
64
51
65
52
sleep (1 );
66
53
}
67
- exit (0 );
68
54
}
69
55
70
56
@@ -74,10 +60,7 @@ void init_list_status(file_node *head, int status) // 모니터링 파일 상태
74
60
75
61
now = head ;
76
62
77
- while (true) {
78
-
79
- if (now == NULL )
80
- break ;
63
+ while (now != NULL ) {
81
64
82
65
now -> status = status ;
83
66
@@ -88,30 +71,6 @@ void init_list_status(file_node *head, int status) // 모니터링 파일 상태
88
71
}
89
72
}
90
73
91
- int count_file (file_node * head ) // 파일 개수 반환
92
- {
93
- int cnt ;
94
- file_node * now ;
95
-
96
- now = head ;
97
- cnt = false;
98
-
99
- while (true) { // 개수 탐색 시작
100
-
101
- if (now == NULL )
102
- break ;
103
-
104
- cnt ++ ;
105
-
106
- if (now -> child != NULL ) // 현재 탐색하는 파일이 디렉토리일 경우
107
- cnt += count_file (now -> child ); // 해당 디렉토리 파일 개수 재귀 탐색
108
-
109
- now = now -> next ; // 다음 파일 탐색
110
- }
111
-
112
- return cnt ;
113
- }
114
-
115
74
void compare_list (file_node * new_list , file_node * old_list ) // 파일 목록 트리 비교
116
75
{
117
76
file_node * now ;
@@ -121,10 +80,7 @@ void compare_list(file_node *new_list, file_node *old_list) // 파일 목록 트
121
80
122
81
now = old_list ;
123
82
124
- while (true) {
125
-
126
- if (now == NULL )
127
- break ;
83
+ while (now != NULL ) {
128
84
129
85
compare_file (new_list , now );
130
86
@@ -141,10 +97,7 @@ int compare_file(file_node *new_file, file_node *old_file) // 파일 정보 비
141
97
142
98
now = new_file ;
143
99
144
- while (true) {
145
-
146
- if (now == NULL )
147
- break ;
100
+ while (now != NULL ) {
148
101
149
102
if (!strcmp (now -> name , old_file -> name )) { // 해당 이름을 가진 파일이 기존에 이미 존재할 경우
150
103
now -> status = CHCKED ;
@@ -172,10 +125,7 @@ int write_change_list(file_node *head, int idx, int status) // 변경사항 목
172
125
173
126
now = head ;
174
127
175
- while (true) {
176
-
177
- if (now == NULL )
178
- break ;
128
+ while (now != NULL ) {
179
129
180
130
switch (now -> status ) {
181
131
case UNCHCK :
0 commit comments