@@ -118,16 +118,16 @@ struct file {
118
118
119
119
/**
120
120
* enum log_level - Logging levels
121
- * @JLOG_SUMMARY : Default log level
122
- * @JLOG_INFO : Verbose logging (verbose == 1)
123
- * @JLOG_VERBOSE1 : Verbosity 2
124
- * @JLOG_VERBOSE2 : Verbosity 3
121
+ * @HDL_LOG_SUMMARY : Default log level
122
+ * @HDL_LOG_INFO : Verbose logging (verbose == 1)
123
+ * @HDL_LOG_VERBOSE1 : Verbosity 2
124
+ * @HDL_LOG_VERBOSE2 : Verbosity 3
125
125
*/
126
- enum log_level {
127
- JLOG_SUMMARY ,
128
- JLOG_INFO ,
129
- JLOG_VERBOSE1 ,
130
- JLOG_VERBOSE2
126
+ enum hdl_log_level {
127
+ HDL_LOG_SUMMARY ,
128
+ HDL_LOG_INFO ,
129
+ HDL_LOG_VERBOSE1 ,
130
+ HDL_LOG_VERBOSE2
131
131
};
132
132
133
133
/**
@@ -183,7 +183,8 @@ static struct options {
183
183
struct hdl_regex * exclude_subtree ;
184
184
185
185
const char * method ;
186
- signed int verbosity ;
186
+ short int verbosity ;
187
+
187
188
bool respect_mode ;
188
189
bool respect_owner ;
189
190
bool respect_name ;
@@ -238,26 +239,20 @@ static void *files_by_ino;
238
239
static volatile sig_atomic_t last_signal ;
239
240
240
241
241
- #define is_log_enabled (_level ) (quiet == 0 && (_level) <= (unsigned int)opts.verbosity )
242
+ #define is_log_enabled ( l ) (quiet == 0 && opts.verbosity >= HDL_LOG_ ## l )
242
243
243
244
/**
244
- * jlog - Logging for hardlink
245
- * @level : The log level
246
- * @format: A format string for printf()
245
+ * hdl_log - Logging for hardlink
246
+ * @l : The log level (without HDL_LOG_ prefix)
247
+ * @x: function to print output
247
248
*/
248
- __attribute__((format (printf , 2 , 3 )))
249
- static void jlog (enum log_level level , const char * format , ...)
250
- {
251
- va_list args ;
252
-
253
- if (!is_log_enabled (level ))
254
- return ;
255
-
256
- va_start (args , format );
257
- vfprintf (stdout , format , args );
258
- va_end (args );
259
- fputc ('\n' , stdout );
260
- }
249
+ #define jlog (l , x ) \
250
+ do { \
251
+ if (is_log_enabled( l )) { \
252
+ x; \
253
+ fputc('\n', stdout); \
254
+ } \
255
+ } while (0)
261
256
262
257
/**
263
258
* CMP - Compare two numerical values, return 1, 0, or -1
@@ -405,32 +400,34 @@ static void print_stats(void)
405
400
gettime_monotonic (& end );
406
401
timersub (& end , & stats .start_time , & delta );
407
402
408
- jlog (JLOG_SUMMARY , "%-25s %s" , _ ("Mode:" ),
409
- opts .dry_run ? _ ("dry-run" ) : _ ("real" ));
410
- jlog (JLOG_SUMMARY , "%-25s %s" , _ ("Method:" ), opts .method );
411
- jlog (JLOG_SUMMARY , "%-25s %zu" , _ ("Files:" ), stats .files );
412
- jlog (JLOG_SUMMARY , _ ("%-25s %zu files" ), _ ("Linked:" ), stats .linked );
403
+ jlog (SUMMARY , printf ( "%-25s %s" , _ ("Mode:" ),
404
+ opts .dry_run ? _ ("dry-run" ) : _ ("real" ) ));
405
+ jlog (SUMMARY , printf ( "%-25s %s" , _ ("Method:" ), opts .method ) );
406
+ jlog (SUMMARY , printf ( "%-25s %zu" , _ ("Files:" ), stats .files ) );
407
+ jlog (SUMMARY , printf ( _ ("%-25s %zu files" ), _ ("Linked:" ), stats .linked ) );
413
408
414
409
#ifdef USE_XATTR
415
- jlog (JLOG_SUMMARY , _ ("%-25s %zu xattrs" ), _ ("Compared:" ),
416
- stats .xattr_comparisons );
410
+ jlog (SUMMARY , printf ( _ ("%-25s %zu xattrs" ), _ ("Compared:" ),
411
+ stats .xattr_comparisons ) );
417
412
#endif
418
- jlog (JLOG_SUMMARY , _ ("%-25s %zu files" ), _ ("Compared:" ),
419
- stats .comparisons );
413
+ jlog (SUMMARY , printf ( _ ("%-25s %zu files" ), _ ("Compared:" ),
414
+ stats .comparisons ) );
420
415
#ifdef USE_REFLINK
421
416
if (reflinks_skip )
422
- jlog (JLOG_SUMMARY , _ ("%-25s %zu files" ), _ ("Skipped reflinks:" ),
423
- stats .ignored_reflinks );
417
+ jlog (SUMMARY , printf ( _ ("%-25s %zu files" ), _ ("Skipped reflinks:" ),
418
+ stats .ignored_reflinks ) );
424
419
#endif
425
420
ssz = size_to_human_string (SIZE_SUFFIX_3LETTER |
426
421
SIZE_SUFFIX_SPACE |
427
422
SIZE_DECIMAL_2DIGITS , stats .saved );
428
423
429
- jlog (JLOG_SUMMARY , "%-25s %s" , _ ("Saved:" ), ssz );
424
+ jlog (SUMMARY , printf ( "%-25s %s" , _ ("Saved:" ), ssz ) );
430
425
free (ssz );
431
426
432
- jlog (JLOG_SUMMARY , _ ("%-25s %" PRId64 ".%06" PRId64 " seconds" ), _ ("Duration:" ),
433
- (int64_t )delta .tv_sec , (int64_t )delta .tv_usec );
427
+ jlog (SUMMARY , printf (_ ("%-25s %" PRId64 ".%06" PRId64 " seconds" ),
428
+ _ ("Duration:" ),
429
+ (int64_t ) delta .tv_sec ,
430
+ (int64_t ) delta .tv_usec ));
434
431
}
435
432
436
433
/**
@@ -560,8 +557,8 @@ static int file_xattrs_equal(const struct file *a, const struct file *b)
560
557
assert (a -> links != NULL );
561
558
assert (b -> links != NULL );
562
559
563
- jlog (JLOG_VERBOSE1 , _ ("Comparing xattrs of %s to %s" ), a -> links -> path ,
564
- b -> links -> path );
560
+ jlog (VERBOSE1 , printf ( _ ("Comparing xattrs of %s to %s" ),
561
+ a -> links -> path , b -> links -> path ) );
565
562
566
563
stats .xattr_comparisons ++ ;
567
564
@@ -727,7 +724,7 @@ static inline int do_link(struct file *a, struct file *b,
727
724
728
725
if (reflink_mode == REFLINK_ALWAYS )
729
726
return - errno ;
730
- jlog (JLOG_VERBOSE2 , _ ("Reflinking failed, fallback to hardlinking" ));
727
+ jlog (VERBOSE2 , printf ( _ ("Reflinking failed, fallback to hardlinking" ) ));
731
728
}
732
729
733
730
return link (a -> links -> path , new_name );
@@ -758,15 +755,15 @@ static int file_link(struct file *a, struct file *b, int reflink)
758
755
assert (a -> links != NULL );
759
756
assert (b -> links != NULL );
760
757
761
- if (is_log_enabled (JLOG_INFO )) {
758
+ if (is_log_enabled (INFO )) {
762
759
char * ssz = size_to_human_string (SIZE_SUFFIX_3LETTER |
763
760
SIZE_SUFFIX_SPACE |
764
761
SIZE_DECIMAL_2DIGITS , a -> st .st_size );
765
- jlog (JLOG_INFO , _ ("%s%sLinking %s to %s (-%s)" ),
762
+ jlog (INFO , printf ( _ ("%s%sLinking %s to %s (-%s)" ),
766
763
opts .dry_run ? _ ("[DryRun] " ) : "" ,
767
764
reflink ? "Ref" : "" ,
768
765
a -> links -> path , b -> links -> path ,
769
- ssz );
766
+ ssz )) ;
770
767
free (ssz );
771
768
}
772
769
@@ -855,8 +852,8 @@ static int inserter(const char *fpath, const struct stat *sb,
855
852
if (opts .exclude_subtree
856
853
&& typeflag == FTW_D
857
854
&& match_any_regex (opts .exclude_subtree , fpath )) {
858
- jlog (JLOG_VERBOSE1 ,
859
- _ ("Skipped (excluded subtree) %s" ), fpath );
855
+ jlog (VERBOSE1 ,
856
+ printf ( _ ("Skipped (excluded subtree) %s" ), fpath ) );
860
857
return FTW_SKIP_SUBTREE ;
861
858
}
862
859
#endif
@@ -868,26 +865,26 @@ static int inserter(const char *fpath, const struct stat *sb,
868
865
869
866
if ((opts .exclude && excluded && !included ) ||
870
867
(!opts .exclude && opts .include && !included )) {
871
- jlog (JLOG_VERBOSE1 ,
872
- _ ("Skipped (excluded) %s" ), fpath );
868
+ jlog (VERBOSE1 ,
869
+ printf ( _ ("Skipped (excluded) %s" ), fpath ) );
873
870
return 0 ;
874
871
}
875
872
876
873
stats .files ++ ;
877
874
878
875
if ((uintmax_t ) sb -> st_size < opts .min_size ) {
879
- jlog (JLOG_VERBOSE1 ,
880
- _ ("Skipped (smaller than configured size) %s" ), fpath );
876
+ jlog (VERBOSE1 ,
877
+ printf ( _ ("Skipped (smaller than configured size) %s" ), fpath ) );
881
878
return 0 ;
882
879
}
883
880
884
- jlog (JLOG_VERBOSE2 , " %5zu: [%" PRIu64 "/%" PRIu64 "/%zu] %s" ,
881
+ jlog (VERBOSE2 , printf ( " %5zu: [%" PRIu64 "/%" PRIu64 "/%zu] %s" ,
885
882
stats .files , sb -> st_dev , sb -> st_ino ,
886
- (size_t ) sb -> st_nlink , fpath );
883
+ (size_t ) sb -> st_nlink , fpath )) ;
887
884
888
885
if ((opts .max_size > 0 ) && ((uintmax_t ) sb -> st_size > opts .max_size )) {
889
- jlog (JLOG_VERBOSE1 ,
890
- _ ("Skipped (greater than configured size) %s" ), fpath );
886
+ jlog (VERBOSE1 ,
887
+ printf ( _ ("Skipped (greater than configured size) %s" ), fpath ) );
891
888
return 0 ;
892
889
}
893
890
@@ -915,8 +912,8 @@ static int inserter(const char *fpath, const struct stat *sb,
915
912
assert ((* node )-> st .st_ino == sb -> st_ino );
916
913
917
914
if (has_fpath (* node , fpath )) {
918
- jlog (JLOG_VERBOSE1 ,
919
- _ ("Skipped (specified more than once) %s" ), fpath );
915
+ jlog (VERBOSE1 ,
916
+ printf ( _ ("Skipped (specified more than once) %s" ), fpath ) );
920
917
free (fil -> links );
921
918
} else {
922
919
fil -> links -> next = (* node )-> links ;
@@ -1121,14 +1118,14 @@ static void visitor(const void *nodep, const VISIT which, const int depth)
1121
1118
1122
1119
/* check file attributes, etc. */
1123
1120
if (!file_may_link_to (master , other )) {
1124
- jlog (JLOG_VERBOSE2 ,
1125
- _ ("Skipped (attributes mismatch) %s" ), other -> links -> path );
1121
+ jlog (VERBOSE2 ,
1122
+ printf ( _ ("Skipped (attributes mismatch) %s" ), other -> links -> path ) );
1126
1123
continue ;
1127
1124
}
1128
1125
#ifdef USE_REFLINK
1129
1126
if (may_reflink && reflinks_skip && is_reflink (master , other )) {
1130
- jlog (JLOG_VERBOSE2 ,
1131
- _ ("Skipped (already reflink) %s" ), other -> links -> path );
1127
+ jlog (VERBOSE2 ,
1128
+ printf ( _ ("Skipped (already reflink) %s" ), other -> links -> path ) );
1132
1129
stats .ignored_reflinks ++ ;
1133
1130
continue ;
1134
1131
}
@@ -1148,8 +1145,8 @@ static void visitor(const void *nodep, const VISIT which, const int depth)
1148
1145
stats .comparisons ++ ;
1149
1146
1150
1147
if (!eq ) {
1151
- jlog (JLOG_VERBOSE2 ,
1152
- _ ("Skipped (content mismatch) %s" ), other -> links -> path );
1148
+ jlog (VERBOSE2 ,
1149
+ printf ( _ ("Skipped (content mismatch) %s" ), other -> links -> path ) );
1153
1150
continue ;
1154
1151
}
1155
1152
@@ -1479,7 +1476,8 @@ int main(int argc, char *argv[])
1479
1476
1480
1477
rc = ul_fileeq_init (& fileeq , opts .method );
1481
1478
if (rc != 0 && strcmp (opts .method , "memcmp" ) != 0 ) {
1482
- jlog (JLOG_INFO , _ ("cannot initialize %s method, use 'memcmp' fallback" ), opts .method );
1479
+ jlog (INFO , printf (_ ("cannot initialize %s method, use 'memcmp' fallback" ),
1480
+ opts .method ));
1483
1481
opts .method = "memcmp" ;
1484
1482
rc = ul_fileeq_init (& fileeq , opts .method );
1485
1483
}
@@ -1505,7 +1503,7 @@ int main(int argc, char *argv[])
1505
1503
if (opts .exclude_subtree )
1506
1504
ftw_flags |= FTW_ACTIONRETVAL ;
1507
1505
#endif
1508
- jlog (JLOG_VERBOSE2 , _ ("Scanning [device/inode/links]:" ));
1506
+ jlog (VERBOSE2 , printf ( _ ("Scanning [device/inode/links]:" ) ));
1509
1507
for (; optind < argc ; optind ++ ) {
1510
1508
char * path = realpath (argv [optind ], NULL );
1511
1509
0 commit comments