| 171 | } |
| 172 | |
| 173 | static void readpipe(int fd, int verify) |
| 174 | { |
| 175 | while (1) { |
| 176 | /* Use larger buffer on receiver as Linux will allow pipes buffers to |
| 177 | * exceed PIPE_BUF. We can't avoid tearing due to small read buffers from |
| 178 | * the Ceph side. |
| 179 | */ |
| 180 | |
| 181 | char buf[65536] = ""; |
| 182 | int rc = read(fd, buf, (sizeof buf) - 1); |
| 183 | if (rc == 0) { |
| 184 | _exit(0); |
| 185 | } else if (rc == -1) { |
| 186 | _exit(1); |
| 187 | } else if (rc > 0) { |
| 188 | if (verify) { |
| 189 | char* p = strrchr(buf, '\n'); |
| 190 | /* verify no torn writes */ |
| 191 | if (p == NULL) { |
| 192 | _exit(2); |
| 193 | } else if (p[1] != '\0') { |
| 194 | std::ignore = write(2, buf, strlen(buf)); |
| 195 | _exit(3); |
| 196 | } |
| 197 | } |
| 198 | } else _exit(100); |
| 199 | usleep(500); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | TEST(Log, StderrPipeAtomic) |
| 204 | { |