00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 #define _GNU_SOURCE
00290 #include <stdio.h>
00291 #include <stdlib.h>
00292 #include <stdarg.h>
00293 #include <stdint.h>
00294 #include <string.h>
00295 #include <errno.h>
00296 #include <getopt.h>
00297
00298 #include <sys/types.h>
00299 #include <sys/stat.h>
00300 #include <sys/param.h>
00301 #include <sys/stat.h>
00302 #include <sys/inotify.h>
00303 #include <sys/select.h>
00304 #include <signal.h>
00305
00306 #include "config.h"
00307 #include "dhash.h"
00308 #include "path_utils.h"
00309 #include "logging.h"
00310 #include "regexp.h"
00311 #include "inotify_watch.h"
00312 #include "util.h"
00313 #include "lwatch.h"
00314
00315
00316
00317
00318
00319 #define LOG_LEVEL_ARG 256
00320 #define LOG_TO_CONSOLE_ARG 257
00321 #define LOGFILE_PATH_ARG 258
00322 #define NO_LOGGING_TO_FILE_ARG 259
00323
00324 #define LOG_SHOW_LEVEL_ARG 260
00325 #define LOG_NO_SHOW_LEVEL_ARG 261
00326 #define LOG_SHOW_FILE_ARG 262
00327 #define LOG_NO_SHOW_FILE_ARG 263
00328 #define LOG_SHOW_LINE_ARG 264
00329 #define LOG_NO_SHOW_LINE_ARG 265
00330 #define LOG_SHOW_FUNCTION_ARG 266
00331 #define LOG_NO_SHOW_FUNCTION_ARG 267
00332 #define LOG_SHOW_TIME_ARG 268
00333 #define LOG_NO_SHOW_TIME_ARG 269
00334
00335
00336
00337
00338
00339
00340
00341
00342 typedef enum {
00343 PROG_ACTION_MONITOR,
00344 PROG_ACTION_LIST,
00345 PROG_ACTION_FIND,
00346 } prog_action_t;
00347
00348
00349
00350
00351 typedef enum {
00352 FILE_NO_CHANGE,
00353 FILE_APPENDED,
00354 FILE_REPLACED,
00355 } file_event_t;
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 static const char *file_event_string(file_event_t event_type);
00366 static int reap_file_data(struct lwatch_path_info_t *path_info);
00367 static int get_create_path_info(const char *path, struct lwatch_path_info_t *path_info);
00368 static int process_file_modification(const char *path);
00369 static int process_file_close(const char *path);
00370 static int process_file_create(const char *path);
00371 static int process_file_delete(const char *path);
00372 static int process_file_rename(const char *prev_path, const char *new_path);
00373 static int regexp_init(void);
00374 static int regexp_fini(void);
00375 static int lwatch_init(void);
00376 static int lwatch_fini(void);
00377 static void signal_handler (int signum);
00378 static const char *lwatch_event_type_string(lwatch_event_type event_type);
00379 static const char *lwatch_event_string(struct lwatch_event_t *event);
00380 static int lwatch_event_callback(struct lwatch_event_t *event);
00381 static int start_monitoring(const char *path_arg);
00382 static int compare_stat_info(struct stat *stat_info, struct lwatch_path_info_t *path_info, file_event_t *result_arg);
00383 static int get_path_info_reap_candidacy(struct lwatch_path_info_t *path_info, bool *should_reap);
00384 static int set_path_info_reap_candidacy(struct lwatch_path_info_t *path_info);
00385 static int update_stat_info_and_write(struct stat *cur_stat_info, struct lwatch_path_info_t *path_info);
00386 static int dump_database(void);
00387 static int validate_backups_in_database(void);
00388 static int process_pending_reaps(void);
00389 static int main_loop(void);
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 struct regexp_t logrotate_numbered_backup_regexp = {"(.*/)?([^/]+)\\.(\\d+)(\\.gz|.\\bz2)?$"};
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 struct regexp_t logrotate_date_backup_regexp = {"(.*/)?([^/]+)-((\\d{4})(\\d{2})(\\d{2}))(\\.gz|.\\bz2)?$"};
00421
00422
00423
00424
00425 static int reap_interval = 15;
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 static const char *file_event_string(file_event_t event_type)
00442 {
00443 static __thread char buf[80];
00444
00445 switch(event_type) {
00446 case FILE_NO_CHANGE: return _("No change");
00447 case FILE_APPENDED: return _("Appended");
00448 case FILE_REPLACED: return _("Replaced");
00449 default:
00450 snprintf(buf, sizeof(buf), "unknown(%d)", event_type);
00451 return buf;
00452 }
00453
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463 static int get_create_path_info(const char *path, struct lwatch_path_info_t *path_info)
00464 {
00465 int error;
00466
00467 error = database_lookup_path_info(path, path_info);
00468 if ((error != SUCCESS) && (error != WATCH_DATABASE_ERROR_NOT_FOUND)) {
00469 log_msg(LOG_ERROR, _("database_lookup_path_info failed \"%s\" (%s)\n"),
00470 path, error_string(error));
00471 return error;
00472 }
00473
00474
00475 if (error == WATCH_DATABASE_ERROR_NOT_FOUND) {
00476 if ((error = init_path_info(path_info, path)) != SUCCESS) {
00477 log_msg(LOG_ERROR, _("could not initialize path_info for path \"%s\" (%s)\n"),
00478 path, error_string(error));
00479 return error;
00480 }
00481
00482 if ((error = database_write_path_info(path_info)) != SUCCESS) {
00483 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00484 path_info->path, error_string(error));
00485 return error;
00486 }
00487 }
00488
00489 return SUCCESS;
00490 }
00491
00492
00493
00494
00495
00496
00497
00498 static int process_file_modification(const char *path)
00499 {
00500 int error;
00501 struct lwatch_path_info_t path_info;
00502
00503 if ((error = database_lookup_path_info(path, &path_info)) != SUCCESS) {
00504 log_msg(LOG_ERROR, _("database_lookup_path_info failed \"%s\" (%s)\n"),
00505 path, error_string(error));
00506 return LWATCH_ERROR_CANNOT_FIND_PATH_INFO;
00507 }
00508
00509 path_info.flags |= NEEDS_REAPING_FLAG;
00510
00511 if ((error = database_write_path_info(&path_info)) != SUCCESS) {
00512 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00513 path_info.path, error_string(error));
00514 return error;
00515 }
00516
00517 return SUCCESS;
00518 }
00519
00520
00521
00522
00523
00524
00525
00526 static int process_file_close(const char *path)
00527 {
00528 int error;
00529 struct lwatch_path_info_t path_info;
00530
00531 if ((error = database_lookup_path_info(path, &path_info)) != SUCCESS) {
00532 log_msg(LOG_ERROR, _("database_lookup_path_info failed \"%s\" (%s)\n"),
00533 path, error_string(error));
00534 return LWATCH_ERROR_CANNOT_FIND_PATH_INFO;
00535 }
00536
00537 if ((error = set_path_info_reap_candidacy(&path_info)) != SUCCESS) {
00538 log_msg(LOG_ERROR, _("get_path_info_reap_candidacy failed \"%s\" (%s)\n"),
00539 path, error_string(error));
00540 return error;
00541 }
00542
00543 if ((error = database_write_path_info(&path_info)) != SUCCESS) {
00544 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00545 path_info.path, error_string(error));
00546 return error;
00547 }
00548
00549 return SUCCESS;
00550 }
00551
00552
00553
00554
00555
00556
00557
00558 static int process_file_create(const char *path)
00559 {
00560 int error;
00561 struct lwatch_path_info_t path_info;
00562
00563 if ((error = database_lookup_path_info(path, &path_info)) != SUCCESS) {
00564 log_msg(LOG_ERROR, _("database_lookup_path_info failed \"%s\" (%s)\n"),
00565 path, error_string(error));
00566 return LWATCH_ERROR_CANNOT_FIND_PATH_INFO;
00567 }
00568
00569 return SUCCESS;
00570 }
00571
00572
00573
00574
00575
00576
00577
00578 static int process_file_delete(const char *path)
00579 {
00580 int error;
00581 struct lwatch_path_info_t path_info;
00582
00583 if ((error = database_lookup_path_info(path, &path_info)) != SUCCESS) {
00584 log_msg(LOG_ERROR, _("database_lookup_path_info failed \"%s\" (%s)\n"),
00585 path, error_string(error));
00586 return LWATCH_ERROR_CANNOT_FIND_PATH_INFO;
00587 }
00588
00589 PATH_INFO_FLAG_SET_NEW_FILE(&path_info);
00590
00591 if ((error = database_write_path_info(&path_info)) != SUCCESS) {
00592 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00593 path_info.path, error_string(error));
00594 return error;
00595 }
00596
00597
00598 return SUCCESS;
00599 }
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 static int process_file_rename(const char *prev_path, const char *new_path)
00632 {
00633 int error;
00634 struct lwatch_path_info_t prev_pathinfo, new_pathinfo;
00635
00636 log_msg(LOG_DEBUG, _("\"%s\" --> \"%s\"\n"), prev_path, new_path);
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 if (!prev_path[0]) {
00651 log_msg(LOG_ERROR, _("%s: previous path is empty, should have been a file in the set of watched files\n"));
00652 return LWATCH_ERROR_LOST_RENAME;
00653 }
00654
00655 if ((error = database_lookup_path_info(prev_path, &prev_pathinfo)) != SUCCESS) {
00656 log_msg(LOG_ERROR, _("database_lookup_path_info failed \"%s\" (%s)\n"),
00657 prev_path, error_string(error));
00658 return LWATCH_ERROR_CANNOT_FIND_PATH_INFO;
00659 }
00660
00661 if (new_path[0]) {
00662
00663
00664 new_pathinfo = prev_pathinfo;
00665 if ((error = copy_path(new_pathinfo.path, new_path, sizeof(new_pathinfo.path))) != SUCCESS) {
00666 log_msg(LOG_ERROR, _("failed to copy path \"%s\" (%s)\n"), new_path, error_string(error));
00667 return error;
00668 }
00669 if ((error = copy_path(new_pathinfo.original_path, prev_path, sizeof(new_pathinfo.original_path))) != SUCCESS) {
00670 log_msg(LOG_ERROR, _("failed to copy path \"%s\" (%s)\n"), prev_path, error_string(error));
00671 return error;
00672 }
00673 PATH_INFO_FLAG_SET_BACKUP(&new_pathinfo);
00674
00675 if ((error = database_write_path_info(&new_pathinfo)) != SUCCESS) {
00676 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00677 new_pathinfo.path, error_string(error));
00678 }
00679
00680 if ((error = inotify_start_monitoring(new_path)) != SUCCESS) {
00681 log_msg(LOG_ERROR, _("could not inotify_start_monitoring for \"%s\" (%s)\n"),
00682 new_path, error_string(error));
00683 }
00684 }
00685
00686
00687 prev_pathinfo.original_path[0] = 0;
00688 PATH_INFO_FLAG_SET_NEW_FILE(&prev_pathinfo);
00689 prev_pathinfo.reap_time = 0;
00690 prev_pathinfo.reap_position = 0;
00691
00692 if ((error = database_write_path_info(&prev_pathinfo)) != SUCCESS) {
00693 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00694 prev_pathinfo.path, error_string(error));
00695 return error;
00696 }
00697
00698 return SUCCESS;
00699 }
00700
00701
00702
00703
00704
00705
00706 static int regexp_init(void)
00707 {
00708 int error;
00709
00710 if ((error = regexp_compile(&logrotate_numbered_backup_regexp)) != SUCCESS) return error;
00711 if ((error = regexp_compile(&logrotate_date_backup_regexp)) != SUCCESS) return error;
00712 return SUCCESS;
00713 }
00714
00715
00716
00717
00718
00719
00720 static int regexp_fini(void)
00721 {
00722 regexp_free(&logrotate_numbered_backup_regexp);
00723 regexp_free(&logrotate_date_backup_regexp);
00724 return SUCCESS;
00725 }
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735 static int lwatch_init(void)
00736 {
00737 int error;
00738
00739 signal(SIGHUP, signal_handler);
00740 signal(SIGINT, signal_handler);
00741 signal(SIGQUIT, signal_handler);
00742
00743 keep_watching = true;
00744
00745
00746 if ((error = inotify_watch_init()) != SUCCESS) {
00747 log_msg(LOG_ERROR, _("inotify_watch_init() failed (%s)\n"), error_string(error));
00748 return error;
00749 }
00750
00751 register_lwatch_event_callback(lwatch_event_callback);
00752
00753
00754 if ((error = validate_backups_in_database()) != SUCCESS) {
00755 log_msg(LOG_ERROR, _("validate_backups_in_database() failed (%s)\n"), error_string(error));
00756 return error;
00757 }
00758
00759 return SUCCESS;
00760 }
00761
00762
00763
00764
00765
00766
00767 static int lwatch_fini()
00768 {
00769 int error;
00770
00771 if ((error = inotify_watch_fini()) != SUCCESS) {
00772 log_msg(LOG_ERROR, _("inotify_watch_fini() failed (%s)\n"), error_string(error));
00773 }
00774
00775 return SUCCESS;
00776 }
00777
00778
00779
00780
00781
00782
00783
00784 static void signal_handler (int signum)
00785 {
00786 log_msg(LOG_INFO, _("received signal %s(%d)\n"), strsignal(signum), signum);
00787
00788 switch(signum) {
00789 case SIGHUP:
00790 break;
00791 case SIGINT:
00792 keep_watching = false;
00793 break;
00794 case SIGQUIT:
00795 keep_watching = false;
00796 break;
00797 }
00798 }
00799
00800
00801
00802
00803
00804
00805
00806 static const char *lwatch_event_type_string(lwatch_event_type event_type)
00807 {
00808 static __thread char buf[80];
00809
00810 switch(event_type) {
00811 case LWATCH_EVENT_CREATE: return "Created";
00812 case LWATCH_EVENT_DELETE: return "Deleted";
00813 case LWATCH_EVENT_RENAME: return "Renamed";
00814 case LWATCH_EVENT_MODIFY: return "Modified";
00815 case LWATCH_EVENT_OPEN: return "Opened";
00816 case LWATCH_EVENT_CLOSE: return "Closed";
00817 default:
00818 snprintf(buf, sizeof(buf), "unknown(%d)", event_type);
00819 return buf;
00820 }
00821 }
00822
00823
00824
00825
00826
00827
00828
00829 static const char *lwatch_event_string(struct lwatch_event_t *event)
00830 {
00831 static __thread char buf[512 + PATH_MAX * 2];
00832 char *p, *buf_end;
00833
00834 p = buf;
00835 buf_end = &buf[sizeof(buf)];
00836 *p = 0;
00837
00838 p += snprintf(p, buf_end - p, "[%s] ", lwatch_event_type_string(event->event_type));
00839 if (p >= buf_end) goto fail;
00840 if (event->event_type == LWATCH_EVENT_RENAME) {
00841 p += snprintf(p, buf_end - p, "prev_path=\"%s\" ", event->rename.prev_path);
00842 if (p >= buf_end) goto fail;
00843 p += snprintf(p, buf_end - p, "new_path=\"%s\"", event->rename.new_path);
00844 if (p >= buf_end) goto fail;
00845 } else {
00846 p += snprintf(p, buf_end - p, "path=\"%s\"", event->path);
00847 if (p >= buf_end) goto fail;
00848 }
00849
00850 return buf;
00851
00852 fail:
00853
00854 buf_end[-1] = 0;
00855 return buf;
00856 }
00857
00858
00859
00860
00861
00862
00863
00864 static int lwatch_event_callback(struct lwatch_event_t *event)
00865 {
00866 int error;
00867
00868 log_msg(LOG_DEBUG, _("event: %s\n"), lwatch_event_string(event));
00869
00870 switch(event->event_type) {
00871 case LWATCH_EVENT_CREATE:
00872 if ((error = process_file_create(event->path)) != SUCCESS) {
00873 log_msg(LOG_ERROR, _("process_file_create failed for \"%s\" (%s)\n"),
00874 event->path, error_string(error));
00875 }
00876 break;
00877 case LWATCH_EVENT_OPEN:
00878 break;
00879 case LWATCH_EVENT_DELETE:
00880 if ((error = process_file_delete(event->path)) != SUCCESS) {
00881 log_msg(LOG_ERROR, _("process_file_delete failed for \"%s\" (%s)\n"),
00882 event->path, error_string(error));
00883 }
00884 break;
00885 case LWATCH_EVENT_RENAME:
00886 if ((error = process_file_rename(event->rename.prev_path, event->rename.new_path)) != SUCCESS) {
00887 log_msg(LOG_ERROR, _("process_file_rename failed for \"%s\" --> \"%s\" (%s)\n"),
00888 event->rename.prev_path, event->rename.new_path, error_string(error));
00889 }
00890 break;
00891 case LWATCH_EVENT_MODIFY:
00892 if ((error = process_file_modification(event->path)) != SUCCESS) {
00893 log_msg(LOG_ERROR, _("process_file_modification failed for \"%s\" (%s)\n"),
00894 event->path, error_string(error));
00895 }
00896 break;
00897 case LWATCH_EVENT_CLOSE:
00898 if ((error = process_file_close(event->path)) != SUCCESS) {
00899 log_msg(LOG_ERROR, _("process_file_close failed for \"%s\" (%s)\n"),
00900 event->path, error_string(error));
00901 }
00902 break;
00903 default:
00904 log_msg(LOG_ERROR, _("unknown watch event type \"%s\"\n"), lwatch_event_string(event));
00905 return EINVAL;
00906 }
00907
00908 return SUCCESS;
00909 }
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923 static int start_monitoring(const char *path_arg)
00924 {
00925 int error;
00926 struct lwatch_path_info_t path_info;
00927 char path[PATH_MAX];
00928
00929 if ((error = make_normalized_absolute_path(path, sizeof(path), path_arg)) != SUCCESS) {
00930 log_msg(LOG_ERROR, _("failed make_normalized_absolute_path from \"%s\" (%s)\n"),
00931 path_arg, error_string(error));
00932 return error;
00933 }
00934
00935 log_msg(LOG_INFO, _("monitoring \"%s\"\n"), path);
00936
00937 if (is_log_backup(path)) {
00938 log_msg(LOG_WARN, _("file \"%s\" appears to be a log backup, only original log files should be monitored\n"),
00939 path);
00940 }
00941
00942 if ((error = get_create_path_info(path, &path_info)) != SUCCESS) {
00943 log_msg(LOG_ERROR, _("get_create_path_info failed \"%s\" (%s)\n"),
00944 path, error_string(error));
00945 return LWATCH_ERROR_CANNOT_MONITOR;
00946 }
00947
00948 PATH_INFO_FLAG_SET_TARGET(&path_info);
00949
00950 if ((error = set_path_info_reap_candidacy(&path_info)) != SUCCESS) {
00951 log_msg(LOG_ERROR, _("set_path_info_reap_candidacy failed \"%s\" (%s)\n"),
00952 path, error_string(error));
00953 return LWATCH_ERROR_CANNOT_MONITOR;
00954 }
00955
00956 if ((error = database_write_path_info(&path_info)) != SUCCESS) {
00957 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
00958 path_info.path, error_string(error));
00959 return error;
00960 }
00961
00962 if (!is_watch_target(path)) {
00963 if ((error = inotify_start_monitoring(path)) != SUCCESS) {
00964 log_msg(LOG_ERROR, _("could not inotify_start_monitoring for \"%s\" (%s)\n"),
00965 path, error_string(error));
00966 return LWATCH_ERROR_CANNOT_MONITOR;
00967 }
00968 }
00969
00970 return SUCCESS;
00971 }
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988 static int compare_stat_info(struct stat *stat_info, struct lwatch_path_info_t *path_info, file_event_t *result_arg)
00989 {
00990 int error;
00991 file_event_t result;
00992
00993 error = SUCCESS;
00994 result = FILE_NO_CHANGE;
00995
00996 if (!(path_info->flags & STAT_DATA_VALID_FLAG)) {
00997 result = FILE_REPLACED;
00998 goto exit;
00999 }
01000
01001 log_msg(LOG_DEBUG, _("st_size=%lu(%lu), st_dev=%llu(%llu) st_ino=%lu(%lu) st_mtime=%ld(%ld) \"%s\"\n"),
01002
01003 stat_info->st_size, path_info->size,
01004 stat_info->st_dev, path_info->dev,
01005 stat_info->st_ino, path_info->inode,
01006 stat_info->st_mtime, path_info->modification_time,
01007 path_info->path);
01008
01009
01010
01011
01012
01013
01014 if ((stat_info->st_dev != path_info->dev) || (stat_info->st_ino != path_info->inode)) {
01015 result = FILE_REPLACED;
01016 }
01017
01018
01019 if (stat_info->st_size < path_info->size) {
01020 result = FILE_REPLACED;
01021 }
01022
01023
01024 if (stat_info->st_size > path_info->size) {
01025 result = FILE_APPENDED;
01026 }
01027
01028 exit:
01029 *result_arg = result;
01030 return error;
01031 }
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 static int get_path_info_reap_candidacy(struct lwatch_path_info_t *path_info, bool *should_reap)
01046 {
01047 int error;
01048 struct stat cur_stat_info;
01049 file_event_t event_type;
01050
01051 *should_reap = false;
01052
01053 if (stat(path_info->path, &cur_stat_info) < 0) {
01054 error = errno;
01055 if (error == ENOENT) {
01056 return SUCCESS;
01057 }
01058 log_msg(LOG_ERROR, _("cannot perform stat on \"%s\" (%s) \n"),
01059 path_info->path, error_string(error));
01060 return error;
01061 }
01062
01063 if ((error = compare_stat_info(&cur_stat_info, path_info, &event_type)) != SUCCESS) {
01064 log_msg(LOG_ERROR, _("compare_stat_info failed \"%s\" (%s) \n"),
01065 path_info->path, error_string(error));
01066 return error;
01067 }
01068
01069 log_msg(LOG_DEBUG, _("compare_stat_info(%s) returns %s\n"),
01070 path_info->path, file_event_string(event_type));
01071
01072
01073 switch(event_type) {
01074 case FILE_NO_CHANGE:
01075 break;
01076 case FILE_APPENDED:
01077 case FILE_REPLACED:
01078 *should_reap = true;
01079 break;
01080 default:
01081 log_msg(LOG_ERROR, _("unknown event type = %d\n"), event_type);
01082 return EINVAL;
01083 }
01084
01085 return SUCCESS;
01086 }
01087
01088
01089
01090
01091
01092
01093
01094 static int set_path_info_reap_candidacy(struct lwatch_path_info_t *path_info)
01095 {
01096 int error;
01097 bool should_reap;
01098
01099 if ((error = get_path_info_reap_candidacy(path_info, &should_reap)) != SUCCESS) {
01100 if (error == ENOENT) {
01101 path_info->flags &= ~NEEDS_REAPING_FLAG;
01102 return SUCCESS;
01103 }
01104 }
01105
01106 if (should_reap) {
01107 path_info->flags |= NEEDS_REAPING_FLAG;
01108 } else {
01109 path_info->flags &= ~NEEDS_REAPING_FLAG;
01110 }
01111 return SUCCESS;
01112 }
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 static int update_stat_info_and_write(struct stat *cur_stat_info, struct lwatch_path_info_t *path_info)
01124 {
01125 int error;
01126
01127 if ((error = update_stat_info(cur_stat_info, path_info)) != SUCCESS) {
01128 log_msg(LOG_ERROR, _("could not update_stat_info for \"%s\" (%s) \n"),
01129 path_info->path, error_string(error));
01130 }
01131
01132 if ((error = database_write_path_info(path_info)) != SUCCESS) {
01133 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
01134 path_info->path, error_string(error));
01135 return error;
01136 }
01137 return SUCCESS;
01138 }
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151 int destroy_path_info(struct lwatch_path_info_t **ppath_info)
01152 {
01153 struct lwatch_path_info_t *path_info;
01154
01155 if (!ppath_info) return EINVAL;
01156 path_info = *ppath_info;
01157 if (!path_info) return EINVAL;
01158
01159 free(path_info);
01160 *ppath_info = NULL;
01161
01162 return SUCCESS;
01163 }
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173 int update_stat_info(struct stat *cur_stat_info, struct lwatch_path_info_t *path_info)
01174 {
01175 int error;
01176 struct stat stat_info;
01177
01178 if (cur_stat_info == NULL) {
01179 if (stat(path_info->path, &stat_info) < 0) {
01180 error = errno;
01181 log_msg(LOG_ERROR, _("cannot perform stat on \"%s\" (%s) \n"),
01182 path_info->path, error_string(error));
01183 return error;
01184 }
01185 cur_stat_info = &stat_info;
01186 }
01187
01188 path_info->dev = cur_stat_info->st_dev;
01189 path_info->inode = cur_stat_info->st_ino;
01190 path_info->mode = cur_stat_info->st_mode;
01191 path_info->uid = cur_stat_info->st_uid;
01192 path_info->gid = cur_stat_info->st_gid;
01193 path_info->size = cur_stat_info->st_size;
01194 path_info->access_time = cur_stat_info->st_atime;
01195 path_info->modification_time = cur_stat_info->st_mtime;
01196 path_info->change_time = cur_stat_info->st_ctime;
01197
01198 path_info->flags |= STAT_DATA_VALID_FLAG;
01199
01200 return SUCCESS;
01201 }
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229 bool is_log_backup(const char *path)
01230 {
01231 int num_matches;
01232
01233 if ((num_matches = regexp_search(&logrotate_numbered_backup_regexp, path)) > 0) {
01234 # if 0
01235
01236
01237
01238 char directory[PATH_MAX];
01239 char filename[PATH_MAX];
01240 char number[9];
01241 char extension[PATH_MAX];
01242
01243 regexp_substring(&logrotate_numbered_backup_regexp, 1, directory, sizeof(directory));
01244 regexp_substring(&logrotate_numbered_backup_regexp, 2, filename, sizeof(filename));
01245 regexp_substring(&logrotate_numbered_backup_regexp, 3, number, sizeof(number));
01246 regexp_substring(&logrotate_numbered_backup_regexp, 4, extension, sizeof(extension));
01247
01248 if (0) printf(" num_matches=%d directory=\"%s\" filename=\"%s\" number=\"%s\" extension=\"%s\" ",
01249 num_matches, directory, filename, number, extension);
01250 #endif
01251 return true;
01252 }
01253 if ((num_matches = regexp_search(&logrotate_date_backup_regexp, path)) > 0) {
01254 # if 0
01255
01256
01257
01258 char directory[PATH_MAX];
01259 char filename[PATH_MAX];
01260 char date[9];
01261 char year[5];
01262 char month[3];
01263 char day[3];
01264 char extension[PATH_MAX];
01265
01266 regexp_substring(&logrotate_date_backup_regexp, 1, directory, sizeof(directory));
01267 regexp_substring(&logrotate_date_backup_regexp, 2, filename, sizeof(filename));
01268 regexp_substring(&logrotate_date_backup_regexp, 3, date, sizeof(date));
01269 regexp_substring(&logrotate_date_backup_regexp, 4, year, sizeof(year));
01270 regexp_substring(&logrotate_date_backup_regexp, 5, month, sizeof(month));
01271 regexp_substring(&logrotate_date_backup_regexp, 6, day, sizeof(day));
01272 regexp_substring(&logrotate_date_backup_regexp, 7, extension, sizeof(extension));
01273
01274 if (0) printf(" num_matches=%d directory=\"%s\" filename=\"%s\" date=\"%s\" year=\"%s\" month=\"%s\" day=\"%s\" extension=\"%s\" ",
01275 num_matches, directory, filename, date, year, month, day, extension);
01276 #endif
01277 return true;
01278 }
01279 return false;
01280 }
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292 static int dump_database()
01293 {
01294 int error;
01295 struct database_iter_context_t *path_iter, *backup_iter;
01296 struct lwatch_path_info_t *path_info, *backup_path_info;
01297
01298 if ((error = database_query_all_paths_iter(&path_iter, NULL)) != SUCCESS) {
01299 log_msg(LOG_ERROR, _("database_query_all_iter failed (%s)\n"), error_string(error));
01300 }
01301
01302 while ((path_info = path_iter->next(path_iter))) {
01303 if (path_info->flags & BACKUP_FLAG)
01304 continue;
01305
01306 printf("%s\n", path_info_string(path_info, ""));
01307
01308 if ((error = database_query_backups_of_target_iter(&backup_iter, path_info->path)) != SUCCESS) {
01309 log_msg(LOG_ERROR, _("database_query_backups_of_target_iter failed (%s)\n"), error_string(error));
01310 }
01311
01312 while ((backup_path_info = backup_iter->next(backup_iter))) {
01313 printf("%s\n", path_info_string(backup_path_info, " "));
01314 }
01315 free(backup_iter);
01316 }
01317 free(path_iter);
01318
01319 return SUCCESS;
01320 }
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354 static int validate_backups_in_database()
01355 {
01356 int error;
01357 struct database_iter_context_t *path_iter;
01358 struct lwatch_path_info_t *path_info;
01359
01360 struct lwatch_path_info_t *path_info_updates;
01361 int i, alloc_increment, alloc_count, update_count;
01362
01363 alloc_increment = 8;
01364 alloc_count = 0;
01365 update_count = 0;
01366 path_info_updates = NULL;
01367
01368 if ((error = database_query_backups_iter(&path_iter)) != SUCCESS) {
01369 log_msg(LOG_ERROR, _("database_query_backups_iter failed (%s)\n"), error_string(error));
01370 }
01371
01372 while ((path_info = path_iter->next(path_iter))) {
01373 if (!(path_info->flags & NEEDS_REAPING_FLAG)) {
01374 if ((error = set_path_info_reap_candidacy(path_info)) != SUCCESS) {
01375 log_msg(LOG_ERROR, _("set_path_info_reap_candidacy failed \"%s\" (%s)\n"),
01376 path_info->path, error_string(error));
01377 }
01378 if (path_info->flags & NEEDS_REAPING_FLAG) {
01379 if (update_count == alloc_count) {
01380 alloc_count += alloc_increment;
01381 if ((path_info_updates = realloc(path_info_updates, alloc_count * sizeof(struct lwatch_path_info_t))) == NULL) {
01382 error = ENOMEM;
01383 free(path_info_updates);
01384 free(path_iter);
01385 log_msg(LOG_ERROR, _("could not alloc memory for update array (%s)\n"), error_string(error));
01386 return error;
01387 }
01388 }
01389 path_info_updates[update_count++] = *path_info;
01390 }
01391 }
01392
01393 if ((error = inotify_start_monitoring(path_info->path)) != SUCCESS) {
01394 log_msg(LOG_ERROR, _("could not inotify_start_monitoring for \"%s\" (%s)\n"),
01395 path_info->path, error_string(error));
01396 }
01397 }
01398 free(path_iter);
01399
01400
01401 for (i = 0, path_info = path_info_updates; i < update_count; i++, path_info++) {
01402 if ((error = database_write_path_info(path_info)) != SUCCESS) {
01403 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
01404 path_info->path, error_string(error));
01405 }
01406 }
01407
01408 if (path_info_updates) free(path_info_updates);
01409
01410 return SUCCESS;
01411 }
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426 static int process_pending_reaps()
01427 {
01428 int error;
01429 struct database_iter_context_t *iter;
01430 struct lwatch_path_info_t *path_info;
01431
01432 log_msg(LOG_DEBUG, _("process_pending_reaps\n"));
01433
01434 if ((error = database_query_pending_reaps_iter(&iter)) != SUCCESS) {
01435 log_msg(LOG_ERROR, _("database_query_pending_reaps_iter failed (%s)\n"),
01436 error_string(error));
01437 return error;
01438 }
01439
01440 while ((path_info = iter->next(iter))) {
01441 if ((error = reap_file_data(path_info)) != SUCCESS) {
01442 log_msg(LOG_ERROR, _("cannot reap file data for \"%s\" (%s)\n"),
01443 path_info->path, error_string(error));
01444 }
01445 }
01446 free(iter);
01447
01448 return SUCCESS;
01449 }
01450
01451
01452
01453
01454
01455
01456
01457
01458 static int reap_file_data(struct lwatch_path_info_t *path_info)
01459 {
01460 int error;
01461 struct stat stat_info;
01462 const char *path;
01463 size_t length;
01464
01465 path = path_info->path;
01466 if (stat(path, &stat_info) < 0) {
01467 error = errno;
01468 log_msg(LOG_ERROR, _("cannot perform stat on \"%s\" (%s) \n"),
01469 path, error_string(error));
01470
01471 if (error == ENOENT) {
01472 int write_error;
01473
01474 log_msg(LOG_ERROR, _("deleted \"%s\" before being fully collected\n"), path);
01475
01476 path_info->flags &= ~NEEDS_REAPING_FLAG;
01477
01478 if ((write_error = database_write_path_info(path_info)) != SUCCESS) {
01479 log_msg(LOG_ERROR, _("could not insert path_info into database for \"%s\" (%s)\n"),
01480 path_info->path, error_string(write_error));
01481 }
01482 }
01483 return error;
01484 }
01485
01486 if (path_info->flags & INC_VERSION_FLAG) {
01487 path_info->version++;
01488 path_info->flags &= ~INC_VERSION_FLAG;
01489 }
01490
01491 length = stat_info.st_size - path_info->reap_position;
01492
01493 printf("REAP \"%s\" [%lu:%lu]\n", path, path_info->reap_position, path_info->reap_position + length);
01494
01495 path_info->reap_position = path_info->reap_position + length;
01496 path_info->reap_time = time(NULL);
01497 path_info->flags &= ~NEEDS_REAPING_FLAG;
01498 if ((error = update_stat_info_and_write(&stat_info, path_info)) != SUCCESS) {
01499 log_msg(LOG_ERROR, _("could not update_stat_info_and_write for \"%s\" (%s) \n"),
01500 path, error_string(error));
01501 return error;
01502 }
01503
01504 return SUCCESS;
01505 }
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518 static int main_loop()
01519 {
01520 int error;
01521 int result;
01522 fd_set read_fds;
01523 int inotify_fd;
01524 struct timeval timeout;
01525
01526 inotify_fd = get_inotify_fd();
01527
01528 timeout.tv_sec = reap_interval;
01529 timeout.tv_usec = 0;
01530
01531 while (keep_watching) {
01532 FD_ZERO(&read_fds);
01533 FD_SET(inotify_fd, &read_fds);
01534
01535 result = select(inotify_fd + 1, &read_fds, NULL, NULL, &timeout);
01536 if (result == -1) {
01537 error = errno;
01538 if (error != EINTR) {
01539 log_msg(LOG_ERROR, _("select error (%s)\n"),
01540 error_string(error));
01541 }
01542 } else if (result) {
01543 read_events();
01544 } else {
01545
01546 timeout.tv_sec = reap_interval;
01547 timeout.tv_usec = 0;
01548
01549 if ((error = process_pending_reaps()) != SUCCESS) {
01550 log_msg(LOG_ERROR, _("error processing pending reaps (%s)\n"),
01551 error_string(error));
01552 }
01553 }
01554 }
01555
01556 return SUCCESS;
01557 }
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577 static bool find_log_files_callback(const char *directory, const char *filename, const char *path, struct stat *info, void *user_data)
01578 {
01579 int *count = (int *)user_data;
01580
01581 if (!(S_ISREG(info->st_mode) || S_ISLNK(info->st_mode))) return true;
01582
01583 if (is_log_backup(path)) return true;
01584
01585 printf("%s\n", path);
01586 (*count)++;
01587
01588 return true;
01589 }
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605 static int find_log_files(const char *dir_path, int recursive)
01606 {
01607 int error;
01608 char path[PATH_MAX];
01609 int count;
01610
01611 if ((error = make_normalized_absolute_path(path, sizeof(path), dir_path)) != SUCCESS) {
01612 log_msg(LOG_ERROR, _("failed make_normalized_absolute_path from \"%s\" (%s)\n"),
01613 dir_path, error_string(error));
01614 return error;
01615 }
01616
01617 count = 0;
01618 directory_list(path, recursive, find_log_files_callback, &count);
01619
01620 return SUCCESS;
01621 }
01622
01623
01624
01625
01626
01627
01628
01629
01630 static void usage(void)
01631 {
01632 const char *msg = "\
01633 -h --help provide usage information\n\
01634 -f --find dir1 [dir2 ...] find all log files in dir(s)\n\
01635 -r --recursive when combined with --find examine all subdirectories too\n\
01636 -l --list dump the contents of the watch database\n\
01637 -i --interval seconds number of seconds in reap period\n\
01638 --log_level level set logging level, one of:\n\
01639 error, warn, info, debug, verbose_debug\n\
01640 --log_to_console logging messsage appear on stdout\n\
01641 --logfile_path pathname of the log file\n\
01642 --no_logging_to_file disable logging to file\n\
01643 --log_show_level show logging level in log message\n\
01644 --log_no_show_level do not show logging level in log message\n\
01645 --log_show_file show file name in log message\n\
01646 --log_no_show_file do not show file name in log message\n\
01647 --log_show_line show line number in log message\n\
01648 --log_no_show_line do not show line number in log message\n\
01649 --log_show_function show function name in log message\n\
01650 --log_no_show_function do not show function name in log message\n\
01651 --log_show_time show time stamp in log message\n\
01652 --log_no_show_time do not show time stamp in log message\n\
01653 ";
01654 printf(msg);
01655 }
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676 int main(int argc, char **argv)
01677 {
01678 int error;
01679 int i;
01680 prog_action_t prog_action = PROG_ACTION_MONITOR;
01681 bool recursive = false;
01682 int log_level = LOG_WARN;
01683 char *logfile_path = NULL;
01684
01685 log_set_show_level(true);
01686 log_set_show_file(false);
01687 log_set_show_line(false);
01688 log_set_show_function(true);
01689 log_set_show_time(false);
01690
01691
01692 while (1) {
01693 int arg;
01694 int option_index = 0;
01695 static struct option long_options[] = {
01696 {"help", 0, 0, 'h'},
01697 {"find", 0, 0, 'f'},
01698 {"recursive", 0, 0, 'r'},
01699 {"list", 0, 0, 'l'},
01700 {"interval", 1, 0, 'i'},
01701 {"log_level", 1, 0, LOG_LEVEL_ARG},
01702 {"log_to_console", 0, 0, LOG_TO_CONSOLE_ARG},
01703 {"logfile_path", 0, 0, LOGFILE_PATH_ARG},
01704 {"no_logging_to_file", 0, 0, NO_LOGGING_TO_FILE_ARG},
01705 {"log_show_level", 0, 0, LOG_SHOW_LEVEL_ARG},
01706 {"log_no_show_level", 0, 0, LOG_NO_SHOW_LEVEL_ARG},
01707 {"log_show_file", 0, 0, LOG_SHOW_FILE_ARG},
01708 {"log_no_show_file", 0, 0, LOG_NO_SHOW_FILE_ARG},
01709 {"log_show_line", 0, 0, LOG_SHOW_LINE_ARG},
01710 {"log_no_show_line", 0, 0, LOG_NO_SHOW_LINE_ARG},
01711 {"log_show_function", 0, 0, LOG_SHOW_FUNCTION_ARG},
01712 {"log_no_show_function", 0, 0, LOG_NO_SHOW_FUNCTION_ARG},
01713 {"log_show_time", 0, 0, LOG_SHOW_TIME_ARG},
01714 {"log_no_show_time", 0, 0, LOG_NO_SHOW_TIME_ARG},
01715 {0, 0, 0, 0}
01716 };
01717
01718 arg = getopt_long(argc, argv, "hfrli:",
01719 long_options, &option_index);
01720 if (arg == -1) break;
01721
01722 switch (arg) {
01723 case 'h':
01724 usage();
01725 exit(0);
01726 break;
01727 case 'f':
01728 prog_action = PROG_ACTION_FIND;
01729 break;
01730 case 'r':
01731 recursive = true;
01732 break;
01733 case 'l':
01734 prog_action = PROG_ACTION_LIST;
01735 break;
01736 case 'i':
01737 reap_interval = atoi(optarg);
01738 break;
01739 case LOG_LEVEL_ARG:
01740 if (log_level_from_string(optarg, &log_level) != SUCCESS) {
01741 fprintf(stderr, _("unknown log level: %s\n"), optarg);
01742 }
01743 break;
01744 case LOG_TO_CONSOLE_ARG:
01745 log_to_console(true);
01746 break;
01747 case LOGFILE_PATH_ARG:
01748 logfile_path = optarg;
01749 break;
01750 case NO_LOGGING_TO_FILE_ARG:
01751 log_to_file(false);
01752 break;
01753
01754 case LOG_SHOW_LEVEL_ARG:
01755 log_set_show_level(true);
01756 break;
01757 case LOG_NO_SHOW_LEVEL_ARG:
01758 log_set_show_level(false);
01759 break;
01760 case LOG_SHOW_FILE_ARG:
01761 log_set_show_file(true);
01762 break;
01763 case LOG_NO_SHOW_FILE_ARG:
01764 log_set_show_file(false);
01765 break;
01766 case LOG_SHOW_LINE_ARG:
01767 log_set_show_line(true);
01768 break;
01769 case LOG_NO_SHOW_LINE_ARG:
01770 log_set_show_line(false);
01771 break;
01772 case LOG_SHOW_FUNCTION_ARG:
01773 log_set_show_function(true);
01774 break;
01775 case LOG_NO_SHOW_FUNCTION_ARG:
01776 log_set_show_function(false);
01777 break;
01778 case LOG_SHOW_TIME_ARG:
01779 log_set_show_time(true);
01780 break;
01781 case LOG_NO_SHOW_TIME_ARG:
01782 log_set_show_time(false);
01783 break;
01784
01785 default:
01786 usage();
01787 exit(1);
01788 break;
01789 }
01790 }
01791
01792 log_set_filepath(logfile_path);
01793 log_set_level(log_level);
01794 if ((error = log_init()) != SUCCESS) {
01795 fprintf(stderr, _("log initialization failed (%s)\n"), error_string(error));
01796 return 1;
01797 }
01798
01799 if ((error = regexp_init()) != SUCCESS) {
01800 log_msg(LOG_ERROR, _("regexp initialization failed (%s)\n"), error_string(error));
01801 return 1;
01802 }
01803
01804 if ((error = watch_database_init()) != SUCCESS) {
01805 log_msg(LOG_ERROR, _("watch_database initialization failed (%s)\n"), error_string(error));
01806 return 1;
01807 }
01808
01809 if ((error = lwatch_init()) != SUCCESS) {
01810 log_msg(LOG_ERROR, _("lwatch initialization failed (%s)\n"), error_string(error));
01811 return 1;
01812 }
01813
01814 switch (prog_action) {
01815 case PROG_ACTION_MONITOR:
01816 for (i = optind; i < argc; i++) {
01817 char *path = argv[i];
01818
01819 if ((error = start_monitoring(path)) != SUCCESS) {
01820 log_msg(LOG_ERROR, _("could not monitor \"%s\" (%s)\n"),
01821 path, error_string(error));
01822 }
01823 }
01824
01825 main_loop();
01826
01827
01828 if ((error = process_pending_reaps()) != SUCCESS) {
01829 log_msg(LOG_ERROR, _("error processing pending reaps (%s)\n"),
01830 error_string(error));
01831 }
01832
01833 break;
01834 case PROG_ACTION_FIND:
01835 for (i = optind; i < argc; i++) {
01836 char *path = argv[i];
01837
01838 if ((error = find_log_files(path, recursive)) != SUCCESS) {
01839 log_msg(LOG_ERROR, _("could not find log files \"%s\" (%s)\n"),
01840 path, error_string(error));
01841 }
01842 }
01843 break;
01844 case PROG_ACTION_LIST:
01845 dump_database();
01846 break;
01847 }
01848
01849 if ((error = lwatch_fini()) != SUCCESS) {
01850 log_msg(LOG_ERROR, _("lwatch finalization failed (%s)\n"), error_string(error));
01851 }
01852
01853 if ((error = regexp_fini()) != SUCCESS) {
01854 log_msg(LOG_ERROR, _("regexp finalization failed (%s)\n"), error_string(error));
01855 }
01856
01857 if ((error = watch_database_fini()) != SUCCESS) {
01858 log_msg(LOG_ERROR, _("watch_database finalization failed (%s)\n"), error_string(error));
01859 }
01860
01861 if ((error = log_fini()) != SUCCESS) {
01862 fprintf(stderr, _("log finalization failed (%s)\n"), error_string(error));
01863 }
01864
01865 return 0;
01866 }
01867