lio_listio Problem
Andreas Jaeger
aj@suse.de
Tue Jul 25 12:28:00 GMT 2000
Kevin send me the appended test program (which I slightly modified).
It segfaults in:
Program received signal SIGSEGV, Segmentation fault.
0x40021423 in lio_listio (mode=1, list=0x8049960, nent=2, sig=0x0)
at lio_listio.c:144
144 lio_listio.c: No such file or directory.
The problem seems to be that sig is dereferenced. Unix98 specifies:
If the mode argument is LIO_NOWAIT, the function returns
immediately, and asynchronous notification occurs, according to the
sig argument, when all the I/O operations complete. If sig is NULL,
then no asynchronous notification occurs. If sig is not NULL,
asynchronous notification occurs as specified in Signal Generation
and Delivery when all the requests in list have completed.
How should this be fixed properly?
Andreas
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <stdio.h>
#include <errno.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include <string.h>
#include <aio.h>
#define FILENAME "async.log"
#define ACCESS_MODE "O_RDWR | O_CREAT"
#define NUM_OF_AIOCBS 2
#define SIG_LISTIO_DONE (SIGRTMAX-9)
/*aiocb_t async0, async1;*/
struct aiocb async_ctrl_blk[NUM_OF_AIOCBS];
char *out_data[NUM_OF_AIOCBS];
int counter;
int buf_switch = 0;
main()
{
for(counter=0; counter<NUM_OF_AIOCBS; counter++)
{
out_data[counter] = (char*)malloc(sizeof(char)+2);
sprintf(out_data[counter], "%1.1d\n", counter);
printf("%s", out_data[counter]);
}
for(counter=0; counter<NUM_OF_AIOCBS; counter++)
{
async_ctrl_blk[counter] = (struct aiocb*)malloc(sizeof(struct aiocb));
async_ctrl_blk[counter].aio_fildes = open(FILENAME,O_RDWR | O_APPEND | O_CREAT, 0666);
async_ctrl_blk[counter].aio_offset = 0;
async_ctrl_blk[counter].aio_lio_opcode = LIO_WRITE;
async_ctrl_blk[counter].aio_buf = out_data[counter];
async_ctrl_blk[counter].aio_nbytes = sizeof(char)+2;
}
if (lio_listio(LIO_NOWAIT, &async_ctrl_blk, NUM_OF_AIOCBS, NULL) < 0 )
perror("lio_listio");
aio_suspend(async_ctrl_blk, NUM_OF_AIOCBS, NULL);
}
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
More information about the Libc-alpha
mailing list