common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / dmapi / src / suite1 / cmd / create_userevent.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
19 #include <lib/hsm.h>
20
21 #include <string.h>
22 #include <getopt.h>
23
24 /*---------------------------------------------------------------------------
25
26 Test program used to test the DMAPI function create_userevent().  The
27 command line is:
28
29         create_userevent [-s sid] string
30
31 where string is the msgdata to be stored in the event.
32 sid is the session ID to use for the event.
33
34 ----------------------------------------------------------------------------*/
35
36 #ifndef linux
37 extern  char    *sys_errlist[];
38 #endif
39 extern  int     optind;
40 extern  char    *optarg;
41
42
43 char    *Progname;
44
45 static void
46 usage(void)
47 {
48         fprintf(stderr, "usage:\t%s [-s sid] string\n", Progname);
49         exit(1);
50 }
51
52
53 int
54 main(
55         int     argc, 
56         char    **argv)
57 {
58         dm_sessid_t     sid = DM_NO_SESSION;
59         char            *string;
60         dm_token_t      token;
61         char            *name;
62         int             opt;
63
64         Progname = strrchr(argv[0], '/');
65         if (Progname) {
66                 Progname++;
67         } else {
68                 Progname = argv[0];
69         }
70
71         /* Crack and validate the command line options. */
72
73         while ((opt = getopt(argc, argv, "s:")) != EOF) {
74                 switch (opt) {
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         if (sid == DM_NO_SESSION)
91                 find_test_session(&sid);
92
93         if (dm_create_userevent(sid, strlen(string)+ 1, string, &token)) {
94                 fprintf(stderr, "dm_create_userevent failed, %s\n",
95                         strerror(errno));
96                 exit(1);
97         }
98
99         fprintf(stdout, "New token %d\n", token);
100         exit(0);
101 }