ecb68364c87bc7ce90de103b9b7ba3c9a8e4cef3
[xfstests-dev.git] / dmapi / src / suite2 / src / send_msg.c
1 /*
2  * Copyright (c) 2000-2001 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 #include <getopt.h>
44 #include <string.h>
45
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         fprintf(stderr, "usage:\t%s [-a] [-s sid] string\n", Progname);
72         exit(1);
73 }
74
75
76 int
77 main(
78         int     argc, 
79         char    **argv)
80 {
81         dm_sessid_t     sid = DM_NO_SESSION;
82         char            *string;
83         char            *name;
84         int             opt;
85         dm_msgtype_t    msgtype = DM_MSGTYPE_SYNC;
86         
87         if (Progname = strrchr(argv[0], '/')) {
88                 Progname++;
89         } else {
90                 Progname = argv[0];
91         }
92
93         /* Crack and validate the command line options. */
94
95         while ((opt = getopt(argc, argv, "as:")) != EOF) {
96                 switch (opt) {
97                 case 'a':
98                         msgtype = DM_MSGTYPE_ASYNC;
99                         break;
100                 case 's':
101                         sid = atol(optarg);
102                         break;
103                 case '?':
104                         usage();
105                 }
106         }
107         if (optind + 1 != argc)
108                 usage();
109         string = argv[optind++];
110
111         if (dm_init_service(&name) == -1)  {
112                 fprintf(stderr, "Can't initialize the DMAPI\n");
113                 exit(1);
114         }
115         
116         if (sid == DM_NO_SESSION)
117                 find_test_session(&sid);
118         
119         if (dm_send_msg(sid, msgtype, strlen(string)+ 1, string)) {
120                 fprintf(stderr, "dm_send_msg failed, %s\n",
121                         strerror(errno));
122                 exit(1);
123         }
124
125         exit(0);
126 }
127