xref: /illumos-gate/usr/src/test/os-tests/tests/uccid/notxn-poll.c (revision 7b34a9a5df26271af0da06974fc361c468cd48d3)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019, Joyent, Inc.
14  */
15 
16 /*
17  * Verify that trying to poll without a transaction / excl access fails
18  * with EACCES.
19  */
20 
21 #include <err.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/debug.h>
26 #include <fcntl.h>
27 #include <strings.h>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <poll.h>
31 
32 #include <sys/usb/clients/ccid/uccid.h>
33 
34 int
35 main(int argc, char *argv[])
36 {
37 	int fd, ret;
38 	struct pollfd pfds[1];
39 
40 	if (argc != 2) {
41 		errx(EXIT_FAILURE, "missing required ccid path");
42 	}
43 
44 	if ((fd = open(argv[1], O_RDWR)) < 0) {
45 		err(EXIT_FAILURE, "failed to open %s", argv[1]);
46 	}
47 
48 	pfds[0].fd = fd;
49 	pfds[0].events = POLLIN;
50 	pfds[0].revents = 0;
51 
52 	ret = poll(pfds, 1, 0);
53 	VERIFY3S(ret, ==, -1);
54 	VERIFY3S(errno, ==, EACCES);
55 
56 	return (0);
57 }
58