Skip to content

Commit f504ba5

Browse files
authored
Merge pull request #37 from wentasah/fixes2
Improve error reporting with device permission denied errors.
2 parents 7e4163e + 133eaa9 commit f504ba5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libusbrelay.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int enumerate_relay_boards(const char *product, int verbose, int debug)
4545
char *vendor;
4646
int result = 0;
4747
struct hid_device_info *devs, *cur_dev;
48+
int num_opened = 0, num_error = 0;
4849

4950
//If we were given a product code, use it
5051
if (product != NULL)
@@ -92,12 +93,14 @@ int enumerate_relay_boards(const char *product, int verbose, int debug)
9293
handle = hid_open_path(cur_dev->path);
9394
if (handle)
9495
{
96+
num_opened++;
9597
result = get_board_features(&relay_boards[i], handle);
9698
hid_close(handle);
9799
}
98100
else
99101
{
100-
perror("unable to open device - Use root, sudo or set the device permissions via udev\n");
102+
num_error++;
103+
perror(cur_dev->path);
101104
result = -1;
102105
}
103106

@@ -133,6 +136,8 @@ int enumerate_relay_boards(const char *product, int verbose, int debug)
133136
}
134137
}
135138
hid_free_enumeration(devs);
139+
if (num_opened == 0 && num_error > 0)
140+
fprintf(stderr, "Unable to open any device - Use root, sudo or set the device permissions via udev\n");
136141
return result;
137142
}
138143

0 commit comments

Comments
 (0)