Welcome! Log In Create A New Profile

Advanced

Re: bug in function ngx_write_file?

July 01, 2010 02:02AM
On Wed, Jun 30, 2010 at 11:26:46AM +0800, lu wenbin wrote:

> Hi
> I read the code in src/os/ngx_files.c, function ngx_write_file, but
> get a little confused
> * for ( ;; ) {
> n = pwrite(file->fd, buf, size, offset);
>
> if (n == -1) {
> ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
> "pwrite() \"%s\" failed", file->name.data);
> return NGX_ERROR;
> }
>
> file->offset += n;
> written += n;
>
> if ((size_t) n == size) {
> return written;
> }
>
> offset += n;
> size -= n;
> }
> * the code seems want to write all content in buf to file(file->fd), but
> I think *n = pwrite(file->fd, buf, size, offset) *should be changed to* **n
> = pwrite(file->fd, buf+written, size, offset);
> man pwrite:
> **pwrite() writes up to count bytes from the buffer starting at buf
> to the file descriptor fd at offset offset. The file offset is not
> changed.**

Yes, you are right, thank you. This bug was not catched since
partial write to a regular file is very seldom issue and currently
ngx_write_file() is used only to write a tiny PID file.


--
Igor Sysoev
http://sysoev.ru/en/

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

bug in function ngx_write_file?

lu wenbin 2631 July 01, 2010 01:58AM

Re: bug in function ngx_write_file?

Igor Sysoev 1417 July 01, 2010 02:02AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 183
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready