xref: /illumos-gate/usr/src/test/os-tests/tests/uccid/pollin.c (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
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  * Open up a device and make sure we get pollout by default.
18  */
19 
20 #include <err.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <strings.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <poll.h>
29 
30 #include <sys/usb/clients/ccid/uccid.h>
31 
32 int
33 main(int argc, char *argv[])
34 {
35 	int fd, ret;
36 	struct pollfd pfds[1];
37 	uccid_cmd_txn_begin_t begin;
38 
39 	if (argc != 2) {
40 		errx(EXIT_FAILURE, "missing required ccid path");
41 	}
42 
43 	if ((fd = open(argv[1], O_RDWR)) < 0) {
44 		err(EXIT_FAILURE, "failed to open %s", argv[1]);
45 	}
46 
47 	bzero(&begin, sizeof (begin));
48 	begin.uct_version = UCCID_CURRENT_VERSION;
49 	if (ioctl(fd, UCCID_CMD_TXN_BEGIN, &begin) != 0) {
50 		err(EXIT_FAILURE, "failed to issue begin ioctl");
51 	}
52 
53 	pfds[0].fd = fd;
54 	pfds[0].events = POLLIN;
55 	pfds[0].revents = 0;
56 
57 	ret = poll(pfds, 1, 0);
58 	if (ret != 0) {
59 		err(EXIT_FAILURE, "poll didn't return 0, returned %d "
60 		    "(errno %d)", ret, errno);
61 	}
62 
63 	return (0);
64 }
65