1*c79ddfbfSchs /* $NetBSD: ras2.c,v 1.11 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 <unistd.h>
353ee9d48cSgmcgarry #include <sys/ras.h>
363ee9d48cSgmcgarry #include <sys/time.h>
373ee9d48cSgmcgarry #include <sys/wait.h>
383ee9d48cSgmcgarry
393ee9d48cSgmcgarry #define COUNT 10
403ee9d48cSgmcgarry
410be44b35Sperry volatile int handled = 0;
420be44b35Sperry volatile int count = 0;
433ee9d48cSgmcgarry struct itimerval itv;
443ee9d48cSgmcgarry
453ee9d48cSgmcgarry void handler(int);
463ee9d48cSgmcgarry
473ee9d48cSgmcgarry void
handler(int sig)483ee9d48cSgmcgarry handler(int sig)
493ee9d48cSgmcgarry {
503ee9d48cSgmcgarry
513ee9d48cSgmcgarry handled++;
523ee9d48cSgmcgarry }
533ee9d48cSgmcgarry
541cda93b4Sthorpej RAS_DECL(main);
551cda93b4Sthorpej
563ee9d48cSgmcgarry int
main(void)573ee9d48cSgmcgarry main(void)
583ee9d48cSgmcgarry {
593ee9d48cSgmcgarry int rv;
603ee9d48cSgmcgarry
613ee9d48cSgmcgarry signal(SIGVTALRM, handler);
623ee9d48cSgmcgarry
633ee9d48cSgmcgarry itv.it_interval.tv_sec = 0;
643ee9d48cSgmcgarry itv.it_interval.tv_usec = 0;
653ee9d48cSgmcgarry itv.it_value.tv_sec = 10;
663ee9d48cSgmcgarry itv.it_value.tv_usec = 0;
673ee9d48cSgmcgarry
681cda93b4Sthorpej if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
698625845cSmartin if (errno == EOPNOTSUPP) {
708625845cSmartin printf("RAS is not supported on this architecture\n");
718625845cSmartin return 0;
728625845cSmartin }
733ee9d48cSgmcgarry return (1);
748625845cSmartin }
753ee9d48cSgmcgarry
763ee9d48cSgmcgarry if (fork() != 0) {
773ee9d48cSgmcgarry wait(&rv);
785d0a5ce9Smartin return WEXITSTATUS(rv);
793ee9d48cSgmcgarry }
809551b193Sdsl setitimer(ITIMER_VIRTUAL, &itv, NULL);
813ee9d48cSgmcgarry
821cda93b4Sthorpej RAS_START(main);
833ee9d48cSgmcgarry count++;
843ee9d48cSgmcgarry if (count > COUNT)
85*c79ddfbfSchs exit(handled != 0);
863ee9d48cSgmcgarry
873ee9d48cSgmcgarry while (!handled) {
883ee9d48cSgmcgarry continue;
893ee9d48cSgmcgarry }
901cda93b4Sthorpej RAS_END(main);
913ee9d48cSgmcgarry
923ee9d48cSgmcgarry return (handled != 0);
933ee9d48cSgmcgarry }
94