| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) | - |
| 18 | { | - |
| 19 | if (key.isEmpty()){ | - |
| 20 | errorString = QCoreApplication::tr("%1: key is empty", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:")); | - |
| 21 | error = QSystemSemaphore::KeyError; | - |
| 22 | return -1; | - |
| 23 | } | - |
| 24 | | - |
| 25 | | - |
| 26 | if (-1 != unix_key) | - |
| 27 | return unix_key; | - |
| 28 | | - |
| 29 | | - |
| 30 | int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); | - |
| 31 | if (-1 == built) { | - |
| 32 | errorString = QCoreApplication::tr("%1: unable to make key", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:")); | - |
| 33 | error = QSystemSemaphore::KeyError; | - |
| 34 | return -1; | - |
| 35 | } | - |
| 36 | createdFile = (1 == built); | - |
| 37 | | - |
| 38 | | - |
| 39 | unix_key = qt_safe_ftok(QFile::encodeName(fileName), 'Q'); | - |
| 40 | if (-1 == unix_key) { | - |
| 41 | errorString = QCoreApplication::tr("%1: ftok failed", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:")); | - |
| 42 | error = QSystemSemaphore::KeyError; | - |
| 43 | return -1; | - |
| 44 | } | - |
| 45 | | - |
| 46 | | - |
| 47 | semaphore = semget(unix_key, 1, 0600 | 01000 | 02000); | - |
| 48 | if (-1 == semaphore) { | - |
| 49 | if ((*__errno_location ()) == 17) | - |
| 50 | semaphore = semget(unix_key, 1, 0600 | 01000); | - |
| 51 | if (-1 == semaphore) { | - |
| 52 | setErrorString(QLatin1String("QSystemSemaphore::handle")); | - |
| 53 | cleanHandle(); | - |
| 54 | return -1; | - |
| 55 | } | - |
| 56 | } else { | - |
| 57 | createdSemaphore = true; | - |
| 58 | | - |
| 59 | createdFile = true; | - |
| 60 | } | - |
| 61 | | - |
| 62 | if (mode == QSystemSemaphore::Create) { | - |
| 63 | createdSemaphore = true; | - |
| 64 | createdFile = true; | - |
| 65 | } | - |
| 66 | | - |
| 67 | | - |
| 68 | if (createdSemaphore && initialValue >= 0) { | - |
| 69 | qt_semun init_op; | - |
| 70 | init_op.val = initialValue; | - |
| 71 | if (-1 == semctl(semaphore, 0, 16, init_op)) { | - |
| 72 | setErrorString(QLatin1String("QSystemSemaphore::handle")); | - |
| 73 | cleanHandle(); | - |
| 74 | return -1; | - |
| 75 | } | - |
| 76 | } | - |
| 77 | | - |
| 78 | return unix_key; | - |
| 79 | } | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | | - |
| 85 | | - |
| 86 | void QSystemSemaphorePrivate::cleanHandle() | - |
| 87 | { | - |
| 88 | unix_key = -1; | - |
| 89 | | - |
| 90 | | - |
| 91 | if (createdFile| TRUE | evaluated 3522 times by 2 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
| | FALSE | evaluated 3937 times by 5 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
- tst_qapplication - unknown status
- tst_qsharedmemory - unknown status
- tst_qsystemsemaphore - unknown status
|
) { | 3522-3937 |
| 92 | QFile::remove(fileName); | - |
| 93 | createdFile = false; | - |
| 94 | }executed 3522 times by 2 tests: end of blockExecuted by:- tst_QSharedMemory
- tst_QSystemSemaphore
| 3522 |
| 95 | | - |
| 96 | if (createdSemaphore| TRUE | evaluated 3520 times by 2 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
| | FALSE | evaluated 3939 times by 5 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
- tst_qapplication - unknown status
- tst_qsharedmemory - unknown status
- tst_qsystemsemaphore - unknown status
|
) { | 3520-3939 |
| 97 | if (-| TRUE | evaluated 3519 times by 2 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
| | FALSE | evaluated 1 time by 1 test |
1 != semaphore| TRUE | evaluated 3519 times by 2 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
| | FALSE | evaluated 1 time by 1 test |
) { | 1-3519 |
| 98 | if (-| TRUE | never evaluated | | FALSE | evaluated 3519 times by 2 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
|
1 == semctl(semaphore, 0, 0, 0)| TRUE | never evaluated | | FALSE | evaluated 3519 times by 2 testsEvaluated by:- tst_QSharedMemory
- tst_QSystemSemaphore
|
) { | 0-3519 |
| 99 | setErrorString(QLatin1String("QSystemSemaphore::cleanHandle")); | - |
| 100 | | - |
| 101 | | - |
| 102 | | - |
| 103 | } never executed: end of block | 0 |
| 104 | semaphore = -1; | - |
| 105 | }executed 3519 times by 2 tests: end of blockExecuted by:- tst_QSharedMemory
- tst_QSystemSemaphore
| 3519 |
| 106 | createdSemaphore = false; | - |
| 107 | }executed 3520 times by 2 tests: end of blockExecuted by:- tst_QSharedMemory
- tst_QSystemSemaphore
| 3520 |
| 108 | }executed 7459 times by 5 tests: end of blockExecuted by:- tst_QSharedMemory
- tst_QSystemSemaphore
- tst_qapplication - unknown status
- tst_qsharedmemory - unknown status
- tst_qsystemsemaphore - unknown status
| 7459 |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | bool QSystemSemaphorePrivate::modifySemaphore(int count) | - |
| 114 | { | - |
| 115 | if (-1 == handle()) | - |
| 116 | return false; | - |
| 117 | | - |
| 118 | struct sembuf operation; | - |
| 119 | operation.sem_num = 0; | - |
| 120 | operation.sem_op = count; | - |
| 121 | operation.sem_flg = 0x1000; | - |
| 122 | | - |
| 123 | int res; | - |
| 124 | do { res = semop(semaphore, &operation, 1); } while (res == -1 && (*__errno_location ()) == 4); | - |
| 125 | if (-1 == res) { | - |
| 126 | | - |
| 127 | if ((*__errno_location ()) == 22 || (*__errno_location ()) == 43) { | - |
| 128 | semaphore = -1; | - |
| 129 | cleanHandle(); | - |
| 130 | handle(); | - |
| 131 | return modifySemaphore(count); | - |
| 132 | } | - |
| 133 | setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore")); | - |
| 134 | | - |
| 135 | | - |
| 136 | | - |
| 137 | return false; | - |
| 138 | } | - |
| 139 | | - |
| 140 | clearError(); | - |
| 141 | return true; | - |
| 142 | } | - |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| | |