This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch]: Create Global Privilege


Two questions:

On Dec  4 22:16, Pierre A. Humblet wrote:
> +locked_append (int fd, const void * buf, size_t size)
> +{
> +  struct __flock64 lock_buffer = {F_WRLCK, SEEK_SET, 0, 0, 0};
> +  int count = 0;
> +
> +  do
> +    if ((lock_buffer.l_start = lseek64 (fd, 0, SEEK_END)) != (_off64_t)-1
> +	&& fcntl_worker (fd, F_SETLK, &lock_buffer) != -1)

What is the advantage of using lseek(SEEK_END) and using that value
for fcntl(F_SETLK, SEEK_SET) over just using fcntl(F_SETLK, SEEK_END)?
Especially since lseek(SEEK_END) is then called afterwards anyway.

> +      {
> +	if (lseek64 (fd, 0, SEEK_END) != (_off64_t)-1)
> +	  write (fd, buf, size);
> +	lock_buffer.l_type = F_UNLCK;
> +	fcntl_worker (fd, F_SETLK, &lock_buffer);
> +	break;
> +      }
> +  while (count++ < 4
> +	 && (errno == EACCES || errno == EAGAIN)
> +	 && !usleep (1000));

What is the advantage of using a finite loop with fcntl(F_SETLK) over
using fcntl(F_SETLKW) just once?  This seems potentially less secure
than F_SETLKW and also less secure than the former Mutex solution.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]