generic/60[78]: ensure the initial DAX file flag state before test
[xfstests-dev.git] / dmapi / src / suite2 / src / send_msg.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <sys/types.h>
8
9 #include <errno.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <strings.h>
13
14 #include <lib/dmport.h>
15 #include <lib/hsm.h>
16
17 #include <getopt.h>
18 #include <string.h>
19
20
21 /*---------------------------------------------------------------------------
22
23 Test program used to test the DMAPI function send_msg().  
24 The command line is:
25
26         send_msg [-a] [-s sid] string
27
28 where string is the msgdata to be stored in the event.
29 sid is the session ID to use for the event.
30
31 ----------------------------------------------------------------------------*/
32
33 #ifndef linux
34 extern  char    *sys_errlist[];
35 #endif
36 extern  int     optind;
37 extern  char    *optarg;
38
39
40 char    *Progname;
41
42 static void
43 usage(void)
44 {
45         fprintf(stderr, "usage:\t%s [-a] [-s sid] string\n", Progname);
46         exit(1);
47 }
48
49
50 int
51 main(
52         int     argc, 
53         char    **argv)
54 {
55         dm_sessid_t     sid = DM_NO_SESSION;
56         char            *string;
57         char            *name;
58         int             opt;
59         dm_msgtype_t    msgtype = DM_MSGTYPE_SYNC;
60         
61         Progname = strrchr(argv[0], '/');
62         if (Progname) {
63                 Progname++;
64         } else {
65                 Progname = argv[0];
66         }
67
68         /* Crack and validate the command line options. */
69
70         while ((opt = getopt(argc, argv, "as:")) != EOF) {
71                 switch (opt) {
72                 case 'a':
73                         msgtype = DM_MSGTYPE_ASYNC;
74                         break;
75                 case 's':
76                         sid = atol(optarg);
77                         break;
78                 case '?':
79                         usage();
80                 }
81         }
82         if (optind + 1 != argc)
83                 usage();
84         string = argv[optind++];
85
86         if (dm_init_service(&name) == -1)  {
87                 fprintf(stderr, "Can't initialize the DMAPI\n");
88                 exit(1);
89         }
90         
91         if (sid == DM_NO_SESSION)
92                 find_test_session(&sid);
93         
94         if (dm_send_msg(sid, msgtype, strlen(string)+ 1, string)) {
95                 fprintf(stderr, "dm_send_msg failed, %s\n",
96                         strerror(errno));
97                 exit(1);
98         }
99
100         exit(0);
101 }
102