1*c79ddfbfSchs /* $NetBSD: ras1.c,v 1.9 2012/11/02 14:53:03 chs Exp $ */
2fdfb13e7Sgmcgarry
3fdfb13e7Sgmcgarry /*-
4fdfb13e7Sgmcgarry * Copyright (c) 2002 The NetBSD Foundation, Inc.
5fdfb13e7Sgmcgarry * All rights reserved.
6fdfb13e7Sgmcgarry *
7fdfb13e7Sgmcgarry * Redistribution and use in source and binary forms, with or without
8fdfb13e7Sgmcgarry * modification, are permitted provided that the following conditions
9fdfb13e7Sgmcgarry * are met:
10fdfb13e7Sgmcgarry * 1. Redistributions of source code must retain the above copyright
11fdfb13e7Sgmcgarry * notice, this list of conditions and the following disclaimer.
12fdfb13e7Sgmcgarry * 2. Redistributions in binary form must reproduce the above copyright
13fdfb13e7Sgmcgarry * notice, this list of conditions and the following disclaimer in the
14fdfb13e7Sgmcgarry * documentation and/or other materials provided with the distribution.
15fdfb13e7Sgmcgarry *
16fdfb13e7Sgmcgarry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17fdfb13e7Sgmcgarry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18fdfb13e7Sgmcgarry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19fdfb13e7Sgmcgarry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20fdfb13e7Sgmcgarry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21fdfb13e7Sgmcgarry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22fdfb13e7Sgmcgarry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23fdfb13e7Sgmcgarry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24fdfb13e7Sgmcgarry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25fdfb13e7Sgmcgarry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26fdfb13e7Sgmcgarry * POSSIBILITY OF SUCH DAMAGE.
27fdfb13e7Sgmcgarry */
28fdfb13e7Sgmcgarry
29*c79ddfbfSchs #include <stdlib.h>
308625845cSmartin #include <errno.h>
311cda93b4Sthorpej #include <inttypes.h>
323ee9d48cSgmcgarry #include <stdio.h>
333ee9d48cSgmcgarry #include <signal.h>
343ee9d48cSgmcgarry #include <sys/ras.h>
353ee9d48cSgmcgarry #include <sys/time.h>
363ee9d48cSgmcgarry
373ee9d48cSgmcgarry #define COUNT 10
383ee9d48cSgmcgarry
390be44b35Sperry volatile int handled = 0;
400be44b35Sperry volatile int count = 0;
413ee9d48cSgmcgarry struct itimerval itv;
423ee9d48cSgmcgarry
433ee9d48cSgmcgarry void handler(int);
443ee9d48cSgmcgarry
453ee9d48cSgmcgarry void
handler(int sig)463ee9d48cSgmcgarry handler(int sig)
473ee9d48cSgmcgarry {
483ee9d48cSgmcgarry
493ee9d48cSgmcgarry handled++;
503ee9d48cSgmcgarry }
513ee9d48cSgmcgarry
521cda93b4Sthorpej RAS_DECL(main);
531cda93b4Sthorpej
543ee9d48cSgmcgarry int
main(void)553ee9d48cSgmcgarry main(void)
563ee9d48cSgmcgarry {
573ee9d48cSgmcgarry
583ee9d48cSgmcgarry signal(SIGVTALRM, handler);
593ee9d48cSgmcgarry
603ee9d48cSgmcgarry itv.it_interval.tv_sec = 0;
613ee9d48cSgmcgarry itv.it_interval.tv_usec = 0;
623ee9d48cSgmcgarry itv.it_value.tv_sec = 10;
633ee9d48cSgmcgarry itv.it_value.tv_usec = 0;
643ee9d48cSgmcgarry setitimer(ITIMER_VIRTUAL, &itv, NULL);
653ee9d48cSgmcgarry
661cda93b4Sthorpej if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
678625845cSmartin if (errno == EOPNOTSUPP) {
688625845cSmartin printf("RAS is not supported on this architecture\n");
698625845cSmartin return 0;
708625845cSmartin }
713ee9d48cSgmcgarry return (1);
728625845cSmartin }
733ee9d48cSgmcgarry
741cda93b4Sthorpej RAS_START(main);
753ee9d48cSgmcgarry count++;
763ee9d48cSgmcgarry if (count > COUNT)
77*c79ddfbfSchs exit(handled != 0);
783ee9d48cSgmcgarry
793ee9d48cSgmcgarry while (!handled) {
803ee9d48cSgmcgarry continue;
813ee9d48cSgmcgarry }
821cda93b4Sthorpej RAS_END(main);
833ee9d48cSgmcgarry
843ee9d48cSgmcgarry return (handled != 0);
853ee9d48cSgmcgarry }
86