| 384 | |
| 385 | |
| 386 | static inline int write_to_fifo(char *fifo, int cnt ) |
| 387 | { |
| 388 | int fd_fifo; |
| 389 | |
| 390 | /* open FIFO file stream */ |
| 391 | if((fd_fifo = open(fifo,O_WRONLY | O_NONBLOCK)) == -1){ |
| 392 | switch(errno){ |
| 393 | case ENXIO: |
| 394 | LM_ERR("nobody listening on [%s] fifo for reading!\n",fifo); |
| 395 | break; |
| 396 | default: |
| 397 | LM_ERR("failed to open [%s] fifo : %s\n", fifo, |
| 398 | strerror(errno)); |
| 399 | } |
| 400 | goto error; |
| 401 | } |
| 402 | |
| 403 | /* write now (unbuffered straight-down write) */ |
| 404 | repeat: |
| 405 | if (writev(fd_fifo, (struct iovec*)(void*)lines_eol, 2*cnt)<0) { |
| 406 | if (errno!=EINTR) { |
| 407 | LM_ERR("writev failed: %s\n", strerror(errno)); |
| 408 | close(fd_fifo); |
| 409 | goto error; |
| 410 | } else { |
| 411 | goto repeat; |
| 412 | } |
| 413 | } |
| 414 | close(fd_fifo); |
| 415 | |
| 416 | LM_DBG("write completed\n"); |
| 417 | return 1; /* OK */ |
| 418 | |
| 419 | error: |
| 420 | return -1; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | |