| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qsharedmemory_systemv.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | - | |||||||||||||
| 12 | - | |||||||||||||
| 13 | key_t QSharedMemoryPrivate::handle() | - | ||||||||||||
| 14 | { | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | if (unix_key
| 0-3537 | ||||||||||||
| 17 | return never executed: unix_key;return unix_key;never executed: return unix_key; | 0 | ||||||||||||
| 18 | - | |||||||||||||
| 19 | - | |||||||||||||
| 20 | if (nativeKey.isEmpty()
| 1-3536 | ||||||||||||
| 21 | errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle:")); | - | ||||||||||||
| 22 | error = QSharedMemory::KeyError; | - | ||||||||||||
| 23 | return executed 1 time by 1 test: 0;return 0;Executed by:
executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||
| 24 | } | - | ||||||||||||
| 25 | - | |||||||||||||
| 26 | - | |||||||||||||
| 27 | if (!QFile::exists(nativeKey)
| 2-3534 | ||||||||||||
| 28 | errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg(QLatin1String("QSharedMemory::handle:")); | - | ||||||||||||
| 29 | error = QSharedMemory::NotFound; | - | ||||||||||||
| 30 | return executed 2 times by 1 test: 0;return 0;Executed by:
executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||||||||
| 31 | } | - | ||||||||||||
| 32 | - | |||||||||||||
| 33 | unix_key = qt_safe_ftok(QFile::encodeName(nativeKey), 'Q'); | - | ||||||||||||
| 34 | if (-
| 0-3534 | ||||||||||||
| 35 | errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:")); | - | ||||||||||||
| 36 | error = QSharedMemory::KeyError; | - | ||||||||||||
| 37 | unix_key = 0; | - | ||||||||||||
| 38 | } never executed: end of block | 0 | ||||||||||||
| 39 | return executed 3534 times by 2 tests: unix_key;return unix_key;Executed by:
executed 3534 times by 2 tests: return unix_key;Executed by:
| 3534 | ||||||||||||
| 40 | } | - | ||||||||||||
| 41 | int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName) | - | ||||||||||||
| 42 | { | - | ||||||||||||
| 43 | int fd = qt_safe_open(QFile::encodeName(fileName).constData(), | - | ||||||||||||
| 44 | 0200 | 0100 | 02, 0640); | - | ||||||||||||
| 45 | if (-
| 3666-6986 | ||||||||||||
| 46 | if ((*
| 53-3613 | ||||||||||||
| 47 | return executed 3613 times by 3 tests: 0;return 0;Executed by:
executed 3613 times by 3 tests: return 0;Executed by:
| 3613 | ||||||||||||
| 48 | return executed 53 times by 1 test: -1;return -1;Executed by:
executed 53 times by 1 test: return -1;Executed by:
| 53 | ||||||||||||
| 49 | } else { | - | ||||||||||||
| 50 | close(fd); | - | ||||||||||||
| 51 | } executed 6986 times by 3 tests: end of blockExecuted by:
| 6986 | ||||||||||||
| 52 | return executed 6986 times by 3 tests: 1;return 1;Executed by:
executed 6986 times by 3 tests: return 1;Executed by:
| 6986 | ||||||||||||
| 53 | } | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | - | |||||||||||||
| 56 | - | |||||||||||||
| 57 | - | |||||||||||||
| 58 | bool QSharedMemoryPrivate::cleanHandle() | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | unix_key = 0; | - | ||||||||||||
| 61 | return executed 14289 times by 2 tests: true;return true;Executed by:
executed 14289 times by 2 tests: return true;Executed by:
| 14289 | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | bool QSharedMemoryPrivate::create(int size) | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | bool createdFile = false; | - | ||||||||||||
| 68 | int built = createUnixKeyFile(nativeKey); | - | ||||||||||||
| 69 | if (built == -1
| 53-3467 | ||||||||||||
| 70 | errorString = QSharedMemory::tr("%1: unable to make key").arg(QLatin1String("QSharedMemory::handle:")); | - | ||||||||||||
| 71 | error = QSharedMemory::KeyError; | - | ||||||||||||
| 72 | return executed 53 times by 1 test: false;return false;Executed by:
executed 53 times by 1 test: return false;Executed by:
| 53 | ||||||||||||
| 73 | } | - | ||||||||||||
| 74 | if (built == 1
| 2-3465 | ||||||||||||
| 75 | createdFile = true; | - | ||||||||||||
| 76 | } executed 3465 times by 2 tests: end of blockExecuted by:
| 3465 | ||||||||||||
| 77 | - | |||||||||||||
| 78 | - | |||||||||||||
| 79 | if (!handle()
| 0-3467 | ||||||||||||
| 80 | if (createdFile
| 0 | ||||||||||||
| 81 | QFile::remove(nativeKey); never executed: QFile::remove(nativeKey); | 0 | ||||||||||||
| 82 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | - | |||||||||||||
| 86 | if (-
| 2-3465 | ||||||||||||
| 87 | const QLatin1String function("QSharedMemory::create"); | - | ||||||||||||
| 88 | switch ((*__errno_location ())) { | - | ||||||||||||
| 89 | case never executed: 22:case 22:never executed: case 22: | 0 | ||||||||||||
| 90 | errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle")); | - | ||||||||||||
| 91 | error = QSharedMemory::InvalidSize; | - | ||||||||||||
| 92 | break; never executed: break; | 0 | ||||||||||||
| 93 | default executed 2 times by 1 test: :default:Executed by:
executed 2 times by 1 test: default:Executed by:
| 2 | ||||||||||||
| 94 | setErrorString(function); | - | ||||||||||||
| 95 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 96 | if (createdFile
| 0-2 | ||||||||||||
| 97 | QFile::remove(nativeKey); never executed: QFile::remove(nativeKey); | 0 | ||||||||||||
| 98 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | return executed 3465 times by 2 tests: true;return true;Executed by:
executed 3465 times by 2 tests: return true;Executed by:
| 3465 | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600)); | - | ||||||||||||
| 108 | if (-
| 0-3532 | ||||||||||||
| 109 | setErrorString(QLatin1String("QSharedMemory::attach (shmget)")); | - | ||||||||||||
| 110 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 111 | } | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | - | |||||||||||||
| 114 | memory = shmat(id, 0, (mode == QSharedMemory::ReadOnly ? 010000 : 0)); | - | ||||||||||||
| 115 | if ((
| 0-3532 | ||||||||||||
| 116 | memory = 0; | - | ||||||||||||
| 117 | setErrorString(QLatin1String("QSharedMemory::attach (shmat)")); | - | ||||||||||||
| 118 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | - | |||||||||||||
| 122 | shmid_ds shmid_ds; | - | ||||||||||||
| 123 | if (!shmctl(id, 2, &shmid_ds)
| 0-3532 | ||||||||||||
| 124 | size = (int)shmid_ds.shm_segsz; | - | ||||||||||||
| 125 | } executed 3532 times by 2 tests: else {end of blockExecuted by:
| 3532 | ||||||||||||
| 126 | setErrorString(QLatin1String("QSharedMemory::attach (shmctl)")); | - | ||||||||||||
| 127 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | return executed 3532 times by 2 tests: true;return true;Executed by:
executed 3532 times by 2 tests: return true;Executed by:
| 3532 | ||||||||||||
| 131 | } | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | bool QSharedMemoryPrivate::detach() | - | ||||||||||||
| 134 | { | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | if (-
| 0-3531 | ||||||||||||
| 137 | const QLatin1String function("QSharedMemory::detach"); | - | ||||||||||||
| 138 | switch ((*__errno_location ())) { | - | ||||||||||||
| 139 | case never executed: 22:case 22:never executed: case 22: | 0 | ||||||||||||
| 140 | errorString = QSharedMemory::tr("%1: not attached").arg(function); | - | ||||||||||||
| 141 | error = QSharedMemory::NotFound; | - | ||||||||||||
| 142 | break; never executed: break; | 0 | ||||||||||||
| 143 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 144 | setErrorString(function); | - | ||||||||||||
| 145 | } never executed: end of block | 0 | ||||||||||||
| 146 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | memory = 0; | - | ||||||||||||
| 149 | size = 0; | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | - | |||||||||||||
| 152 | int id = shmget(unix_key, 0, 0400); | - | ||||||||||||
| 153 | cleanHandle(); | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | struct shmid_ds shmid_ds; | - | ||||||||||||
| 156 | if (0 != shmctl(id, 2, &shmid_ds)
| 0-3531 | ||||||||||||
| 157 | switch ((*__errno_location ())) { | - | ||||||||||||
| 158 | case never executed: 22:case 22:never executed: case 22: | 0 | ||||||||||||
| 159 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 160 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 161 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | } | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | if (shmid_ds.shm_nattch == 0
| 66-3465 | ||||||||||||
| 166 | - | |||||||||||||
| 167 | if (-
| 0-3465 | ||||||||||||
| 168 | setErrorString(QLatin1String("QSharedMemory::remove")); | - | ||||||||||||
| 169 | switch ((*__errno_location ())) { | - | ||||||||||||
| 170 | case never executed: 22:case 22:never executed: case 22: | 0 | ||||||||||||
| 171 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 172 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 173 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | } | - | ||||||||||||
| 176 | - | |||||||||||||
| 177 | - | |||||||||||||
| 178 | if (!QFile::remove(nativeKey)
| 0-3465 | ||||||||||||
| 179 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 180 | } executed 3465 times by 1 test: end of blockExecuted by:
| 3465 | ||||||||||||
| 181 | return executed 3531 times by 1 test: true;return true;Executed by:
executed 3531 times by 1 test: return true;Executed by:
| 3531 | ||||||||||||
| 182 | } | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | - | |||||||||||||
| 185 | - | |||||||||||||
| Switch to Source code | Preprocessed file |