From: rubric Date: Mon, 6 Mar 2017 05:11:14 +0000 (+0900) Subject: Replaced indicator lock's lockf with fnctl X-Git-Tag: dali_1.2.30~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=655b95a82d2e15ec7b0ce111fe5c7ec1cc93916b 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 f344e25..568890b 100644 --- a/adaptors/ecore/common/ecore-indicator-impl.cpp +++ b/adaptors/ecore/common/ecore-indicator-impl.cpp @@ -475,21 +475,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; } @@ -497,15 +503,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() ); } }