Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void _set_processing_status(const char* status)
- {
- if ( ! proc_status_file )
- return;
- // This function can be called from a signal context, so we have to
- // make sure to only call reentrant functions and to restore errno
- // afterwards.
- int old_errno = errno;
- int fd = open(proc_status_file, O_CREAT | O_WRONLY | O_TRUNC, 0700);
- if ( fd < 0 )
- {
- char buf[256];
- bro_strerror_r(errno, buf, sizeof(buf));
- string open_err = "Failed to open process status file '";
- open_err += proc_status_file;
- open_err += "': ";
- open_err += buf;
- open_err += "\n";
- int fd_err_len = strlen(open_err.c_str());
- while ( fd_err_len )
- {
- int n = write(STDERR_FILENO, open_err.c_str(), fd_err_len);
- if ( n < 0 && errno != EINTR && errno != EAGAIN )
- break;
- open_err += n;
- fd_err_len -= n;
- }
- errno = old_errno;
- return;
- }
- int len = strlen(status);
- while ( len )
- {
- int n = write(fd, status, len);
- if ( n < 0 && errno != EINTR && errno != EAGAIN )
- // Ignore errors, as they're too difficult to
- // safely report here.
- break;
- status += n;
- len -= n;
- }
- if ( close(fd) < 0 && errno != EINTR )
- {
- char buf[128];
- bro_strerror_r(errno, buf, sizeof(buf));
- string close_err = "close() error ";
- close_err += errno;
- close_err += ": ";
- close_err += buf;
- close_err += "\n";
- int fd_cls_err_len = strlen(close_err.c_str());
- while ( fd_cls_err_len )
- {
- int n = write(STDERR_FILENO, close_err.c_str(), fd_cls_err_len);
- if ( n < 0 && errno != EINTR && errno != EAGAIN )
- break;
- close_err += n;
- fd_cls_err_len -= n;
- }
- abort();
- }
- errno = old_errno;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement