From: rubric Date: Mon, 6 Mar 2017 05:11:14 +0000 (+0900) Subject: [3.0] Replaced indicator lock's lockf with fnctl X-Git-Tag: accepted/tizen/3.0/common/20170323.155239~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F45%2F117445%2F1;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git [3.0] Replaced indicator lock's lockf with fnctl Change-Id: I232867e42e87b00a2a1658443f17267dd7bb2bfa --- diff --git a/adaptors/ecore/common/ecore-indicator-impl.cpp b/adaptors/ecore/common/ecore-indicator-impl.cpp index c9cefb4..30b6c00 100644 --- a/adaptors/ecore/common/ecore-indicator-impl.cpp +++ b/adaptors/ecore/common/ecore-indicator-impl.cpp @@ -419,21 +419,27 @@ bool Indicator::LockFile::Lock() bool locked = false; if( mFileDescriptor > 0 ) { - if( lockf( mFileDescriptor, F_LOCK, 0 ) == 0 ) // Note, operation may block. + struct flock filelock; + + filelock.l_type = F_RDLCK; + filelock.l_whence = SEEK_SET; + filelock.l_start = 0; + filelock.l_len = 0; + if( fcntl( mFileDescriptor, F_SETLKW, &filelock ) == -1 ) { - locked = true; + mErrorThrown = true; + DALI_LOG_ERROR( "### Failed to lock with fd : %s ###\n", mFilename.c_str() ); } else { - if( errno == EBADF ) - { - // file descriptor is no longer valid or not writable - mFileDescriptor = 0; - mErrorThrown = true; - DALI_LOG_ERROR( "### Cannot lock indicator: bad file descriptor for %s ###\n", mFilename.c_str() ); - } + locked = true; } } + else + { + mErrorThrown = true; + DALI_LOG_ERROR( "### Invalid fd ###\n" ); + } return locked; } @@ -441,15 +447,17 @@ bool Indicator::LockFile::Lock() void Indicator::LockFile::Unlock() { DALI_LOG_TRACE_METHOD( gIndicatorLogFilter ); - if( lockf( mFileDescriptor, F_ULOCK, 0 ) != 0 ) + + struct flock filelock; + + filelock.l_type = F_UNLCK; + filelock.l_whence = SEEK_SET; + filelock.l_start = 0; + filelock.l_len = 0; + if (fcntl(mFileDescriptor, F_SETLKW, &filelock) == -1) { - if( errno == EBADF ) - { - // file descriptor is no longer valid or not writable - mFileDescriptor = 0; - mErrorThrown = true; - DALI_LOG_ERROR( "### Cannot unlock indicator: bad file descriptor for %s\n", mFilename.c_str() ); - } + mErrorThrown = true; + DALI_LOG_ERROR( "### Failed to lock with fd : %s ###\n", mFilename.c_str() ); } } diff --git a/adaptors/tizen/ecore-indicator-impl-tizen.cpp b/adaptors/tizen/ecore-indicator-impl-tizen.cpp index fcce43f..52fef73 100644 --- a/adaptors/tizen/ecore-indicator-impl-tizen.cpp +++ b/adaptors/tizen/ecore-indicator-impl-tizen.cpp @@ -434,21 +434,27 @@ bool Indicator::LockFile::Lock() bool locked = false; if( mFileDescriptor > 0 ) { - if( lockf( mFileDescriptor, F_LOCK, 0 ) == 0 ) // Note, operation may block. + struct flock filelock; + + filelock.l_type = F_RDLCK; + filelock.l_whence = SEEK_SET; + filelock.l_start = 0; + filelock.l_len = 0; + if( fcntl( mFileDescriptor, F_SETLKW, &filelock ) == -1 ) { - locked = true; + mErrorThrown = true; + DALI_LOG_ERROR( "### Failed to lock with fd : %s ###\n", mFilename.c_str() ); } else { - if( errno == EBADF ) - { - // file descriptor is no longer valid or not writable - mFileDescriptor = 0; - mErrorThrown = true; - DALI_LOG_ERROR( "### Cannot lock indicator: bad file descriptor for %s ###\n", mFilename.c_str() ); - } + locked = true; } } + else + { + mErrorThrown = true; + DALI_LOG_ERROR( "### Invalid fd ###\n" ); + } return locked; } @@ -456,15 +462,17 @@ bool Indicator::LockFile::Lock() void Indicator::LockFile::Unlock() { DALI_LOG_TRACE_METHOD( gIndicatorLogFilter ); - if( lockf( mFileDescriptor, F_ULOCK, 0 ) != 0 ) + + struct flock filelock; + + filelock.l_type = F_UNLCK; + filelock.l_whence = SEEK_SET; + filelock.l_start = 0; + filelock.l_len = 0; + if (fcntl(mFileDescriptor, F_SETLKW, &filelock) == -1) { - if( errno == EBADF ) - { - // file descriptor is no longer valid or not writable - mFileDescriptor = 0; - mErrorThrown = true; - DALI_LOG_ERROR( "### Cannot unlock indicator: bad file descriptor for %s\n", mFilename.c_str() ); - } + mErrorThrown = true; + DALI_LOG_ERROR( "### Failed to lock with fd : %s ###\n", mFilename.c_str() ); } }