1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge pull request #1192 from profanity-im/issue1186

log: set nonblocking mode for stderr
This commit is contained in:
Michael Vetter 2019-09-13 13:54:12 +02:00 committed by GitHub
commit fd161d92ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -790,26 +790,36 @@ log_stderr_handler(void)
} }
} }
static int log_stderr_nonblock_set(int fd)
{
int rc;
rc = fcntl(fd, F_GETFL);
if (rc >= 0)
rc = fcntl(fd, F_SETFL, rc | O_NONBLOCK);
return rc;
}
void void
log_stderr_init(log_level_t level) log_stderr_init(log_level_t level)
{ {
int rc; int rc;
int flags;
rc = pipe(stderr_pipe); rc = pipe(stderr_pipe);
if (rc != 0) if (rc != 0)
goto err; goto err;
flags = fcntl(stderr_pipe[0], F_GETFL);
rc = fcntl(stderr_pipe[0], F_SETFL, flags | O_NONBLOCK);
if (rc != 0)
goto err_close;
close(STDERR_FILENO); close(STDERR_FILENO);
rc = dup2(stderr_pipe[1], STDERR_FILENO); rc = dup2(stderr_pipe[1], STDERR_FILENO);
if (rc < 0) if (rc < 0)
goto err_close; goto err_close;
rc = log_stderr_nonblock_set(stderr_pipe[0])
?: log_stderr_nonblock_set(stderr_pipe[1]);
if (rc != 0)
goto err_close;
stderr_buf = malloc(STDERR_BUFSIZE); stderr_buf = malloc(STDERR_BUFSIZE);
stderr_msg = g_string_sized_new(STDERR_BUFSIZE); stderr_msg = g_string_sized_new(STDERR_BUFSIZE);
stderr_level = level; stderr_level = level;