20c4cb3abc2316b1a29f9bdc9a4f010f62a7806d
[xfstests-dev.git] / dmapi / src / simple / dm_find_eventmsg.c
1 /*
2  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <sys/errno.h>
21 #include <getopt.h>
22 #ifdef linux
23 #include <dmapi.h>
24 #endif
25 #ifdef __sgi
26 #include <sys/dmi.h>
27 #endif
28
29 int
30 main( int argc, char **argv )
31 {
32         extern char *optarg;
33         int c;
34         int ret;
35         dm_sessid_t sid = 0;
36         dm_token_t token = 0;
37         dm_eventmsg_t msg;
38         size_t rlen;
39         int buflen = sizeof(dm_eventmsg_t) + 100;
40         char *versionstr;
41
42         while( (c = getopt(argc, argv, "hs:t:l:q")) != -1 ) {
43                 switch(c){
44                 case 's':
45                         sid = atoi( optarg );
46                         break;
47                 case 't':
48                         token = atoi( optarg );
49                         break;
50                 case 'l':
51                         buflen = atoi( optarg );
52                         break;
53                 case 'q':
54                         printf("dm_eventmsg_t=%d\n", sizeof(dm_eventmsg_t) );
55                         exit(0);
56                 case 'h':
57                         fprintf(stderr, "Usage: %s <-s sid> <-t token> [-l buflen]\n", argv[0]);
58                         fprintf(stderr, "       %s -q\n", argv[0]);
59                         exit(2);
60                 }
61         }
62
63         if( sid == 0 ){
64                 fprintf(stderr, "%s: must specify -s\n", argv[0] );
65                 exit(1);
66         }
67
68         if( token == 0 ){
69                 fprintf(stderr, "%s: must specify -t\n", argv[0] );
70                 exit(1);
71         }
72
73         if( dm_init_service( &versionstr ) < 0 )
74                 exit(1);
75
76         ret = dm_find_eventmsg( sid, token, buflen, &msg, &rlen );
77         printf( "ret=%d\n", ret );
78         printf( "rlen=%d\n", rlen );
79         exit(0);
80 }