summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Hatch <jhatch@multitech.com>2016-06-23 12:31:51 -0500
committerJeff Hatch <jhatch@multitech.com>2016-06-23 12:31:51 -0500
commit41abe2c0e76ede64a043f710f217caaca16763b6 (patch)
tree11cff542b8c4b5fbbbb910d87236e283f7c3381d /src
parentb707562b962d5bed4034f47e02f8c5e64de8fbd1 (diff)
downloadsms-utils-41abe2c0e76ede64a043f710f217caaca16763b6.tar.gz
sms-utils-41abe2c0e76ede64a043f710f217caaca16763b6.tar.bz2
sms-utils-41abe2c0e76ede64a043f710f217caaca16763b6.zip
Add retry code for getting the lock on the modem tty, tries every 100ms for one second before giving up.1.0.1
Diffstat (limited to 'src')
-rw-r--r--src/utils.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/utils.c b/src/utils.c
index 8e7bed7..b93634c 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -246,6 +246,8 @@ char *shell_path_expand(const char *path)
return strdup(line);
}
+#define MAX_TRY 10
+
char *device_lock(const char *path)
{
int tmp;
@@ -253,6 +255,7 @@ char *device_lock(const char *path)
int fd;
char str[32];
char *lock;
+ unsigned char num_try=0;
tmp = asprintf(&lock, "/var/lock/LCK..%s", name);
if (tmp < 0) {
@@ -260,12 +263,21 @@ char *device_lock(const char *path)
return NULL;
}
- fd = open(lock, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644);
- if (fd < 0) {
- log_error("failed to create %s: %m", lock);
- free(lock);
- return NULL;
- }
+ do{
+ fd = open(lock, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644);
+ if (fd > 0) {
+ break;
+ }else{
+ log_error("%i number of trying to create %s: %m",num_try+1,lock);
+ };
+ if(num_try++>=MAX_TRY){
+ //something locks device too long
+ log_error("failed to create %s: %m", lock);
+ free(lock);
+ return NULL;
+ }
+ usleep(100000ul);//100ms
+ }while(1);
snprintf(str, sizeof(str), "%10d\n", getpid());