* cygthread.cc (cygthread::initialized): Avoid copying on fork or some threads

may not end up in the pool.
(cygthread::new): Avoid race when checking for initialized.  Add debugging
code.
* fhandler.cc (fhandler_base::raw_read): Add case for ERROR_INVALID_HANDLE due
to Win95 directories.
(fhandler_base::open): Handle errors due to Win95 directories.
(fhandler_base::close): Add get_nohandle () test.
(fhandler_base::set_close_on_exec): Ditto.
(fhandler_base::fork_fixup): Ditto.
(fhandler_base::lock): Change error code to Posix EINVAL.
(fhandler_base::dup): If get_nohandle (), set new value to INVALID_HANDLE_VALUE
instead of NULL.
* fhandler_disk_file.cc (fhandler_disk_file::fstat): Call fstat_by_name if
get_nohandle ().  Remove extraneous element from strpbrk.
(fhandler_disk_file::open): Remove test for Win95 directory.
* fhandler_random.cc (fhandler_dev_random::open): Add set_nohandle ().
* fhandler_clipboard.cc (fhandler_dev_clipboard::open): Ditto.
* fhandler_zero.cc (fhandler_dev_zero::open): Ditto.
(fhandler_dev_zero::close): Delete.
* fhandler.h (class fhandler_dev_zero): Ditto.
This commit is contained in:
Christopher Faylor 2002-09-19 03:30:20 +00:00
parent 57dfd574a7
commit 5bf785a017
20 changed files with 152 additions and 111 deletions

View File

@ -1,3 +1,31 @@
2002-09-18 Christopher Faylor <cgf@redhat.com>
* cygthread.cc (cygthread::initialized): Avoid copying on fork or some
threads may not end up in the pool.
(cygthread::new): Avoid race when checking for initialized. Add
debugging code.
2002-09-18 Pierre Humblet <pierre.humblet@ieee.org>
* fhandler.cc (fhandler_base::raw_read): Add case for
ERROR_INVALID_HANDLE due to Win95 directories.
(fhandler_base::open): Handle errors due to Win95 directories.
(fhandler_base::close): Add get_nohandle () test.
(fhandler_base::set_close_on_exec): Ditto.
(fhandler_base::fork_fixup): Ditto.
(fhandler_base::lock): Change error code to Posix EINVAL.
(fhandler_base::dup): If get_nohandle (), set new value to
INVALID_HANDLE_VALUE instead of NULL.
* fhandler_disk_file.cc (fhandler_disk_file::fstat): Call fstat_by_name
if get_nohandle (). Remove extraneous element from strpbrk.
(fhandler_disk_file::open): Remove test for Win95 directory.
* fhandler_random.cc (fhandler_dev_random::open): Add set_nohandle ().
* fhandler_clipboard.cc (fhandler_dev_clipboard::open): Ditto.
* fhandler_zero.cc (fhandler_dev_zero::open): Ditto.
(fhandler_dev_zero::close): Delete.
* fhandler.h (class fhandler_dev_zero): Ditto.
2002-09-17 Robert Collins <rbtcollins@hotmail.com> 2002-09-17 Robert Collins <rbtcollins@hotmail.com>
* thread.cc (pthread_key::set): Preserve GetLastError(). Reported * thread.cc (pthread_key::set): Preserve GetLastError(). Reported

View File

@ -19,7 +19,7 @@ static cygthread NO_COPY threads[6];
#define NTHREADS (sizeof (threads) / sizeof (threads[0])) #define NTHREADS (sizeof (threads) / sizeof (threads[0]))
DWORD NO_COPY cygthread::main_thread_id; DWORD NO_COPY cygthread::main_thread_id;
bool cygthread::initialized; bool NO_COPY cygthread::initialized;
/* Initial stub called by cygthread constructor. Performs initial /* Initial stub called by cygthread constructor. Performs initial
per-thread initialization and loops waiting for new thread functions per-thread initialization and loops waiting for new thread functions
@ -127,8 +127,9 @@ new (size_t)
for (;;) for (;;)
{ {
bool was_initialized = initialized;
/* Search the threads array for an empty slot to use */ /* Search the threads array for an empty slot to use */
for (info = threads; info < threads + NTHREADS; info++) for (info = threads + NTHREADS - 1; info >= threads; info--)
if ((id = (DWORD) InterlockedExchange ((LPLONG) &info->avail, 0))) if ((id = (DWORD) InterlockedExchange ((LPLONG) &info->avail, 0)))
{ {
info->id = id; info->id = id;
@ -139,10 +140,17 @@ new (size_t)
return info; return info;
} }
if (!initialized) if (!was_initialized)
Sleep (0); /* thread_runner is not be finished yet. */ Sleep (0); /* thread_runner is not finished yet. */
else else
return freerange (); {
#ifdef DEBUGGING
char buf[1024];
if (GetEnvironmentVariable ("CYGWIN_NOFREERANGE", buf, sizeof (buf)))
api_fatal ("Overflowed cygwin thread pool");
#endif
return freerange ();
}
} }
} }

View File

@ -730,7 +730,7 @@ handle_to_fn (HANDLE h, char *posix_fn)
if (!strncasematch (win32_fn, DEVICE_PREFIX, DEVICE_PREFIX_LEN) if (!strncasematch (win32_fn, DEVICE_PREFIX, DEVICE_PREFIX_LEN)
|| !QueryDosDevice (NULL, fnbuf, sizeof (fnbuf))) || !QueryDosDevice (NULL, fnbuf, sizeof (fnbuf)))
return strcpy (posix_fn, win32_fn); return strcpy (posix_fn, win32_fn);
char *p = strchr (win32_fn + DEVICE_PREFIX_LEN, '\\'); char *p = strchr (win32_fn + DEVICE_PREFIX_LEN, '\\');
if (!p) if (!p)
p = strchr (win32_fn + DEVICE_PREFIX_LEN, '\0'); p = strchr (win32_fn + DEVICE_PREFIX_LEN, '\0');

View File

@ -960,10 +960,10 @@ build_env (const char * const *envp, char *&envblock, int &envc,
{ {
tl = new_tl + 100; tl = new_tl + 100;
char *new_envblock = char *new_envblock =
(char *) realloc (envblock, 2 + tl); (char *) realloc (envblock, 2 + tl);
/* If realloc moves the block, move `s' with it. */ /* If realloc moves the block, move `s' with it. */
if (new_envblock != envblock) if (new_envblock != envblock)
{ {
s += new_envblock - envblock; s += new_envblock - envblock;
envblock = new_envblock; envblock = new_envblock;
} }

View File

@ -234,8 +234,8 @@ fhandler_base::set_flags (int flags, int supplied_bin)
else if (supplied_bin) else if (supplied_bin)
bin = supplied_bin; bin = supplied_bin;
else else
bin = get_w_binary () || get_r_binary () || (binmode != O_TEXT) ? bin = get_w_binary () || get_r_binary () || (binmode != O_TEXT)
O_BINARY : O_TEXT; ? O_BINARY : O_TEXT;
openflags = flags | bin; openflags = flags | bin;
@ -275,6 +275,7 @@ fhandler_base::raw_read (void *ptr, size_t ulen)
return 0; return 0;
case ERROR_INVALID_FUNCTION: case ERROR_INVALID_FUNCTION:
case ERROR_INVALID_PARAMETER: case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_HANDLE:
if (openflags & O_DIROPEN) if (openflags & O_DIROPEN)
{ {
set_errno (EISDIR); set_errno (EISDIR);
@ -441,11 +442,21 @@ fhandler_base::open (path_conv *pc, int flags, mode_t mode)
if (x == INVALID_HANDLE_VALUE) if (x == INVALID_HANDLE_VALUE)
{ {
if (GetLastError () == ERROR_INVALID_HANDLE) if (pc->isdir () && !wincap.can_open_directories ())
{
if (mode & (O_CREAT | O_EXCL) == (O_CREAT | O_EXCL))
set_errno (EEXIST);
else if (mode & (O_WRONLY | O_RDWR))
set_errno (EISDIR);
else
set_nohandle (true);
}
else if (GetLastError () == ERROR_INVALID_HANDLE)
set_errno (ENOENT); set_errno (ENOENT);
else else
__seterrno (); __seterrno ();
goto done; if (!get_nohandle ())
goto done;
} }
/* Attributes may be set only if a file is _really_ created. /* Attributes may be set only if a file is _really_ created.
@ -712,7 +723,7 @@ fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
{ {
tot = 0; tot = 0;
const struct iovec *iovptr = iov + iovcnt; const struct iovec *iovptr = iov + iovcnt;
do do
{ {
iovptr -= 1; iovptr -= 1;
tot += iovptr->iov_len; tot += iovptr->iov_len;
@ -764,7 +775,7 @@ fhandler_base::writev (const struct iovec *const iov, const int iovcnt,
{ {
tot = 0; tot = 0;
const struct iovec *iovptr = iov + iovcnt; const struct iovec *iovptr = iov + iovcnt;
do do
{ {
iovptr -= 1; iovptr -= 1;
tot += iovptr->iov_len; tot += iovptr->iov_len;
@ -871,7 +882,7 @@ fhandler_base::close ()
int res = -1; int res = -1;
syscall_printf ("closing '%s' handle %p", get_name (), get_handle()); syscall_printf ("closing '%s' handle %p", get_name (), get_handle());
if (CloseHandle (get_handle())) if (get_nohandle () || CloseHandle (get_handle()))
res = 0; res = 0;
else else
{ {
@ -898,7 +909,7 @@ fhandler_base::ioctl (unsigned int cmd, void *buf)
int int
fhandler_base::lock (int, struct flock *) fhandler_base::lock (int, struct flock *)
{ {
set_errno (ENOSYS); set_errno (EINVAL);
return -1; return -1;
} }
@ -996,7 +1007,7 @@ fhandler_base::dup (fhandler_base *child)
HANDLE nh; HANDLE nh;
if (get_nohandle ()) if (get_nohandle ())
nh = NULL; nh = INVALID_HANDLE_VALUE;
else if (!DuplicateHandle (hMainProc, get_handle(), hMainProc, &nh, 0, TRUE, else if (!DuplicateHandle (hMainProc, get_handle(), hMainProc, &nh, 0, TRUE,
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
@ -1207,7 +1218,8 @@ fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
void void
fhandler_base::set_close_on_exec (int val) fhandler_base::set_close_on_exec (int val)
{ {
set_inheritance (io_handle, val); if (!get_nohandle ())
set_inheritance (io_handle, val);
set_close_on_exec_flag (val); set_close_on_exec_flag (val);
debug_printf ("set close_on_exec for %s to %d", get_name (), val); debug_printf ("set close_on_exec for %s to %d", get_name (), val);
} }
@ -1216,7 +1228,8 @@ void
fhandler_base::fixup_after_fork (HANDLE parent) fhandler_base::fixup_after_fork (HANDLE parent)
{ {
debug_printf ("inheriting '%s' from parent", get_name ()); debug_printf ("inheriting '%s' from parent", get_name ());
fork_fixup (parent, io_handle, "io_handle"); if (!get_nohandle ())
fork_fixup (parent, io_handle, "io_handle");
} }
bool bool

View File

@ -954,7 +954,6 @@ class fhandler_dev_zero: public fhandler_base
int write (const void *ptr, size_t len); int write (const void *ptr, size_t len);
int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3)));
__off64_t lseek (__off64_t offset, int whence); __off64_t lseek (__off64_t offset, int whence);
int close (void);
void dump (); void dump ();
}; };

View File

@ -73,6 +73,7 @@ fhandler_dev_clipboard::open (path_conv *, int flags, mode_t)
membuffer = NULL; membuffer = NULL;
if (!cygnativeformat) if (!cygnativeformat)
cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE); cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
set_nohandle (true);
set_open_status (); set_open_status ();
return 1; return 1;
} }

View File

@ -185,7 +185,7 @@ fhandler_console::send_winch_maybe ()
SHORT y = info.dwWinSize.Y; SHORT y = info.dwWinSize.Y;
SHORT x = info.dwWinSize.X; SHORT x = info.dwWinSize.X;
fillin_info (); fillin_info ();
if (y != info.dwWinSize.Y || x != info.dwWinSize.X) if (y != info.dwWinSize.Y || x != info.dwWinSize.X)
tc->kill_pgrp (SIGWINCH); tc->kill_pgrp (SIGWINCH);
} }

View File

@ -156,8 +156,12 @@ fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc)
bool query_open_already; bool query_open_already;
if (get_io_handle ()) if (get_io_handle ())
return fstat_by_handle (buf, pc); {
if (get_nohandle ())
return fstat_by_name (buf, pc);
else
return fstat_by_handle (buf, pc);
}
/* If we don't care if the file is executable or we already know if it is, /* If we don't care if the file is executable or we already know if it is,
then just do a "query open" as it is apparently much faster. */ then just do a "query open" as it is apparently much faster. */
if (pc->exec_state () != dont_know_if_executable) if (pc->exec_state () != dont_know_if_executable)
@ -166,7 +170,7 @@ fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc)
query_open_already = false; query_open_already = false;
if (query_open_already && strncasematch (pc->volname (), "FAT", 3) if (query_open_already && strncasematch (pc->volname (), "FAT", 3)
&& !strpbrk (get_win32_name (), "?*|<>|")) && !strpbrk (get_win32_name (), "?*|<>"))
oret = 0; oret = 0;
else if (!(oret = open (pc, open_flags, 0))) else if (!(oret = open (pc, open_flags, 0)))
{ {
@ -191,7 +195,7 @@ fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc)
} }
} }
if (!oret) if (!oret || get_nohandle ())
res = fstat_by_name (buf, pc); res = fstat_by_name (buf, pc);
else else
{ {
@ -363,15 +367,7 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode)
set_has_acls (real_path->has_acls ()); set_has_acls (real_path->has_acls ());
set_isremote (real_path->isremote ()); set_isremote (real_path->isremote ());
int res; int res = this->fhandler_base::open (real_path, flags | O_DIROPEN, mode);
if (!real_path->isdir () || wincap.can_open_directories ())
res = this->fhandler_base::open (real_path, flags | O_DIROPEN, mode);
else
{
set_errno (EISDIR);
res = 0;
}
if (!res) if (!res)
goto out; goto out;
@ -790,7 +786,7 @@ fhandler_cygdrive::readdir (DIR *dir)
dir->__d_position++; dir->__d_position++;
pdrive = strchr (pdrive, '\0') + 1; pdrive = strchr (pdrive, '\0') + 1;
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir, syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
dir->__d_dirent->d_name); dir->__d_dirent->d_name);
return dir->__d_dirent; return dir->__d_dirent;
} }

View File

@ -224,7 +224,7 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode)
fileid = process_file_no; fileid = process_file_no;
if (!fill_filebuf ()) if (!fill_filebuf ())
{ {
res = 0; res = 0;
goto out; goto out;
} }
@ -458,8 +458,8 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
utime = put.UserTime.QuadPart * HZ / 10000000ULL; utime = put.UserTime.QuadPart * HZ / 10000000ULL;
stime = put.KernelTime.QuadPart * HZ / 10000000ULL; stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart) if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart)
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart - start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL; stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL;
else else
/* /*
* sometimes stodi.CurrentTime is a bit behind * sometimes stodi.CurrentTime is a bit behind
@ -590,7 +590,7 @@ off_t
format_process_statm (_pinfo *p, char *destbuf, size_t maxsize) format_process_statm (_pinfo *p, char *destbuf, size_t maxsize)
{ {
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL, unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL,
vmlib = 0UL, vmshare = 0UL; vmlib = 0UL, vmshare = 0UL;
if (wincap.is_winnt ()) if (wincap.is_winnt ())
{ {
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,

View File

@ -32,6 +32,7 @@ int
fhandler_dev_random::open (path_conv *, int flags, mode_t) fhandler_dev_random::open (path_conv *, int flags, mode_t)
{ {
set_flags ((flags & ~O_TEXT) | O_BINARY); set_flags ((flags & ~O_TEXT) | O_BINARY);
set_nohandle (true);
set_open_status (); set_open_status ();
return 1; return 1;
} }

View File

@ -325,7 +325,7 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
{ {
#define un_addr ((struct sockaddr_un *) name) #define un_addr ((struct sockaddr_un *) name)
struct sockaddr_in sin; struct sockaddr_in sin;
int len = sizeof sin; int len = sizeof sin;
int fd; int fd;
if (strlen (un_addr->sun_path) >= UNIX_PATH_LEN) if (strlen (un_addr->sun_path) >= UNIX_PATH_LEN)
@ -513,45 +513,45 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
int wait_result; int wait_result;
wait_result = WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE, wait_result = WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE,
FALSE); FALSE);
if (wait_result == WSA_WAIT_EVENT_0) if (wait_result == WSA_WAIT_EVENT_0)
WSAEnumNetworkEvents (get_socket (), ev[0], &sock_event); WSAEnumNetworkEvents (get_socket (), ev[0], &sock_event);
/* Unset events for listening socket and /* Unset events for listening socket and
switch back to blocking mode */ switch back to blocking mode */
WSAEventSelect (get_socket (), ev[0], 0); WSAEventSelect (get_socket (), ev[0], 0);
unsigned long nonblocking = 0; unsigned long nonblocking = 0;
ioctlsocket (get_socket (), FIONBIO, &nonblocking); ioctlsocket (get_socket (), FIONBIO, &nonblocking);
switch (wait_result) switch (wait_result)
{ {
case WSA_WAIT_EVENT_0: case WSA_WAIT_EVENT_0:
if (sock_event.lNetworkEvents & FD_ACCEPT) if (sock_event.lNetworkEvents & FD_ACCEPT)
{ {
if (sock_event.iErrorCode[FD_ACCEPT_BIT]) if (sock_event.iErrorCode[FD_ACCEPT_BIT])
{ {
WSASetLastError (sock_event.iErrorCode[FD_ACCEPT_BIT]); WSASetLastError (sock_event.iErrorCode[FD_ACCEPT_BIT]);
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
goto done; goto done;
} }
} }
/* else; : Should never happen since FD_ACCEPT is the only event /* else; : Should never happen since FD_ACCEPT is the only event
that has been selected */ that has been selected */
break; break;
case WSA_WAIT_EVENT_0 + 1: case WSA_WAIT_EVENT_0 + 1:
debug_printf ("signal received during accept"); debug_printf ("signal received during accept");
set_errno (EINTR); set_errno (EINTR);
res = -1; res = -1;
goto done; goto done;
case WSA_WAIT_FAILED: case WSA_WAIT_FAILED:
default: /* Should never happen */ default: /* Should never happen */
WSASetLastError (WSAEFAULT); WSASetLastError (WSAEFAULT);
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
goto done; goto done;
} }
} }
} }
res = ::accept (get_socket (), peer, len); res = ::accept (get_socket (), peer, len);
@ -566,7 +566,7 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
{ {
if (!create_secret_event ()) if (!create_secret_event ())
secret_check_failed = TRUE; secret_check_failed = TRUE;
else if (in_progress) else if (in_progress)
signal_secret_event (); signal_secret_event ();
} }
@ -599,12 +599,12 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
set_winsock_errno (); set_winsock_errno ();
else else
{ {
fhandler_socket* res_fh = fdsock (res_fd, get_name (), res); fhandler_socket* res_fh = fdsock (res_fd, get_name (), res);
if (get_addr_family () == AF_LOCAL) if (get_addr_family () == AF_LOCAL)
res_fh->set_sun_path (get_sun_path ()); res_fh->set_sun_path (get_sun_path ());
res_fh->set_addr_family (get_addr_family ()); res_fh->set_addr_family (get_addr_family ());
res_fh->set_socket_type (get_socket_type ()); res_fh->set_socket_type (get_socket_type ());
res = res_fd; res = res_fd;
} }
} }
@ -750,7 +750,7 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot)
{ {
tot = 0; tot = 0;
const struct iovec *iovptr = iov + iovcnt; const struct iovec *iovptr = iov + iovcnt;
do do
{ {
iovptr -= 1; iovptr -= 1;
tot += iovptr->iov_len; tot += iovptr->iov_len;
@ -903,7 +903,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags,
{ {
set_errno (EPIPE); set_errno (EPIPE);
if (! (flags & MSG_NOSIGNAL)) if (! (flags & MSG_NOSIGNAL))
_raise (SIGPIPE); _raise (SIGPIPE);
} }
return res; return res;
@ -938,7 +938,7 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot)
{ {
tot = 0; tot = 0;
const struct iovec *iovptr = iov + iovcnt; const struct iovec *iovptr = iov + iovcnt;
do do
{ {
iovptr -= 1; iovptr -= 1;
tot += iovptr->iov_len; tot += iovptr->iov_len;

View File

@ -116,7 +116,7 @@ fhandler_virtual::lseek (__off64_t offset, int whence)
* the contents of the file are updated. * the contents of the file are updated.
*/ */
if (!fill_filebuf ()) if (!fill_filebuf ())
return (__off64_t) -1; return (__off64_t) -1;
switch (whence) switch (whence)
{ {
case SEEK_SET: case SEEK_SET:

View File

@ -24,6 +24,7 @@ int
fhandler_dev_zero::open (path_conv *, int flags, mode_t) fhandler_dev_zero::open (path_conv *, int flags, mode_t)
{ {
set_flags ((flags & ~O_TEXT) | O_BINARY); set_flags ((flags & ~O_TEXT) | O_BINARY);
set_nohandle (true);
set_open_status (); set_open_status ();
return 1; return 1;
} }
@ -47,12 +48,6 @@ fhandler_dev_zero::lseek (__off64_t, int)
return 0; return 0;
} }
int
fhandler_dev_zero::close (void)
{
return 0;
}
void void
fhandler_dev_zero::dump () fhandler_dev_zero::dump ()
{ {

View File

@ -187,10 +187,10 @@ read_etc_group ()
{ {
char strbuf[100]; char strbuf[100];
snprintf (linebuf, sizeof (linebuf), "%s:%s:%lu:", snprintf (linebuf, sizeof (linebuf), "%s:%s:%lu:",
group_name, group_name,
tg.string (strbuf), tg.string (strbuf),
*GetSidSubAuthority(tg, *GetSidSubAuthority(tg,
*GetSidSubAuthorityCount(tg) - 1)); *GetSidSubAuthorityCount(tg) - 1));
debug_printf ("Emulating /etc/group: %s", linebuf); debug_printf ("Emulating /etc/group: %s", linebuf);
add_grp_line (linebuf); add_grp_line (linebuf);
group_state = emulated; group_state = emulated;
@ -365,7 +365,7 @@ getgroups32 (int gidsetsize, __gid32_t *grouplist, __gid32_t gid,
for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx)
if (sid.getfromgr (gr)) if (sid.getfromgr (gr))
for (DWORD pg = 0; pg < groups->GroupCount; ++pg) for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
if (sid == groups->Groups[pg].Sid && if (sid == groups->Groups[pg].Sid &&
sid != well_known_world_sid) sid != well_known_world_sid)
{ {
if (cnt < gidsetsize) if (cnt < gidsetsize)
@ -516,7 +516,7 @@ setgroups (int ngroups, const __gid16_t *grouplist)
if (grouplist32 == NULL) if (grouplist32 == NULL)
return -1; return -1;
for (int i = 0; i < ngroups; i++) for (int i = 0; i < ngroups; i++)
grouplist32[i] = grouplist[i]; grouplist32[i] = grouplist[i];
} }
return setgroups32 (ngroups, grouplist32); return setgroups32 (ngroups, grouplist32);
} }

View File

@ -724,7 +724,7 @@ cygwin_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
else else
{ {
res = getsockopt (fh->get_socket (), level, optname, (char *) optval, res = getsockopt (fh->get_socket (), level, optname, (char *) optval,
(int *) optlen); (int *) optlen);
if (optname == SO_ERROR) if (optname == SO_ERROR)
{ {
@ -2137,7 +2137,7 @@ cygwin_sendmsg (int fd, const struct msghdr *msg, int flags)
(unsigned) msg->msg_namelen)) (unsigned) msg->msg_namelen))
|| !fh) || !fh)
res = -1; res = -1;
else else
{ {
res = check_iovec_for_write (msg->msg_iov, msg->msg_iovlen); res = check_iovec_for_write (msg->msg_iov, msg->msg_iovlen);
if (res > 0) if (res > 0)

View File

@ -697,10 +697,10 @@ get_priv_list (LSA_HANDLE lsa, cygsid &usersid, cygsidlist &grp_list)
/* Accept a token if /* Accept a token if
- the requested usersid matches the TokenUser and - the requested usersid matches the TokenUser and
- if setgroups has been called: - if setgroups has been called:
the token groups that are listed in /etc/group match the union of the token groups that are listed in /etc/group match the union of
the requested primary and supplementary groups in gsids. the requested primary and supplementary groups in gsids.
- else the (unknown) implicitly requested supplementary groups and those - else the (unknown) implicitly requested supplementary groups and those
in the token are the groups associated with the usersid. We assume in the token are the groups associated with the usersid. We assume
they match and verify only the primary groups. they match and verify only the primary groups.
The requested primary group must appear in the token. The requested primary group must appear in the token.
The primary group in the token is a group associated with the usersid, The primary group in the token is a group associated with the usersid,
@ -782,14 +782,14 @@ verify_token (HANDLE token, cygsid &usersid, user_groups &groups, BOOL *pintern)
saw[pos] = TRUE; saw[pos] = TRUE;
else if (groups.pgsid == gsid) else if (groups.pgsid == gsid)
sawpg = TRUE; sawpg = TRUE;
else if (gsid != well_known_world_sid && else if (gsid != well_known_world_sid &&
gsid != usersid) gsid != usersid)
goto done; goto done;
} }
for (int gidx = 0; gidx < groups.sgsids.count; gidx++) for (int gidx = 0; gidx < groups.sgsids.count; gidx++)
if (!saw[gidx]) if (!saw[gidx])
goto done; goto done;
if (sawpg || if (sawpg ||
groups.sgsids.contains (groups.pgsid) || groups.sgsids.contains (groups.pgsid) ||
groups.pgsid == usersid) groups.pgsid == usersid)
ret = TRUE; ret = TRUE;
@ -859,7 +859,7 @@ create_token (cygsid &usersid, user_groups &new_groups, struct passwd *pw)
else else
{ {
/* Switching user context to SYSTEM doesn't inherit the authentication /* Switching user context to SYSTEM doesn't inherit the authentication
id of the user account running current process. */ id of the user account running current process. */
if (usersid != well_known_system_sid) if (usersid != well_known_system_sid)
if (!GetTokenInformation (my_token, TokenStatistics, if (!GetTokenInformation (my_token, TokenStatistics,
&stats, sizeof stats, &size)) &stats, sizeof stats, &size))
@ -869,7 +869,7 @@ create_token (cygsid &usersid, user_groups &new_groups, struct passwd *pw)
auth_luid = stats.AuthenticationId; auth_luid = stats.AuthenticationId;
/* Retrieving current processes group list to be able to inherit /* Retrieving current processes group list to be able to inherit
some important well known group sids. */ some important well known group sids. */
if (!GetTokenInformation (my_token, TokenGroups, NULL, 0, &size) && if (!GetTokenInformation (my_token, TokenGroups, NULL, 0, &size) &&
GetLastError () != ERROR_INSUFFICIENT_BUFFER) GetLastError () != ERROR_INSUFFICIENT_BUFFER)
debug_printf ("GetTokenInformation(my_token, TokenGroups): %E\n"); debug_printf ("GetTokenInformation(my_token, TokenGroups): %E\n");
@ -1187,8 +1187,8 @@ write_sd (const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size)
&bytes_written, FALSE, TRUE, &context)) &bytes_written, FALSE, TRUE, &context))
{ {
/* Samba returns ERROR_NOT_SUPPORTED. /* Samba returns ERROR_NOT_SUPPORTED.
FAT returns ERROR_INVALID_SECURITY_DESCR. FAT returns ERROR_INVALID_SECURITY_DESCR.
This shouldn't return as error, but better be ignored. */ This shouldn't return as error, but better be ignored. */
DWORD ret = GetLastError (); DWORD ret = GetLastError ();
if (ret != ERROR_NOT_SUPPORTED && ret != ERROR_INVALID_SECURITY_DESCR) if (ret != ERROR_NOT_SUPPORTED && ret != ERROR_INVALID_SECURITY_DESCR)
{ {
@ -1463,7 +1463,7 @@ get_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type,
if (allow_ntsec) if (allow_ntsec)
{ {
int res = get_nt_object_attribute (handle, object_type, attribute, int res = get_nt_object_attribute (handle, object_type, attribute,
uidret, gidret); uidret, gidret);
if (attribute && (*attribute & S_IFLNK) == S_IFLNK) if (attribute && (*attribute & S_IFLNK) == S_IFLNK)
*attribute |= S_IRWXU | S_IRWXG | S_IRWXO; *attribute |= S_IRWXU | S_IRWXG | S_IRWXO;
return res; return res;

View File

@ -113,7 +113,7 @@ strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
static NO_COPY int nonewline = FALSE; static NO_COPY int nonewline = FALSE;
DWORD err = GetLastError (); DWORD err = GetLastError ();
const char *tn = cygthread::name (); const char *tn = cygthread::name ();
char *pn = __progname ?: myself->progname; char *pn = __progname ?: (myself ? myself->progname : NULL);
int microsec = microseconds (); int microsec = microseconds ();
lmicrosec = microsec; lmicrosec = microsec;

View File

@ -387,7 +387,7 @@ pthread::setTlsSelfPointer (pthread *thisThread)
/* member methods */ /* member methods */
pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0), pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0),
cancelstate (0), canceltype (0), cancel_event (0), cancelstate (0), canceltype (0), cancel_event (0),
joiner (NULL), cleanup_stack (NULL) joiner (NULL), cleanup_stack (NULL)
{ {
} }

View File

@ -296,7 +296,7 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
if (newhomedrive && newhomedrive != homedrive) if (newhomedrive && newhomedrive != homedrive)
cfree_and_set (homedrive, (newhomedrive == almost_null) cfree_and_set (homedrive, (newhomedrive == almost_null)
? almost_null : cstrdup (newhomedrive)); ? almost_null : cstrdup (newhomedrive));
if (newhomepath && newhomepath != homepath) if (newhomepath && newhomepath != homepath)
cfree_and_set (homepath, cstrdup (newhomepath)); cfree_and_set (homepath, cstrdup (newhomepath));