mfi_evt.c (256281) | mfi_evt.c (266400) |
---|---|
1/*- 2 * Copyright (c) 2008, 2009 Yahoo!, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2008, 2009 Yahoo!, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: stable/10/usr.sbin/mfiutil/mfi_evt.c 237260 2012-06-19 06:18:42Z eadler $ | 29 * $FreeBSD: stable/10/usr.sbin/mfiutil/mfi_evt.c 266400 2014-05-18 15:28:25Z jhb $ |
30 */ 31 32#include <sys/types.h> 33#include <sys/errno.h> 34#include <err.h> 35#include <fcntl.h> | 30 */ 31 32#include <sys/types.h> 33#include <sys/errno.h> 34#include <err.h> 35#include <fcntl.h> |
36#include <stdbool.h> |
|
36#include <stdio.h> 37#include <stdlib.h> 38#include <strings.h> 39#include <time.h> 40#include <unistd.h> 41#include "mfiutil.h" 42 43static int --- 485 unchanged lines hidden (view full) --- 529} 530 531static int 532show_events(int ac, char **av) 533{ 534 struct mfi_evt_log_state info; 535 struct mfi_evt_list *list; 536 union mfi_evt filter; | 37#include <stdio.h> 38#include <stdlib.h> 39#include <strings.h> 40#include <time.h> 41#include <unistd.h> 42#include "mfiutil.h" 43 44static int --- 485 unchanged lines hidden (view full) --- 530} 531 532static int 533show_events(int ac, char **av) 534{ 535 struct mfi_evt_log_state info; 536 struct mfi_evt_list *list; 537 union mfi_evt filter; |
538 bool first; |
|
537 long val; 538 char *cp; 539 ssize_t size; 540 uint32_t seq, start, stop; 541 uint8_t status; 542 int ch, error, fd, num_events, verbose; 543 u_int i; 544 --- 90 unchanged lines hidden (view full) --- 635 } 636 637 list = malloc(size); 638 if (list == NULL) { 639 warnx("malloc failed"); 640 close(fd); 641 return (ENOMEM); 642 } | 539 long val; 540 char *cp; 541 ssize_t size; 542 uint32_t seq, start, stop; 543 uint8_t status; 544 int ch, error, fd, num_events, verbose; 545 u_int i; 546 --- 90 unchanged lines hidden (view full) --- 637 } 638 639 list = malloc(size); 640 if (list == NULL) { 641 warnx("malloc failed"); 642 close(fd); 643 return (ENOMEM); 644 } |
643 for (seq = start;;) { | 645 first = true; 646 seq = start; 647 for (;;) { |
644 if (mfi_get_events(fd, list, num_events, filter, seq, 645 &status) < 0) { 646 error = errno; 647 warn("Failed to fetch events"); 648 free(list); 649 close(fd); 650 return (error); 651 } 652 if (status == MFI_STAT_NOT_FOUND) { | 648 if (mfi_get_events(fd, list, num_events, filter, seq, 649 &status) < 0) { 650 error = errno; 651 warn("Failed to fetch events"); 652 free(list); 653 close(fd); 654 return (error); 655 } 656 if (status == MFI_STAT_NOT_FOUND) { |
653 if (seq == start) 654 warnx("No matching events found"); | |
655 break; 656 } 657 if (status != MFI_STAT_OK) { 658 warnx("Error fetching events: %s", mfi_status(status)); 659 free(list); 660 close(fd); 661 return (EIO); 662 } 663 664 for (i = 0; i < list->count; i++) { 665 /* 666 * If this event is newer than 'stop_seq' then 667 * break out of the loop. Note that the log 668 * is a circular buffer so we have to handle 669 * the case that our stop point is earlier in 670 * the buffer than our start point. 671 */ | 657 break; 658 } 659 if (status != MFI_STAT_OK) { 660 warnx("Error fetching events: %s", mfi_status(status)); 661 free(list); 662 close(fd); 663 return (EIO); 664 } 665 666 for (i = 0; i < list->count; i++) { 667 /* 668 * If this event is newer than 'stop_seq' then 669 * break out of the loop. Note that the log 670 * is a circular buffer so we have to handle 671 * the case that our stop point is earlier in 672 * the buffer than our start point. 673 */ |
672 if (list->event[i].seq >= stop) { | 674 if (list->event[i].seq > stop) { |
673 if (start <= stop) | 675 if (start <= stop) |
674 break; | 676 goto finish; |
675 else if (list->event[i].seq < start) | 677 else if (list->event[i].seq < start) |
676 break; | 678 goto finish; |
677 } 678 mfi_decode_evt(fd, &list->event[i], verbose); | 679 } 680 mfi_decode_evt(fd, &list->event[i], verbose); |
681 first = false; |
|
679 } 680 681 /* 682 * XXX: If the event's seq # is the end of the buffer 683 * then this probably won't do the right thing. We 684 * need to know the size of the buffer somehow. 685 */ 686 seq = list->event[list->count - 1].seq + 1; 687 688 } | 682 } 683 684 /* 685 * XXX: If the event's seq # is the end of the buffer 686 * then this probably won't do the right thing. We 687 * need to know the size of the buffer somehow. 688 */ 689 seq = list->event[list->count - 1].seq + 1; 690 691 } |
692finish: 693 if (first) 694 warnx("No matching events found"); |
|
689 690 free(list); 691 close(fd); 692 693 return (0); 694} 695MFI_COMMAND(show, events, show_events); | 695 696 free(list); 697 close(fd); 698 699 return (0); 700} 701MFI_COMMAND(show, events, show_events); |