* tmpbuf.h: New file.

* flock.cc: Include tmpbuf.h for new tmpbuf functionality.
(allow_others_to_sync): Use tmpbuf rather than tmp_pathbuf.  Explain why.
(lf_setlock): For consistency, use tmpbuf rather than tmp_pathbuf.
(lf_getlock): Ditto.
This commit is contained in:
Christopher Faylor 2010-06-21 19:55:12 +00:00
parent 94880465ac
commit f074bd3aef
3 changed files with 46 additions and 9 deletions

View File

@ -1,3 +1,12 @@
2010-06-21 Christopher Faylor <me+cygwin@cgf.cx>
* tmpbuf.h: New file.
* flock.cc: Include tmpbuf.h for new tmpbuf functionality.
(allow_others_to_sync): Use tmpbuf rather than tmp_pathbuf. Explain
why.
(lf_setlock): For consistency, use tmpbuf rather than tmp_pathbuf.
(lf_getlock): Ditto.
2010-06-21 Christopher Faylor <me+cygwin@cgf.cx> 2010-06-21 Christopher Faylor <me+cygwin@cgf.cx>
* dcrt0.cc (__api_fatal): Temporarily generate a stackdump. * dcrt0.cc (__api_fatal): Temporarily generate a stackdump.

View File

@ -105,7 +105,7 @@
#include "pinfo.h" #include "pinfo.h"
#include "sigproc.h" #include "sigproc.h"
#include "cygtls.h" #include "cygtls.h"
#include "tls_pbuf.h" #include "tmpbuf.h"
#include "ntdll.h" #include "ntdll.h"
#include <sys/queue.h> #include <sys/queue.h>
#include <wchar.h> #include <wchar.h>
@ -151,10 +151,11 @@ allow_others_to_sync ()
LPVOID ace; LPVOID ace;
ULONG len; ULONG len;
/* Get this process DACL. We use a temporary path buffer in TLS space /* Get this process DACL. We use a temporary buffer to avoid having to
to avoid having to alloc 64K from the stack. */ alloc 64K from the stack. Can't use tls functions at this point because
tmp_pathbuf tp; this gets called during initialization when the tls is not really
PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR) tp.w_get (); available. */
tmpbuf sd;
status = NtQuerySecurityObject (NtCurrentProcess (), status = NtQuerySecurityObject (NtCurrentProcess (),
DACL_SECURITY_INFORMATION, sd, DACL_SECURITY_INFORMATION, sd,
NT_MAX_PATH * sizeof (WCHAR), &len); NT_MAX_PATH * sizeof (WCHAR), &len);
@ -873,7 +874,7 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl)
lockf_t **head = lock->lf_head; lockf_t **head = lock->lf_head;
lockf_t **prev, *overlap; lockf_t **prev, *overlap;
int ovcase, priority, old_prio, needtolink; int ovcase, priority, old_prio, needtolink;
tmp_pathbuf tp; tmpbuf tp;
/* /*
* Set the priority * Set the priority
@ -885,7 +886,7 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl)
* Scan lock list for this file looking for locks that would block us. * Scan lock list for this file looking for locks that would block us.
*/ */
/* Create temporary space for the all locks list. */ /* Create temporary space for the all locks list. */
node->i_all_lf = (lockf_t *) tp.w_get (); node->i_all_lf = (lockf_t *) (void *) tp;
while ((block = lf_getblock(lock, node))) while ((block = lf_getblock(lock, node)))
{ {
DWORD ret; DWORD ret;
@ -1227,10 +1228,10 @@ static int
lf_getlock (lockf_t *lock, inode_t *node, struct __flock64 *fl) lf_getlock (lockf_t *lock, inode_t *node, struct __flock64 *fl)
{ {
lockf_t *block; lockf_t *block;
tmp_pathbuf tp; tmpbuf tp;
/* Create temporary space for the all locks list. */ /* Create temporary space for the all locks list. */
node->i_all_lf = (lockf_t *) tp.w_get (); node->i_all_lf = (lockf_t *) (void * ) tp;
if ((block = lf_getblock (lock, node))) if ((block = lf_getblock (lock, node)))
{ {
if (block->lf_obj) if (block->lf_obj)

27
winsup/cygwin/tmpbuf.h Normal file
View File

@ -0,0 +1,27 @@
/* tmpbuf.h
Copyright 2010 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _TMPBUF_H
#define _TMPBUF_H
class tmpbuf
{
void *buf;
public:
tmpbuf (size_t size = NT_MAX_PATH)
{
buf = calloc (1, size);
if (!buf)
api_fatal ("allocation of temporary buffer failed");
}
operator void * () {return buf;}
operator char * () {return (char *) buf;}
operator PSECURITY_DESCRIPTOR () {return (PSECURITY_DESCRIPTOR) buf;}
PSECURITY_DESCRIPTOR operator -> () {return (PSECURITY_DESCRIPTOR) buf;}
~tmpbuf () {free (buf);}
};
#endif /*_TMPBUF_H*/