Fixing Linux AIO syscalls return value handling:

syscall(2) uses usual libc convention, it returns -1 on error and
sets errno. Obsolete _syscall(2) returns negative value of error.

Thanks to Hagai Avrahami.
This commit is contained in:
Igor Sysoev 2011-09-16 12:43:16 +00:00
parent c6353a5654
commit 4134b48b68
2 changed files with 18 additions and 19 deletions

View File

@ -184,7 +184,7 @@ ngx_module_t ngx_epoll_module = {
* into single eventfd() function with different number of parameters.
*/
static long
static int
io_setup(u_int nr_reqs, aio_context_t *ctx)
{
return syscall(SYS_io_setup, nr_reqs, ctx);
@ -198,7 +198,7 @@ io_destroy(aio_context_t ctx)
}
static long
static int
io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events,
struct timespec *tmo)
{
@ -247,10 +247,10 @@ ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"eventfd: %d", ngx_eventfd);
n = io_setup(1024, &ngx_aio_ctx);
if (io_setup(1024, &ngx_aio_ctx) == -1) {
if (n != 0) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, -n, "io_setup() failed");
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"io_setup() failed");
return NGX_ERROR;
}
@ -316,7 +316,7 @@ ngx_epoll_done(ngx_cycle_t *cycle)
#if (NGX_HAVE_FILE_AIO)
if (io_destroy(ngx_aio_ctx) != 0) {
if (io_destroy(ngx_aio_ctx) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"io_destroy() failed");
}
@ -667,8 +667,8 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
static void
ngx_epoll_eventfd_handler(ngx_event_t *ev)
{
int n;
long i, events;
int n, events;
long i;
uint64_t ready;
ngx_err_t err;
ngx_event_t *e;
@ -738,8 +738,9 @@ ngx_epoll_eventfd_handler(ngx_event_t *ev)
return;
}
/* events < 0 */
ngx_log_error(NGX_LOG_ALERT, ev->log, -events, "io_getevents() failed");
/* events == -1 */
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
"io_getevents() failed");
return;
}
}

View File

@ -16,7 +16,7 @@ extern aio_context_t ngx_aio_ctx;
static void ngx_file_aio_event_handler(ngx_event_t *ev);
static long
static int
io_submit(aio_context_t ctx, long n, struct iocb **paiocb)
{
return syscall(SYS_io_submit, ctx, n, paiocb);
@ -27,7 +27,7 @@ ssize_t
ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
ngx_pool_t *pool)
{
long n;
ngx_err_t err;
struct iocb *piocb[1];
ngx_event_t *ev;
ngx_event_aio_t *aio;
@ -96,9 +96,7 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
piocb[0] = &aio->aiocb;
n = io_submit(ngx_aio_ctx, 1, piocb);
if (n == 1) {
if (io_submit(ngx_aio_ctx, 1, piocb) == 1) {
ev->active = 1;
ev->ready = 0;
ev->complete = 0;
@ -106,16 +104,16 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
return NGX_AGAIN;
}
n = -n;
err = ngx_errno;
if (n == NGX_EAGAIN) {
if (err == NGX_EAGAIN) {
return ngx_read_file(file, buf, size, offset);
}
ngx_log_error(NGX_LOG_CRIT, file->log, n,
ngx_log_error(NGX_LOG_CRIT, file->log, err,
"io_submit(\"%V\") failed", &file->name);
if (n == NGX_ENOSYS) {
if (err == NGX_ENOSYS) {
ngx_file_aio = 0;
return ngx_read_file(file, buf, size, offset);
}