cmd/xfsprogs/libdm/dmapi_tests/README 1.1 Renamed to cmd/xfstests/dmapi/README
[xfstests-dev.git] / dmapi / src / suite2 / src / send_msg.c
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  * 
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * 
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  * 
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  * 
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  * 
26  * http://www.sgi.com 
27  * 
28  * For further information regarding this notice, see: 
29  * 
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include <sys/types.h>
34
35 #include <errno.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <strings.h>
39
40 #include <lib/dmport.h>
41 #include <lib/hsm.h>
42
43 #ifdef linux
44 #include <string.h>
45 #endif
46
47 /*---------------------------------------------------------------------------
48
49 Test program used to test the DMAPI function send_msg().  
50 The command line is:
51
52         send_msg [-a] [-s sid] string
53
54 where string is the msgdata to be stored in the event.
55 sid is the session ID to use for the event.
56
57 ----------------------------------------------------------------------------*/
58
59 #ifndef linux
60 extern  char    *sys_errlist[];
61 #endif
62 extern  int     optind;
63 extern  char    *optarg;
64
65
66 char    *Progname;
67
68 static void
69 usage(void)
70 {
71         int     i;
72
73         fprintf(stderr, "usage:\t%s [-a] [-s sid] string\n", Progname);
74         exit(1);
75 }
76
77
78 int
79 main(
80         int     argc, 
81         char    **argv)
82 {
83         dm_sessid_t     sid = DM_NO_SESSION;
84         char            *string;
85         dm_token_t      token;
86         char            *name;
87         int             opt;
88         int             i;
89         dm_msgtype_t    msgtype = DM_MSGTYPE_SYNC;
90         
91         if (Progname = strrchr(argv[0], '/')) {
92                 Progname++;
93         } else {
94                 Progname = argv[0];
95         }
96
97         /* Crack and validate the command line options. */
98
99         while ((opt = getopt(argc, argv, "as:")) != EOF) {
100                 switch (opt) {
101                 case 'a':
102                         msgtype = DM_MSGTYPE_ASYNC;
103                         break;
104                 case 's':
105                         sid = atol(optarg);
106                         break;
107                 case '?':
108                         usage();
109                 }
110         }
111         if (optind + 1 != argc)
112                 usage();
113         string = argv[optind++];
114
115         if (dm_init_service(&name) == -1)  {
116                 fprintf(stderr, "Can't inititalize the DMAPI\n");
117                 exit(1);
118         }
119         
120         if (sid == DM_NO_SESSION)
121                 find_test_session(&sid);
122         
123         if (dm_send_msg(sid, msgtype, strlen(string)+ 1, string)) {
124                 fprintf(stderr, "dm_send_msg failed, %s\n",
125                         strerror(errno));
126                 exit(1);
127         }
128
129         exit(0);
130 }
131