version 1.4, 2019/06/27 18:03:37 |
version 1.5, 2019/06/28 13:35:04 |
|
|
ret = SSH_ERR_ALLOC_FAIL; |
ret = SSH_ERR_ALLOC_FAIL; |
goto done; |
goto done; |
} |
} |
if ((lockfd = open(lockfile, O_CREAT|O_RDONLY, 0600)) < 0) { |
if ((lockfd = open(lockfile, O_CREAT|O_RDONLY, 0600)) == -1) { |
ret = SSH_ERR_SYSTEM_ERROR; |
ret = SSH_ERR_SYSTEM_ERROR; |
PRINT("%s: cannot open/create: %s", __func__, lockfile); |
PRINT("%s: cannot open/create: %s", __func__, lockfile); |
goto done; |
goto done; |
} |
} |
while (flock(lockfd, LOCK_EX|LOCK_NB) < 0) { |
while (flock(lockfd, LOCK_EX|LOCK_NB) == -1) { |
if (errno != EWOULDBLOCK) { |
if (errno != EWOULDBLOCK) { |
ret = SSH_ERR_SYSTEM_ERROR; |
ret = SSH_ERR_SYSTEM_ERROR; |
PRINT("%s: cannot lock: %s", __func__, lockfile); |
PRINT("%s: cannot lock: %s", __func__, lockfile); |
|
|
PRINT("%s: ENCRYPT FAILED: %d", __func__, ret); |
PRINT("%s: ENCRYPT FAILED: %d", __func__, ret); |
goto done; |
goto done; |
} |
} |
if ((fd = open(nstatefile, O_CREAT|O_WRONLY|O_EXCL, 0600)) < 0) { |
if ((fd = open(nstatefile, O_CREAT|O_WRONLY|O_EXCL, 0600)) == -1) { |
ret = SSH_ERR_SYSTEM_ERROR; |
ret = SSH_ERR_SYSTEM_ERROR; |
PRINT("%s: open new state file: %s", __func__, nstatefile); |
PRINT("%s: open new state file: %s", __func__, nstatefile); |
goto done; |
goto done; |
|
|
close(fd); |
close(fd); |
goto done; |
goto done; |
} |
} |
if (fsync(fd) < 0) { |
if (fsync(fd) == -1) { |
ret = SSH_ERR_SYSTEM_ERROR; |
ret = SSH_ERR_SYSTEM_ERROR; |
PRINT("%s: sync new state file: %s", __func__, nstatefile); |
PRINT("%s: sync new state file: %s", __func__, nstatefile); |
close(fd); |
close(fd); |
goto done; |
goto done; |
} |
} |
if (close(fd) < 0) { |
if (close(fd) == -1) { |
ret = SSH_ERR_SYSTEM_ERROR; |
ret = SSH_ERR_SYSTEM_ERROR; |
PRINT("%s: close new state file: %s", __func__, nstatefile); |
PRINT("%s: close new state file: %s", __func__, nstatefile); |
goto done; |
goto done; |
|
|
goto done; |
goto done; |
} |
} |
} |
} |
if (rename(nstatefile, statefile) < 0) { |
if (rename(nstatefile, statefile) == -1) { |
ret = SSH_ERR_SYSTEM_ERROR; |
ret = SSH_ERR_SYSTEM_ERROR; |
PRINT("%s: rename %s to %s", __func__, nstatefile, statefile); |
PRINT("%s: rename %s to %s", __func__, nstatefile, statefile); |
goto done; |
goto done; |