lock: Use wide char types for lock functions.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Klaas Freitag 2013-07-10 15:59:17 +02:00 committed by Andreas Schneider
parent 70495d3ede
commit 9f9209bba0

View file

@ -126,12 +126,21 @@ static pid_t _csync_lock_read(const char *lockfile) {
ssize_t rc; ssize_t rc;
int fd; int fd;
pid_t pid; pid_t pid;
mbchar_t *wlockfile;
/* Read PID from existing lock */ /* Read PID from existing lock */
#ifdef _WIN32 #ifdef _WIN32
_fmode = _O_BINARY; _fmode = _O_BINARY;
#endif #endif
if ((fd = open(lockfile, O_RDONLY)) < 0) {
wlockfile = c_utf8_to_locale(lockfile);
if (wlockfile == NULL) {
return -1;
}
fd = _topen(wlockfile, O_RDONLY);
c_free_locale_string(wlockfile);
if (fd < 0) {
return -1; return -1;
} }
@ -160,13 +169,16 @@ static pid_t _csync_lock_read(const char *lockfile) {
/* Check if process is still alive */ /* Check if process is still alive */
if (kill(pid, 0) < 0 && errno == ESRCH) { if (kill(pid, 0) < 0 && errno == ESRCH) {
/* Process is dead. Remove stale lock. */ /* Process is dead. Remove stale lock. */
if (unlink(lockfile) < 0) { wlockfile = c_utf8_to_locale(lockfile);
if (_tunlink(wlockfile) < 0) {
strerror_r(errno, errbuf, sizeof(errbuf)); strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"Unable to remove stale lock %s - %s", "Unable to remove stale lock %s - %s",
lockfile, lockfile,
errbuf); errbuf);
} }
c_free_locale_string(wlockfile);
return -1; return -1;
} }
@ -187,16 +199,21 @@ int csync_lock(const char *lockfile) {
void csync_lock_remove(const char *lockfile) { void csync_lock_remove(const char *lockfile) {
char errbuf[256] = {0}; char errbuf[256] = {0};
mbchar_t *wlockfile;
/* You can't remove the lock if it is from another process */ /* You can't remove the lock if it is from another process */
if (_csync_lock_read(lockfile) == getpid()) { if (_csync_lock_read(lockfile) == getpid()) {
wlockfile = c_utf8_to_locale(lockfile);
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Removing lock file: %s", lockfile); CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Removing lock file: %s", lockfile);
if (unlink(lockfile) < 0) { if (_tunlink(wlockfile) < 0) {
strerror_r(errno, errbuf, sizeof(errbuf)); strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"Unable to remove lock %s - %s", "Unable to remove lock %s - %s",
lockfile, lockfile,
errbuf); errbuf);
} }
c_free_locale_string(wlockfile);
} }
} }