Changeset 271
- Timestamp:
- Jan 8, 2010, 6:38:48 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docs/Changelog
r270 r271 1 1 2.6.2: 2 * handle named pipes in log monitoring module 3 (open in nonblocking mode, ignore read error if empty) 2 4 * fix bug in the server function to probe for necessity 3 5 of configuration reload for client -
trunk/include/sh_log_check.h
r186 r271 25 25 #define SH_LOGFILE_MOVED (1<<0) 26 26 #define SH_LOGFILE_REWIND (1<<1) 27 #define SH_LOGFILE_PIPE (1<<2) 27 28 28 29 struct sh_logfile -
trunk/src/sh_log_check.c
r265 r271 7 7 #include <sys/types.h> 8 8 #include <sys/stat.h> 9 #include <fcntl.h> 10 11 #if !defined(O_NONBLOCK) 12 #if defined(O_NDELAY) 13 #define O_NONBLOCK O_NDELAY 14 #else 15 #define O_NONBLOCK 0 16 #endif 17 #endif 9 18 10 19 #ifdef USE_LOGFILE_MONITOR … … 316 325 if (0 == stat(thisfile->filename, &buf)) 317 326 { 318 thisfile->inode = buf.st_ino; 319 thisfile->device_id = buf.st_dev; 327 if (S_ISREG(buf.st_mode) 328 #ifdef S_ISLNK 329 || S_ISLNK(buf.st_mode) 330 #endif 331 ) 332 { 333 thisfile->inode = buf.st_ino; 334 thisfile->device_id = buf.st_dev; 335 336 if (0 != read_pos(thisfile)) 337 { 338 thisfile->flags &= ~SH_LOGFILE_REWIND; 339 } 340 } 341 else if (S_ISFIFO(buf.st_mode)) 342 { 343 thisfile->inode = buf.st_ino; 344 thisfile->device_id = buf.st_dev; 345 thisfile->flags |= SH_LOGFILE_PIPE; 346 } 347 } 348 else 349 { 350 sh_string * msg = sh_string_new(0); 351 sh_string_add_from_char(msg, _("Logfile is not a regular file, link, or named pipe: ")); 352 sh_string_add_from_char(msg, splits[1]); 320 353 321 if (0 != read_pos(thisfile)) 322 { 323 thisfile->flags &= ~SH_LOGFILE_REWIND; 324 } 354 SH_MUTEX_LOCK(mutex_thread_nolog); 355 sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN, 356 sh_string_str(msg), 357 _("sh_add_watch")); 358 SH_MUTEX_UNLOCK(mutex_thread_nolog); 359 sh_string_destroy(&msg); 360 361 SH_FREE(filename); 362 SH_FREE(thisfile); 363 SH_FREE(new); 364 return -1; 325 365 } 326 366 … … 340 380 sh_watched_logs = thisfile->next; 341 381 342 save_pos(thisfile); 382 if ((thisfile->flags & SH_LOGFILE_PIPE) == 0) 383 { 384 save_pos(thisfile); 385 } 343 386 344 387 if (thisfile->fp) … … 360 403 void sh_check_watches() 361 404 { 362 static size_t count = 0;363 405 struct sh_logrecord * logrecord; 364 406 struct sh_logfile * thisfile = sh_watched_logs; … … 373 415 while (thisfile) 374 416 { 417 volatile size_t count = 0; 418 375 419 SH_MUTEX_LOCK(mutex_thread_nolog); 376 420 tmp = sh_util_safe_name (thisfile->filename); … … 529 573 /* detect and handle logfile rotation 530 574 */ 531 if (logfile->inode != buf.st_ino && logfile->inode != 0) 575 if (logfile->inode != buf.st_ino && 576 logfile->inode != 0 && 577 !S_ISFIFO(buf.st_mode)) 532 578 { 533 579 /* Case 1) We have dealt with the moved file already. … … 572 618 /* open file 573 619 */ 574 logfile->fp = fopen(filename->str, "r"); 620 if (!S_ISFIFO(buf.st_mode)) 621 { 622 logfile->fp = fopen(filename->str, "r"); 623 } 624 else 625 { 626 int fd_temp = open (filename->str, O_RDONLY|O_NONBLOCK); 627 628 if (fd_temp >= 0) 629 { 630 logfile->fp = fdopen(fd_temp, "r"); 631 } 632 } 633 575 634 if (!logfile->fp) 576 635 { … … 590 649 sh_string_destroy(&filename); 591 650 592 if ((logfile->flags & SH_LOGFILE_REWIND) != 0) 593 { 594 rewind(logfile->fp); 595 fgetpos(logfile->fp, &(logfile->offset)); 596 logfile->flags &= ~SH_LOGFILE_REWIND; 597 } 598 else 599 { 600 /* file too short 601 */ 602 if (0 != fsetpos(logfile->fp, &(logfile->offset))) 651 if ((logfile->flags & SH_LOGFILE_PIPE) == 0) 652 { 653 if ((logfile->flags & SH_LOGFILE_REWIND) != 0) 603 654 { 604 655 rewind(logfile->fp); 605 656 fgetpos(logfile->fp, &(logfile->offset)); 657 logfile->flags &= ~SH_LOGFILE_REWIND; 658 } 659 else 660 { 661 /* file too short 662 */ 663 if (0 != fsetpos(logfile->fp, &(logfile->offset))) 664 { 665 rewind(logfile->fp); 666 fgetpos(logfile->fp, &(logfile->offset)); 667 } 606 668 } 607 669 } … … 631 693 logfile->fp = NULL; 632 694 sh_string_destroy(&s); 633 if (status == 0 )695 if (status == 0 || (logfile->flags & SH_LOGFILE_PIPE) != 0) 634 696 { 635 697 return NULL; … … 707 769 logfile->fp = NULL; 708 770 sh_string_destroy(&s); 709 if (status == 0 )771 if (status == 0 || (logfile->flags & SH_LOGFILE_PIPE) != 0) 710 772 { 711 773 return NULL; … … 747 809 if (status != 1) 748 810 { 749 if (ferror(logfile->fp) )811 if (ferror(logfile->fp) && (logfile->flags & SH_LOGFILE_PIPE) == 0) 750 812 { 751 813 char * tmp;
Note:
See TracChangeset
for help on using the changeset viewer.