dmapi: spdx license conversion
[xfstests-dev.git] / dmapi / src / suite1 / cmd / create_userevent.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 <lib/hsm.h>
8
9 #include <string.h>
10 #include <getopt.h>
11
12 /*---------------------------------------------------------------------------
13
14 Test program used to test the DMAPI function create_userevent().  The
15 command line is:
16
17         create_userevent [-s sid] string
18
19 where string is the msgdata to be stored in the event.
20 sid is the session ID to use for the event.
21
22 ----------------------------------------------------------------------------*/
23
24 #ifndef linux
25 extern  char    *sys_errlist[];
26 #endif
27 extern  int     optind;
28 extern  char    *optarg;
29
30
31 char    *Progname;
32
33 static void
34 usage(void)
35 {
36         fprintf(stderr, "usage:\t%s [-s sid] string\n", Progname);
37         exit(1);
38 }
39
40
41 int
42 main(
43         int     argc, 
44         char    **argv)
45 {
46         dm_sessid_t     sid = DM_NO_SESSION;
47         char            *string;
48         dm_token_t      token;
49         char            *name;
50         int             opt;
51
52         Progname = strrchr(argv[0], '/');
53         if (Progname) {
54                 Progname++;
55         } else {
56                 Progname = argv[0];
57         }
58
59         /* Crack and validate the command line options. */
60
61         while ((opt = getopt(argc, argv, "s:")) != EOF) {
62                 switch (opt) {
63                 case 's':
64                         sid = atol(optarg);
65                         break;
66                 case '?':
67                         usage();
68                 }
69         }
70         if (optind + 1 != argc)
71                 usage();
72         string = argv[optind++];
73
74         if (dm_init_service(&name) == -1)  {
75                 fprintf(stderr, "Can't initialize the DMAPI\n");
76                 exit(1);
77         }
78         if (sid == DM_NO_SESSION)
79                 find_test_session(&sid);
80
81         if (dm_create_userevent(sid, strlen(string)+ 1, string, &token)) {
82                 fprintf(stderr, "dm_create_userevent failed, %s\n",
83                         strerror(errno));
84                 exit(1);
85         }
86
87         fprintf(stdout, "New token %d\n", token);
88         exit(0);
89 }