Commit 4e308e6b authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Add file-locking for serial2002

parent a813c679
......@@ -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;
}
......
......@@ -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;
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment