Home | History | Annotate | Line # | Download | only in ras3
ras3.c revision 1.9
      1  1.9    martin /* $NetBSD: ras3.c,v 1.9 2008/04/28 20:23:07 martin Exp $ */
      2  1.2  gmcgarry 
      3  1.2  gmcgarry /*-
      4  1.2  gmcgarry  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.2  gmcgarry  * All rights reserved.
      6  1.2  gmcgarry  *
      7  1.2  gmcgarry  * Redistribution and use in source and binary forms, with or without
      8  1.2  gmcgarry  * modification, are permitted provided that the following conditions
      9  1.2  gmcgarry  * are met:
     10  1.2  gmcgarry  * 1. Redistributions of source code must retain the above copyright
     11  1.2  gmcgarry  *    notice, this list of conditions and the following disclaimer.
     12  1.2  gmcgarry  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2  gmcgarry  *    notice, this list of conditions and the following disclaimer in the
     14  1.2  gmcgarry  *    documentation and/or other materials provided with the distribution.
     15  1.2  gmcgarry  *
     16  1.2  gmcgarry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.2  gmcgarry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.2  gmcgarry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.2  gmcgarry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.2  gmcgarry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.2  gmcgarry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.2  gmcgarry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.2  gmcgarry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.2  gmcgarry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.2  gmcgarry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.2  gmcgarry  * POSSIBILITY OF SUCH DAMAGE.
     27  1.2  gmcgarry  */
     28  1.2  gmcgarry 
     29  1.5    martin #include <errno.h>
     30  1.6   thorpej #include <inttypes.h>
     31  1.1  gmcgarry #include <stdio.h>
     32  1.1  gmcgarry #include <signal.h>
     33  1.1  gmcgarry #include <unistd.h>
     34  1.1  gmcgarry #include <sys/ras.h>
     35  1.1  gmcgarry #include <sys/time.h>
     36  1.1  gmcgarry #include <sys/wait.h>
     37  1.1  gmcgarry 
     38  1.1  gmcgarry #define COUNT	10
     39  1.1  gmcgarry 
     40  1.7     perry volatile int handled = 0;
     41  1.7     perry volatile int count = 0;
     42  1.1  gmcgarry struct itimerval itv;
     43  1.1  gmcgarry 
     44  1.1  gmcgarry void handler(int);
     45  1.1  gmcgarry 
     46  1.1  gmcgarry void
     47  1.1  gmcgarry handler(int sig)
     48  1.1  gmcgarry {
     49  1.1  gmcgarry 
     50  1.1  gmcgarry 	handled++;
     51  1.1  gmcgarry }
     52  1.1  gmcgarry 
     53  1.6   thorpej RAS_DECL(main);
     54  1.6   thorpej 
     55  1.1  gmcgarry int
     56  1.1  gmcgarry main(int argc, char *argv[])
     57  1.1  gmcgarry {
     58  1.1  gmcgarry 	int rv;
     59  1.1  gmcgarry 	char *const args[] = { argv[0], "1", NULL };
     60  1.1  gmcgarry 
     61  1.1  gmcgarry         signal(SIGVTALRM, handler);
     62  1.1  gmcgarry 
     63  1.1  gmcgarry         itv.it_interval.tv_sec = 0;
     64  1.1  gmcgarry         itv.it_interval.tv_usec = 0;
     65  1.1  gmcgarry         itv.it_value.tv_sec = 10;
     66  1.1  gmcgarry         itv.it_value.tv_usec = 0;
     67  1.1  gmcgarry         setitimer(ITIMER_VIRTUAL, &itv, NULL);
     68  1.1  gmcgarry 
     69  1.1  gmcgarry 	if (argc != 2) {
     70  1.6   thorpej 		if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
     71  1.5    martin 			if (errno == EOPNOTSUPP) {
     72  1.5    martin 				printf("RAS is not supported on this "
     73  1.5    martin 				    "architecture\n");
     74  1.5    martin 				return 0;
     75  1.5    martin 			}
     76  1.1  gmcgarry 			return (1);
     77  1.5    martin 		}
     78  1.1  gmcgarry 		if (fork() != 0) {
     79  1.1  gmcgarry 			wait(&rv);
     80  1.8    martin 			return (WEXITSTATUS(rv) == 0);
     81  1.1  gmcgarry 		}
     82  1.1  gmcgarry 		if (execvp(argv[0],args) < 0) {
     83  1.1  gmcgarry 			printf("exec failed\n");
     84  1.1  gmcgarry 			return (0);
     85  1.1  gmcgarry 		}
     86  1.1  gmcgarry 	}
     87  1.1  gmcgarry 
     88  1.6   thorpej 	RAS_START(main);
     89  1.1  gmcgarry 	count++;
     90  1.1  gmcgarry 	if (count > COUNT)
     91  1.1  gmcgarry 		goto end;
     92  1.1  gmcgarry 
     93  1.1  gmcgarry 	while (!handled) {
     94  1.1  gmcgarry 		continue;
     95  1.1  gmcgarry 	}
     96  1.1  gmcgarry end:
     97  1.6   thorpej 	RAS_END(main);
     98  1.1  gmcgarry 
     99  1.1  gmcgarry 	return (handled != 0);
    100  1.1  gmcgarry }
    101