Add additional port locking for root users
This commit is contained in:
parent
11896f44cc
commit
051ba9f8fb
|
@ -2,10 +2,10 @@
|
|||
* PosixHelperFunctions.c
|
||||
*
|
||||
* Created on: Mar 10, 2015
|
||||
* Last Updated on: Dec 07, 2018
|
||||
* Last Updated on: Mar 07, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2018 Fazecast, Inc.
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
*
|
||||
* This file is part of jSerialComm.
|
||||
*
|
||||
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -613,6 +614,36 @@ void searchForComPorts(charTupleVector* comPorts)
|
|||
}
|
||||
}
|
||||
|
||||
int flock(int fd, int op)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
#if defined(F_SETLK) && defined(F_SETLKW)
|
||||
struct flock fl = {0};
|
||||
switch (op & (LOCK_EX|LOCK_SH|LOCK_UN))
|
||||
{
|
||||
case LOCK_EX:
|
||||
fl.l_type = F_WRLCK;
|
||||
break;
|
||||
case LOCK_SH:
|
||||
fl.l_type = F_RDLCK;
|
||||
break;
|
||||
case LOCK_UN:
|
||||
fl.l_type = F_UNLCK;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
fl.l_whence = SEEK_SET;
|
||||
rc = fcntl(fd, op & LOCK_NB ? F_SETLK : F_SETLKW, &fl);
|
||||
if (rc && (errno == EAGAIN))
|
||||
errno = EWOULDBLOCK;
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
baud_rate getBaudRateCode(baud_rate baudRate)
|
||||
{
|
||||
// Translate a raw baud rate into a system-specified one
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
* PosixHelperFunctions.h
|
||||
*
|
||||
* Created on: Mar 10, 2015
|
||||
* Last Updated on: Nov 12, 2018
|
||||
* Last Updated on: Mar 07, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2018 Fazecast, Inc.
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
*
|
||||
* This file is part of jSerialComm.
|
||||
*
|
||||
|
@ -53,8 +53,13 @@ void driverBasedSearchForComPorts(charTupleVector* comPorts);
|
|||
|
||||
// Solaris-specific functionality
|
||||
#elif defined(__sun__)
|
||||
#define LOCK_SH 1
|
||||
#define LOCK_EX 2
|
||||
#define LOCK_NB 4
|
||||
#define LOCK_UN 8
|
||||
typedef int baud_rate;
|
||||
extern int ioctl(int __fd, int __request, ...);
|
||||
int flock(int fd, int op);
|
||||
void searchForComPorts(charTupleVector* comPorts);
|
||||
|
||||
// Apple-specific functionality
|
||||
|
|
Loading…
Reference in New Issue