summaryrefslogtreecommitdiff
path: root/src/atcmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/atcmd.c')
-rw-r--r--src/atcmd.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/atcmd.c b/src/atcmd.c
index 55d2ebc..6dee9ed 100644
--- a/src/atcmd.c
+++ b/src/atcmd.c
@@ -267,6 +267,10 @@ int tty_set_read_timeout(int fd, int timeout)
int tty_close(int fd)
{
+ if (fd < 0) {
+ return -1;
+ }
+
tcflush(fd, TCIOFLUSH);
return close(fd);
}
@@ -1113,19 +1117,41 @@ static int sms_atcmd_init(int fd)
return 0;
}
+static char *lock_path;
+
+int sms_device_close(int fd)
+{
+ int ret;
+
+ ret = tty_close(fd);
+
+ if (lock_path) {
+ unlink(lock_path);
+ }
+
+ return ret;
+}
+
int sms_device_open(void)
{
int fd;
int tmp;
+ lock_path = device_lock(Global.core.device);
+ if (!lock_path) {
+ return -1;
+ }
+
fd = tty_open(Global.core.device, Global.core.baud_rate);
if (fd < 0) {
+ unlink(lock_path);
return -1;
}
tmp = tty_set_read_timeout(fd, Global.core.read_timeout);
if (tmp < 0) {
close(fd);
+ unlink(lock_path);
return tmp;
}
@@ -1133,6 +1159,7 @@ int sms_device_open(void)
tmp = sms_atcmd_init(fd);
if (tmp < 0) {
close(fd);
+ unlink(lock_path);
return tmp;
}
}