2b6a269d748f24890fdc58e32b402018b08f7751
[xfstests-dev.git] / dmapi / src / simple / dm_query_session.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 <stdlib.h>
19 #include <stdio.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         char *sessinfo;
36         size_t rlen = 0;
37         dm_sessid_t sid = 0;
38         int buflen = 100;
39         char *versionstr;
40
41         while( (c = getopt(argc, argv, "hs:l:")) != -1 ) {
42                 switch(c){
43                 case 's':
44                         sid = atoi( optarg );
45                         break;
46                 case 'l':
47                         buflen = atoi( optarg );
48                         break;
49                 case 'h':
50                         fprintf(stderr, "Usage: %s <-s sid> [-l buflen]\n", argv[0]);
51                         exit(2);
52                 }
53         }
54
55         if( sid == 0 ){
56                 fprintf(stderr, "%s: must specify -s\n", argv[0] );
57                 exit(1);
58         }
59
60         if( (sessinfo = malloc( sizeof(char*) * buflen )) == NULL ){
61                 fprintf(stderr, "%s: malloc failed\n", argv[0] );
62                 exit(1);
63         }
64
65         if( dm_init_service( &versionstr ) < 0 )
66                 exit(1);
67
68         ret = dm_query_session( sid, buflen, sessinfo, &rlen );
69         printf( "ret=%d\n", ret );
70         printf( "rlen=%zd\n", rlen );
71         if( ret != -1 )
72                 printf( "sessinfo=%s\n", sessinfo );
73         exit(0);
74 }