Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mattias Fält
moberg
Commits
4e308e6b
Commit
4e308e6b
authored
May 10, 2021
by
Anders Blomdell
Browse files
Add file-locking for serial2002
parent
a813c679
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugins/serial2002/serial2002.c
View file @
4e308e6b
...
...
@@ -451,6 +451,7 @@ static struct moberg_status device_open(struct moberg_device_context *device)
if
(
device
->
port
.
count
==
0
)
{
fd
=
open
(
device
->
port
.
name
,
O_RDWR
);
if
(
fd
<
0
)
{
goto
err_errno
;
}
if
(
lockf
(
fd
,
F_TLOCK
,
0
))
{
goto
err_errno
;
}
struct
termios2
termios2
;
if
(
ioctl
(
fd
,
TCGETS2
,
&
termios2
)
<
0
)
{
goto
err_errno
;
}
termios2
.
c_iflag
=
0
;
...
...
@@ -492,6 +493,7 @@ err_errno:
result
=
MOBERG_ERRNO
(
errno
);
err_result:
if
(
fd
>=
0
)
{
lockf
(
fd
,
F_ULOCK
,
0
);
close
(
fd
);
}
return
result
;
...
...
@@ -502,6 +504,7 @@ static struct moberg_status device_close(struct moberg_device_context *device)
if
(
device
->
port
.
count
<
0
)
{
errno
=
ENODEV
;
goto
err_errno
;
}
device
->
port
.
count
--
;
if
(
device
->
port
.
count
==
0
)
{
lockf
(
device
->
port
.
io
.
fd
,
F_ULOCK
,
0
);
if
(
close
(
device
->
port
.
io
.
fd
)
<
0
)
{
goto
err_errno
;
}
}
return
MOBERG_OK
;
...
...
@@ -531,6 +534,9 @@ static int channel_down(struct moberg_channel *channel)
static
struct
moberg_status
channel_open
(
struct
moberg_channel
*
channel
)
{
struct
moberg_status
result
=
device_open
(
channel
->
context
->
device
);
if
(
!
OK
(
result
))
{
goto
return_result
;
}
int
count
=
0
;
switch
(
channel
->
kind
)
{
case
chan_ANALOGIN
:
...
...
@@ -553,6 +559,7 @@ static struct moberg_status channel_open(struct moberg_channel *channel)
device_close
(
channel
->
context
->
device
);
result
=
MOBERG_ERRNO
(
ENODEV
);
}
return_result:
return
result
;
}
...
...
plugins/serial2002/serial2002_lib.c
View file @
4e308e6b
...
...
@@ -287,7 +287,10 @@ static void discard_pending(struct serial2002_io *io)
break
;
}
else
{
char
discard
;
read
(
io
->
fd
,
&
discard
,
1
);
err
=
read
(
io
->
fd
,
&
discard
,
1
);
if
(
err
<=
0
)
{
break
;
}
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment