mirror of https://github.com/sfeakes/AqualinkD.git
serial_logger: drop pointless check for root
Requiring a program to run as root is a big hammer to an otherwise delicate situation, and is sure to get a UNIX engineer's blood boiling with instant rapidity. For the case of serial_logger, permissions are required for opening the serial port block device. When those permissions are not present, the program exits gracefully: $ sudo -u nobody ./release/serial_logger /dev/ttyUSB0 AqualinkD serial_logger V2.7 Error: RS Serial: Unable to open port: /dev/ttyUSB0, error 13 Error: Serial Log:Unable to open port: /dev/ttyUSB0 Permission denied: /dev/ttyUSB0 However, the program can be run successfully without root. In most distros, this is achieved with the **dialout** group. As long as the user is a member of **dialout**, things will run as expected: $ ls -l /dev/ttyUSB0 crw-rw----+ 1 root **dialout** 188, 0 Jan 2 13:04 /dev/ttyUSB0 $ groups mrnuke wheel **dialout** lock $ ./release/serial_logger /dev/ttyUSB0 -d AqualinkD serial_logger V2.7 Debug: RS Serial: Openeded serial port /dev/ttyUSB0 Notice: RS Serial: Port /dev/ttyUSB0 low latency mode is set Info: RS Serial: Port /dev/ttyUSB0 set I/O blocking attributes Remove the pointless root check. For users that already run as root, nothing changes. Users that prefer to use granular more permissions can now run without requiring root.pull/375/head
parent
65b845743d
commit
c2067be46e
|
@ -514,11 +514,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
printf("AqualinkD %s\n",VERSION);
|
||||
|
||||
if (getuid() != 0) {
|
||||
fprintf(stderr, "ERROR %s Can only be run as root\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc < 2 || access( argv[1], F_OK ) == -1 ) {
|
||||
fprintf(stderr, "ERROR, first param must be valid serial port, ie:-\n\t%s /dev/ttyUSB0\n\n", argv[0]);
|
||||
//fprintf(stderr, "Optional parameters are -d (debug) & -p <number> (log # packets) & -i <ID> & -r (raw) ie:=\n\t%s /dev/ttyUSB0 -d -p 1000 -i 0x08\n\n", argv[0]);
|
||||
|
|
Loading…
Reference in New Issue