| 183 | } |
| 184 | |
| 185 | static int read_delay_line(char *buf, int *flags_p) |
| 186 | { |
| 187 | static int read_pos = 0; |
| 188 | unsigned int mode; |
| 189 | int j, len; |
| 190 | char *bp, *past_space; |
| 191 | |
| 192 | while (1) { |
| 193 | for (j = read_pos; j < deldelay_cnt && deldelay_buf[j]; j++) {} |
| 194 | if (j < deldelay_cnt) |
| 195 | break; |
| 196 | if (deldelay_fd < 0) { |
| 197 | if (j > read_pos) |
| 198 | goto invalid_data; |
| 199 | return -1; |
| 200 | } |
| 201 | deldelay_cnt -= read_pos; |
| 202 | if (deldelay_cnt == deldelay_size) |
| 203 | goto invalid_data; |
| 204 | if (deldelay_cnt && read_pos) { |
| 205 | memmove(deldelay_buf, deldelay_buf + read_pos, |
| 206 | deldelay_cnt); |
| 207 | } |
| 208 | len = read(deldelay_fd, deldelay_buf + deldelay_cnt, |
| 209 | deldelay_size - deldelay_cnt); |
| 210 | if (len == 0) { |
| 211 | if (deldelay_cnt) { |
| 212 | rprintf(FERROR, "ERROR: unexpected EOF in delete-delay file.\n"); |
| 213 | } |
| 214 | return -1; |
| 215 | } |
| 216 | if (len < 0) { |
| 217 | rsyserr(FERROR, errno, |
| 218 | "reading delete-delay file"); |
| 219 | return -1; |
| 220 | } |
| 221 | deldelay_cnt += len; |
| 222 | read_pos = 0; |
| 223 | } |
| 224 | |
| 225 | bp = deldelay_buf + read_pos; |
| 226 | if (*bp == '!') { |
| 227 | bp++; |
| 228 | *flags_p = DEL_NO_UID_WRITE; |
| 229 | } else |
| 230 | *flags_p = 0; |
| 231 | |
| 232 | if (sscanf(bp, "%x ", &mode) != 1) { |
| 233 | goto invalid_data; |
| 234 | } |
| 235 | past_space = strchr(bp, ' '); |
| 236 | if (!past_space) { |
| 237 | goto invalid_data; |
| 238 | } |
| 239 | past_space++; |
| 240 | len = j - read_pos - (past_space - bp) + 1; /* count the '\0' */ |
| 241 | read_pos = j + 1; |
| 242 |
no test coverage detected