@@ -72,15 +72,16 @@ volatile atomic_bool stop = false, hup = false, run_stats = false;
72
72
// Local variables
73
73
static conf_t config ;
74
74
// This holds info about all file systems to watch
75
- struct fs_avl {
75
+ typedef struct fs_avl {
76
76
avl_tree_t index ;
77
- };
77
+ } fs_avl ;
78
78
// This is the data about a specific file system to watch
79
79
typedef struct fs_data {
80
80
avl_t avl ; // This has to be first
81
81
const char * fs_name ;
82
82
} fs_data_t ;
83
- static struct fs_avl filesystems ;
83
+ static fs_avl filesystems ;
84
+ static fs_avl ignored_mounts ;
84
85
85
86
// List of mounts being watched
86
87
static mlist * m = NULL ;
@@ -141,27 +142,27 @@ static void free_filesystem(fs_data_t *s)
141
142
}
142
143
143
144
144
- static void destroy_filesystem (void )
145
+ static void destroy_filesystem (fs_avl * fs )
145
146
{
146
- avl_t * cur = filesystems . index .root ;
147
+ avl_t * cur = fs -> index .root ;
147
148
148
- fs_data_t * tmp = (fs_data_t * )avl_remove (& filesystems . index , cur );
149
+ fs_data_t * tmp = (fs_data_t * )avl_remove (& fs -> index , cur );
149
150
if ((avl_t * )tmp != cur )
150
151
msg (LOG_DEBUG , "filesystem: removal of invalid node" );
151
152
free_filesystem (tmp );
152
153
}
153
154
154
155
155
- static void destroy_fs_list (void )
156
+ static void destroy_fs_list (fs_avl * fs )
156
157
{
157
- while (filesystems . index .root )
158
- destroy_filesystem ();
158
+ while (fs -> index .root )
159
+ destroy_filesystem (fs );
159
160
}
160
161
161
162
162
- static int add_filesystem (fs_data_t * f )
163
+ static int add_filesystem (fs_avl * fs , fs_data_t * f )
163
164
{
164
- fs_data_t * tmp = (fs_data_t * )avl_insert (& filesystems . index ,(avl_t * )(f ));
165
+ fs_data_t * tmp = (fs_data_t * )avl_insert (& fs -> index ,(avl_t * )(f ));
165
166
if (tmp ) {
166
167
if (tmp != f ) {
167
168
msg (LOG_DEBUG , "fs_list: duplicate filesystem found" );
@@ -173,40 +174,40 @@ static int add_filesystem(fs_data_t *f)
173
174
}
174
175
175
176
176
- static fs_data_t * new_filesystem (const char * fs )
177
+ static fs_data_t * new_filesystem (fs_avl * fs , const char * f )
177
178
{
178
179
fs_data_t * tmp = malloc (sizeof (fs_data_t ));
179
180
if (tmp ) {
180
- tmp -> fs_name = fs ? strdup (fs ) : strdup ("" );
181
- if (add_filesystem (tmp ) != 0 )
181
+ tmp -> fs_name = fs ? strdup (f ) : strdup ("" );
182
+ if (add_filesystem (fs , tmp ) != 0 )
182
183
return NULL ;
183
184
}
184
185
return tmp ;
185
186
}
186
187
187
188
188
- static fs_data_t * find_filesystem (const char * f )
189
+ static fs_data_t * find_filesystem (fs_avl * fs , const char * f )
189
190
{
190
191
fs_data_t tmp ;
191
192
192
193
tmp .fs_name = f ;
193
- return (fs_data_t * )avl_search (& filesystems . index , (avl_t * ) & tmp );
194
+ return (fs_data_t * )avl_search (& fs -> index , (avl_t * ) & tmp );
194
195
}
195
196
196
197
197
- static void init_fs_list (const char * watch_fs )
198
+ static void init_fs_list (fs_avl * fs , const char * watch_fs )
198
199
{
199
200
if (watch_fs == NULL ) {
200
201
msg (LOG_ERR , "File systems to watch is empty" );
201
202
exit (1 );
202
203
}
203
- avl_init (& filesystems . index , cmp_fs );
204
+ avl_init (& fs -> index , cmp_fs );
204
205
205
206
// Now parse up list and push into avl
206
207
char * ptr , * saved , * tmp = strdup (watch_fs );
207
208
ptr = strtok_r (tmp , "," , & saved );
208
209
while (ptr ) {
209
- new_filesystem (ptr );
210
+ new_filesystem (fs , ptr );
210
211
ptr = strtok_r (NULL , "," , & saved );
211
212
}
212
213
free (tmp );
@@ -344,13 +345,12 @@ static int become_daemon(void)
344
345
// Returns 1 if we care about the entry and 0 if we do not
345
346
static int check_mount_entry (const char * point , const char * type )
346
347
{
347
- // Some we know we don't want
348
- if (strcmp (point , "/run" ) == 0 )
349
- return 0 ;
350
- if (strncmp (point , "/sys" , 4 ) == 0 )
348
+ // ignored mount points
349
+ if (find_filesystem (& ignored_mounts , point ))
351
350
return 0 ;
352
351
353
- if (find_filesystem (type ))
352
+ // wanted filesystems
353
+ if (find_filesystem (& filesystems , type ))
354
354
return 1 ;
355
355
else
356
356
return 0 ;
@@ -640,7 +640,8 @@ int main(int argc, const char *argv[])
640
640
}
641
641
642
642
// Setup filesystem to watch list
643
- init_fs_list (config .watch_fs );
643
+ init_fs_list (& filesystems , config .watch_fs );
644
+ init_fs_list (& ignored_mounts , config .ignore_mounts );
644
645
645
646
// Write the pid file for the init system
646
647
write_pid_file ();
@@ -678,7 +679,7 @@ int main(int argc, const char *argv[])
678
679
if (init_database (& config )) {
679
680
destroy_event_system ();
680
681
destroy_rules ();
681
- destroy_fs_list ();
682
+ destroy_fs_list (& filesystems );
682
683
free_daemon_config (& config );
683
684
unlink (pidfile );
684
685
exit (1 );
@@ -757,7 +758,8 @@ int main(int argc, const char *argv[])
757
758
}
758
759
destroy_event_system ();
759
760
destroy_rules ();
760
- destroy_fs_list ();
761
+ destroy_fs_list (& filesystems );
762
+ destroy_fs_list (& ignored_mounts );
761
763
free_daemon_config (& config );
762
764
763
765
return 0 ;
0 commit comments