Deleted Added
full compact
mfi_evt.c (222589) mfi_evt.c (222899)
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: head/usr.sbin/mfiutil/mfi_evt.c 222589 2011-06-02 00:43:16Z emaste $
29 * $FreeBSD: head/usr.sbin/mfiutil/mfi_evt.c 222899 2011-06-09 19:52:28Z bz $
30 */
31
32#include <sys/types.h>
33#include <sys/errno.h>
34#include <err.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <strings.h>

--- 40 unchanged lines hidden (view full) ---

78 error = errno;
79 warn("mfi_open");
80 return (error);
81 }
82
83 if (mfi_event_get_info(fd, &info, NULL) < 0) {
84 error = errno;
85 warn("Failed to get event log info");
30 */
31
32#include <sys/types.h>
33#include <sys/errno.h>
34#include <err.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <strings.h>

--- 40 unchanged lines hidden (view full) ---

78 error = errno;
79 warn("mfi_open");
80 return (error);
81 }
82
83 if (mfi_event_get_info(fd, &info, NULL) < 0) {
84 error = errno;
85 warn("Failed to get event log info");
86 close(fd);
86 return (error);
87 }
88
89 printf("mfi%d Event Log Sequence Numbers:\n", mfi_unit);
90 printf(" Newest Seq #: %u\n", info.newest_seq_num);
91 printf(" Oldest Seq #: %u\n", info.oldest_seq_num);
92 printf(" Clear Seq #: %u\n", info.clear_seq_num);
93 printf("Shutdown Seq #: %u\n", info.shutdown_seq_num);

--- 451 unchanged lines hidden (view full) ---

545 error = errno;
546 warn("mfi_open");
547 return (error);
548 }
549
550 if (mfi_event_get_info(fd, &info, NULL) < 0) {
551 error = errno;
552 warn("Failed to get event log info");
87 return (error);
88 }
89
90 printf("mfi%d Event Log Sequence Numbers:\n", mfi_unit);
91 printf(" Newest Seq #: %u\n", info.newest_seq_num);
92 printf(" Oldest Seq #: %u\n", info.oldest_seq_num);
93 printf(" Clear Seq #: %u\n", info.clear_seq_num);
94 printf("Shutdown Seq #: %u\n", info.shutdown_seq_num);

--- 451 unchanged lines hidden (view full) ---

546 error = errno;
547 warn("mfi_open");
548 return (error);
549 }
550
551 if (mfi_event_get_info(fd, &info, NULL) < 0) {
552 error = errno;
553 warn("Failed to get event log info");
554 close(fd);
553 return (error);
554 }
555
556 /* Default settings. */
557 num_events = 15;
558 filter.members.reserved = 0;
559 filter.members.locale = MFI_EVT_LOCALE_ALL;
560 filter.members.evt_class = MFI_EVT_CLASS_WARNING;

--- 4 unchanged lines hidden (view full) ---

565 /* Parse any options. */
566 optind = 1;
567 while ((ch = getopt(ac, av, "c:l:n:v")) != -1) {
568 switch (ch) {
569 case 'c':
570 if (parse_class(optarg, &filter.members.evt_class) < 0) {
571 error = errno;
572 warn("Error parsing event class");
555 return (error);
556 }
557
558 /* Default settings. */
559 num_events = 15;
560 filter.members.reserved = 0;
561 filter.members.locale = MFI_EVT_LOCALE_ALL;
562 filter.members.evt_class = MFI_EVT_CLASS_WARNING;

--- 4 unchanged lines hidden (view full) ---

567 /* Parse any options. */
568 optind = 1;
569 while ((ch = getopt(ac, av, "c:l:n:v")) != -1) {
570 switch (ch) {
571 case 'c':
572 if (parse_class(optarg, &filter.members.evt_class) < 0) {
573 error = errno;
574 warn("Error parsing event class");
575 close(fd);
573 return (error);
574 }
575 break;
576 case 'l':
577 if (parse_locale(optarg, &filter.members.locale) < 0) {
578 error = errno;
579 warn("Error parsing event locale");
576 return (error);
577 }
578 break;
579 case 'l':
580 if (parse_locale(optarg, &filter.members.locale) < 0) {
581 error = errno;
582 warn("Error parsing event locale");
583 close(fd);
580 return (error);
581 }
582 break;
583 case 'n':
584 val = strtol(optarg, &cp, 0);
585 if (*cp != '\0' || val <= 0) {
586 warnx("Invalid event count");
584 return (error);
585 }
586 break;
587 case 'n':
588 val = strtol(optarg, &cp, 0);
589 if (*cp != '\0' || val <= 0) {
590 warnx("Invalid event count");
591 close(fd);
587 return (EINVAL);
588 }
589 num_events = val;
590 break;
591 case 'v':
592 verbose = 1;
593 break;
594 case '?':
595 default:
592 return (EINVAL);
593 }
594 num_events = val;
595 break;
596 case 'v':
597 verbose = 1;
598 break;
599 case '?':
600 default:
601 close(fd);
596 return (EINVAL);
597 }
598 }
599 ac -= optind;
600 av += optind;
601
602 /* Determine buffer size and validate it. */
603 size = sizeof(struct mfi_evt_list) + sizeof(struct mfi_evt_detail) *
604 (num_events - 1);
605 if (size > getpagesize()) {
606 warnx("Event count is too high");
602 return (EINVAL);
603 }
604 }
605 ac -= optind;
606 av += optind;
607
608 /* Determine buffer size and validate it. */
609 size = sizeof(struct mfi_evt_list) + sizeof(struct mfi_evt_detail) *
610 (num_events - 1);
611 if (size > getpagesize()) {
612 warnx("Event count is too high");
613 close(fd);
607 return (EINVAL);
608 }
609
610 /* Handle optional start and stop sequence numbers. */
611 if (ac > 2) {
612 warnx("show events: extra arguments");
614 return (EINVAL);
615 }
616
617 /* Handle optional start and stop sequence numbers. */
618 if (ac > 2) {
619 warnx("show events: extra arguments");
620 close(fd);
613 return (EINVAL);
614 }
615 if (ac > 0 && parse_seq(&info, av[0], &start) < 0) {
616 error = errno;
617 warn("Error parsing starting sequence number");
621 return (EINVAL);
622 }
623 if (ac > 0 && parse_seq(&info, av[0], &start) < 0) {
624 error = errno;
625 warn("Error parsing starting sequence number");
626 close(fd);
618 return (error);
619 }
620 if (ac > 1 && parse_seq(&info, av[1], &stop) < 0) {
621 error = errno;
622 warn("Error parsing ending sequence number");
627 return (error);
628 }
629 if (ac > 1 && parse_seq(&info, av[1], &stop) < 0) {
630 error = errno;
631 warn("Error parsing ending sequence number");
632 close(fd);
623 return (error);
624 }
625
626 list = malloc(size);
627 if (list == NULL) {
628 warnx("malloc failed");
633 return (error);
634 }
635
636 list = malloc(size);
637 if (list == NULL) {
638 warnx("malloc failed");
639 close(fd);
629 return (ENOMEM);
630 }
631 for (seq = start;;) {
632 if (mfi_get_events(fd, list, num_events, filter, seq,
633 &status) < 0) {
634 error = errno;
635 warn("Failed to fetch events");
640 return (ENOMEM);
641 }
642 for (seq = start;;) {
643 if (mfi_get_events(fd, list, num_events, filter, seq,
644 &status) < 0) {
645 error = errno;
646 warn("Failed to fetch events");
647 free(list);
648 close(fd);
636 return (error);
637 }
638 if (status == MFI_STAT_NOT_FOUND) {
639 if (seq == start)
640 warnx("No matching events found");
641 break;
642 }
643 if (status != MFI_STAT_OK) {
644 warnx("Error fetching events: %s", mfi_status(status));
649 return (error);
650 }
651 if (status == MFI_STAT_NOT_FOUND) {
652 if (seq == start)
653 warnx("No matching events found");
654 break;
655 }
656 if (status != MFI_STAT_OK) {
657 warnx("Error fetching events: %s", mfi_status(status));
658 free(list);
659 close(fd);
645 return (EIO);
646 }
647
648 for (i = 0; i < list->count; i++) {
649 /*
650 * If this event is newer than 'stop_seq' then
651 * break out of the loop. Note that the log
652 * is a circular buffer so we have to handle

--- 27 unchanged lines hidden ---
660 return (EIO);
661 }
662
663 for (i = 0; i < list->count; i++) {
664 /*
665 * If this event is newer than 'stop_seq' then
666 * break out of the loop. Note that the log
667 * is a circular buffer so we have to handle

--- 27 unchanged lines hidden ---