Deleted Added
sdiff udiff text old ( 256281 ) new ( 266400 )
full compact
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 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>
36#include <stdbool.h>
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;
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 }
645 first = true;
646 seq = start;
647 for (;;) {
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) {
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 */
674 if (list->event[i].seq > stop) {
675 if (start <= stop)
676 goto finish;
677 else if (list->event[i].seq < start)
678 goto finish;
679 }
680 mfi_decode_evt(fd, &list->event[i], verbose);
681 first = false;
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");
695
696 free(list);
697 close(fd);
698
699 return (0);
700}
701MFI_COMMAND(show, events, show_events);