diff options
author | Maksym Telychko <maksym.telychko@globallogic.com> | 2020-03-30 15:04:21 +0300 |
---|---|---|
committer | Maksym Telychko <maksym.telychko@globallogic.com> | 2020-03-30 15:04:21 +0300 |
commit | d48fa68d6207b25061d5276021b1dd25ce5da89d (patch) | |
tree | cf6d684596ddeb198f221b9eaad69ca307e503f4 | |
parent | 7568024baa8e6a2488e307e38ade8e7b6a46720f (diff) | |
download | sms-utils-d48fa68d6207b25061d5276021b1dd25ce5da89d.tar.gz sms-utils-d48fa68d6207b25061d5276021b1dd25ce5da89d.tar.bz2 sms-utils-d48fa68d6207b25061d5276021b1dd25ce5da89d.zip |
MTX-3262 mpower lockfile: code style
-rw-r--r-- | src/atcmd.c | 2 | ||||
-rw-r--r-- | src/utils.c | 58 |
2 files changed, 30 insertions, 30 deletions
diff --git a/src/atcmd.c b/src/atcmd.c index e85758d..eab4210 100644 --- a/src/atcmd.c +++ b/src/atcmd.c @@ -1479,7 +1479,7 @@ int sms_device_close(int fd) ret = tty_close(fd); - lock_file = device_unlock(lock_file); + lock_file = device_unlock(lock_file); return ret; } diff --git a/src/utils.c b/src/utils.c index c48686b..e7d6b69 100644 --- a/src/utils.c +++ b/src/utils.c @@ -251,47 +251,47 @@ char *shell_path_expand(const char *path) struct Lock *device_lock(const char *path) { - struct Lock *result = (struct Lock*)calloc(1, sizeof(struct Lock)); - if (result == NULL) { - log_error("out of memory"); - return NULL; - } + struct Lock *result = (struct Lock*)calloc(1, sizeof(struct Lock)); + if (result == NULL) { + log_error("out of memory"); + return NULL; + } if (asprintf(&result->path, "/var/lock/LCK..%s", basename(path)) < 0) { - log_error("out of memory"); - return NULL; + log_error("out of memory"); + return NULL; } - result->fd = open(result->path, O_CREAT | O_RDWR, 0644); - if (result->fd >= 0) { - unsigned char num_try = 0; - while (1) { - int lockErr = flock(result->fd, LOCK_EX | LOCK_NB); - if (lockErr == 0) { - return result; - } else if (errno != EWOULDBLOCK) { - break; - } - if (num_try++>=MAX_TRY) { - //something locks device too long - break; - } - usleep(100000ul);//100ms - } - log_error("failed to create %s: %m", result->path); - device_unlock(result); - } + result->fd = open(result->path, O_CREAT | O_RDWR, 0644); + if (result->fd >= 0) { + unsigned char num_try = 0; + while (1) { + int lockErr = flock(result->fd, LOCK_EX | LOCK_NB); + if (lockErr == 0) { + return result; + } else if (errno != EWOULDBLOCK) { + break; + } + if (num_try++>=MAX_TRY) { + //something locks device too long + break; + } + usleep(100000ul);//100ms + } + log_error("failed to create %s: %m", result->path); + device_unlock(result); + } return NULL; } struct Lock *device_unlock(struct Lock *lock) { if (lock) { - close(lock->fd); + close(lock->fd); free(lock->path); - free(lock); + free(lock); } - return NULL; + return NULL; } int indexOfChar(const char *array, int len, char character) |