Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-08-09 06:33:47 +0400
committerChristopher Faylor <me@cgf.cx>2000-08-09 06:33:47 +0400
commit0072fdab860eb12ab2a454860a8c25ade253de6c (patch)
treefa970886fb81871f5714dbe2734ba91e40a7740a
parentc51a2a8ba4b5d7fa3831303f2bf8611d23b52765 (diff)
* select.cc (allocfd_set): Zero allocated fd_set.
(cygwin_select): Move fd_set copying logic from ::wait to here. Use common return through sell.poll. (select_stuff::wait): Just return success or failure and let caller fill in fd_set. * pinfo.h (pinfo): Eliminate self-referential pointer to sidbuf since pinfo structure exists at random locations now. * fork.cc (fork): Use 'use_psid' element to control when the psid is relevant. * shared.cc (sec_user): Ditto. * spawn.cc (spawn_guts): Ditto. * uinfo.cc (internal_getlogin): Ditto. * syscall.cc (seteuid): Ditto. Set use_psid element.
-rw-r--r--winsup/cygwin/ChangeLog16
-rw-r--r--winsup/cygwin/fork.cc8
-rw-r--r--winsup/cygwin/pinfo.h14
-rw-r--r--winsup/cygwin/select.cc77
-rw-r--r--winsup/cygwin/shared.cc2
-rw-r--r--winsup/cygwin/spawn.cc10
-rw-r--r--winsup/cygwin/syscalls.cc4
-rw-r--r--winsup/cygwin/uinfo.cc8
8 files changed, 70 insertions, 69 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index b9c8ca3f9..a8a11c318 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,19 @@
+Tue Aug 8 22:25:39 2000 Christopher Faylor <cgf@cygnus.com>
+
+ * select.cc (allocfd_set): Zero allocated fd_set.
+ (cygwin_select): Move fd_set copying logic from ::wait to here. Use
+ common return through sell.poll.
+ (select_stuff::wait): Just return success or failure and let caller
+ fill in fd_set.
+ * pinfo.h (pinfo): Eliminate self-referential pointer to sidbuf since
+ pinfo structure exists at random locations now.
+ * fork.cc (fork): Use 'use_psid' element to control when the psid is
+ relevant.
+ * shared.cc (sec_user): Ditto.
+ * spawn.cc (spawn_guts): Ditto.
+ * uinfo.cc (internal_getlogin): Ditto.
+ * syscall.cc (seteuid): Ditto. Set use_psid element.
+
Tue Aug 8 13:20:00 2000 Bob Wilson <bwilson@tensilica.com>
* fhandler_serial.cc (tcsendbreak): "sleeptime" argument to usleep()
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 6052bac7f..6dfa83aa5 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -423,9 +423,11 @@ fork ()
forked->process_state |= PID_INITIALIZING |
(myself->process_state & PID_USETTY);
memcpy (forked->username, myself->username, MAX_USER_NAME);
- memcpy (forked->sidbuf, myself->sidbuf, MAX_SID_LEN);
- if (myself->psid)
- forked->psid = forked->sidbuf;
+ if (myself->use_psid)
+ {
+ memcpy (forked->psid, myself->psid, MAX_SID_LEN);
+ forked->use_psid = 1;
+ }
memcpy (forked->logsrv, myself->logsrv, MAX_HOST_NAME);
memcpy (forked->domain, myself->domain, MAX_COMPUTERNAME_LENGTH+1);
forked->token = myself->token;
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 4d9d71afd..87d4f3dfc 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -49,19 +49,19 @@ public:
if not found. This data resides in the shared data area (allowing
tasks to store whatever they want here) so it's for informational
purposes only. */
- uid_t uid; /* User ID */
- gid_t gid; /* Group ID */
- pid_t pgid; /* Process group ID */
- pid_t sid; /* Session ID */
- int ctty; /* Control tty */
+ uid_t uid; /* User ID */
+ gid_t gid; /* Group ID */
+ pid_t pgid; /* Process group ID */
+ pid_t sid; /* Session ID */
+ int ctty; /* Control tty */
mode_t umask;
char username[MAX_USER_NAME]; /* user's name */
/* Extendend user information.
The information is derived from the internal_getlogin call
when on a NT system. */
- PSID psid; /* user's SID */
- char sidbuf[MAX_SID_LEN]; /* buffer for user's SID */
+ int use_psid; /* TRUE if psid contains valid data */
+ char psid[MAX_SID_LEN]; /* buffer for user's SID */
char logsrv[MAX_HOST_NAME]; /* Logon server, may be FQDN */
char domain[MAX_COMPUTERNAME_LENGTH+1]; /* Logon domain of the user */
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index db87643f4..6d2296b95 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -1,6 +1,6 @@
/* select.cc
- Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions.
+ Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc.
Written by Christopher Faylor of Cygnus Solutions
cgf@cygnus.com
@@ -71,7 +71,7 @@ typedef long fd_mask;
#define UNIX_FD_ZERO(p, n) \
bzero ((caddr_t)(p), sizeof_fd_set ((n)))
-#define allocfd_set(n) ((fd_set *) alloca (sizeof_fd_set (n)))
+#define allocfd_set(n) ((fd_set *) memset (alloca (sizeof_fd_set (n)), 0, sizeof_fd_set (n)))
#define copyfd_set(to, from, n) memcpy (to, from, sizeof_fd_set (n));
/* Make a fhandler_foo::ready_for_ready method.
@@ -105,13 +105,13 @@ fhandler_##what::ready_for_read (int fd, DWORD howlong, int ignra) \
*/
extern "C"
int
-cygwin_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- struct timeval *to)
+cygwin_select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+ struct timeval *to)
{
select_stuff sel;
- fd_set *dummy_readfds = allocfd_set (n);
- fd_set *dummy_writefds = allocfd_set (n);
- fd_set *dummy_exceptfds = allocfd_set (n);
+ fd_set *dummy_readfds = allocfd_set (maxfds);
+ fd_set *dummy_writefds = allocfd_set (maxfds);
+ fd_set *dummy_exceptfds = allocfd_set (maxfds);
sigframe thisframe (mainthread, 0);
#if 0
@@ -122,25 +122,16 @@ cygwin_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
}
#endif
- select_printf ("%d, %p, %p, %p, %p", n, readfds, writefds, exceptfds, to);
+ select_printf ("%d, %p, %p, %p, %p", maxfds, readfds, writefds, exceptfds, to);
if (!readfds)
- {
- UNIX_FD_ZERO (dummy_readfds, n);
- readfds = dummy_readfds;
- }
+ readfds = dummy_readfds;
if (!writefds)
- {
- UNIX_FD_ZERO (dummy_writefds, n);
- writefds = dummy_writefds;
- }
+ writefds = dummy_writefds;
if (!exceptfds)
- {
- UNIX_FD_ZERO (dummy_exceptfds, n);
- exceptfds = dummy_exceptfds;
- }
+ exceptfds = dummy_exceptfds;
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < maxfds; i++)
if (!sel.test_and_set (i, readfds, writefds, exceptfds))
{
select_printf ("aborting due to test_and_set error");
@@ -171,18 +162,19 @@ cygwin_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
return 0;
}
- /* If one of the selected fds is "always ready" just poll everything and return
- the result. There is no need to wait. */
- if (sel.always_ready || ms == 0)
- {
- UNIX_FD_ZERO (readfds, n);
- UNIX_FD_ZERO (writefds, n);
- UNIX_FD_ZERO (exceptfds, n);
- return sel.poll (readfds, writefds, exceptfds);
- }
-
- /* Wait for an fd to come alive */
- return sel.wait (readfds, writefds, exceptfds, ms);
+ /* Allocate some fd_set structures using the number of fds as a guide. */
+ fd_set *r = allocfd_set (maxfds);
+ fd_set *w = allocfd_set (maxfds);
+ fd_set *e = allocfd_set (maxfds);
+
+ /* Don't bother waiting if one of the selected fds is "always ready". */
+ if ((!sel.always_ready || ms != 0) && sel.wait (r, w, e, ms))
+ return -1; /* some kind of error */
+
+ copyfd_set (readfds, r, maxfds);
+ copyfd_set (writefds, w, maxfds);
+ copyfd_set (exceptfds, e, maxfds);
+ return sel.poll (readfds, writefds, exceptfds);
}
/* Cleanup */
@@ -273,17 +265,9 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
continue;
}
- int n = m - 1;
DWORD start_time = GetTickCount (); /* Record the current time for later use. */
- /* Allocate some fd_set structures using the number of fds as a guide. */
- fd_set *r = allocfd_set (n);
- fd_set *w = allocfd_set (n);
- fd_set *e = allocfd_set (n);
- UNIX_FD_ZERO (r, n);
- UNIX_FD_ZERO (w, n);
- UNIX_FD_ZERO (e, n);
- debug_printf ("n %d, ms %u", n, ms);
+ debug_printf ("m %d, ms %u", m, ms);
for (;;)
{
if (!windows_used)
@@ -313,7 +297,7 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
if (s->saw_error)
return -1; /* Somebody detected an error */
else if ((((wait_ret >= m && s->windows_handle) || s->h == w4[wait_ret])) &&
- s->verify (s, r, w, e))
+ s->verify (s, readfds, writefds, exceptfds))
gotone = TRUE;
select_printf ("gotone %d", gotone);
@@ -339,11 +323,8 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
}
out:
- copyfd_set (readfds, r, n);
- copyfd_set (writefds, w, n);
- copyfd_set (exceptfds, e, n);
-
- return poll (readfds, writefds, exceptfds);
+ select_printf ("returning 0");
+ return 0;
}
static int
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index a73494baa..ff8dd3dfa 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -212,7 +212,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
char sid_buf[MAX_SID_LEN];
PSID sid = (PSID) sid_buf;
- if (myself->psid)
+ if (myself->use_psid)
CopySid (MAX_SID_LEN, sid, myself->psid);
else if (! lookup_name (getlogin (), myself->logsrv, sid))
return inherit ? &sec_none_nih : &sec_none;
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index be35a0b7d..36098a279 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -670,9 +670,11 @@ skip_arg_parsing:
child->ctty = myself->ctty;
child->umask = myself->umask;
child->process_state |= PID_INITIALIZING;
- memcpy (child->sidbuf, myself->sidbuf, MAX_SID_LEN);
- if (myself->psid)
- child->psid = child->sidbuf;
+ if (myself->use_psid)
+ {
+ child->use_psid = 1;
+ memcpy (child->psid, myself->psid, MAX_SID_LEN);
+ }
memcpy (child->logsrv, myself->logsrv, MAX_HOST_NAME);
memcpy (child->domain, myself->domain, MAX_COMPUTERNAME_LENGTH+1);
memcpy (child->root, myself->root, MAX_PATH+1);
@@ -691,7 +693,7 @@ skip_arg_parsing:
/* Set child->uid to USHRT_MAX to force calling internal_getlogin()
from child process. Clear username and psid to play it safe. */
child->uid = USHRT_MAX;
- child->psid = NULL;
+ child->use_psid = 0;
}
child.remember ();
}
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 5698a9b72..e4a705c2d 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1865,7 +1865,6 @@ seteuid (uid_t uid)
}
struct _pinfo pi;
- pi.psid = (PSID) pi.sidbuf;
/* pi.token is used in internal_getlogin() to determine if
impersonation is active. If so, the token is used for
retrieving user's SID. */
@@ -1884,7 +1883,8 @@ seteuid (uid_t uid)
strcpy (myself->username, pi.username);
strcpy (myself->logsrv, pi.logsrv);
strcpy (myself->domain, pi.domain);
- memcpy (myself->sidbuf, pi.sidbuf, MAX_SID_LEN);
+ memcpy (myself->psid, pi.psid, MAX_SID_LEN);
+ myself->use_psid = 1;
}
}
else
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 592ef36e9..d752d69ea 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -112,7 +112,7 @@ internal_getlogin (_pinfo *pi)
else if (!GetTokenInformation (ptok, TokenUser, (LPVOID) &tu,
sizeof tu, &siz))
debug_printf ("GetTokenInformation(): %E");
- else if (!(ret = CopySid (MAX_SID_LEN, (PSID) pi->sidbuf,
+ else if (!(ret = CopySid (MAX_SID_LEN, (PSID) pi->psid,
((TOKEN_USER *) &tu)->User.Sid)))
debug_printf ("Couldn't retrieve SID from access token!");
/* Close token only if it's a result from OpenProcessToken(). */
@@ -126,14 +126,14 @@ internal_getlogin (_pinfo *pi)
{
/* Concat DOMAIN\USERNAME for the next lookup */
strcat (strcat (strcpy (buf, pi->domain), "\\"), pi->username);
- if (!(ret = lookup_name (buf, NULL, (PSID) pi->sidbuf)))
+ if (!(ret = lookup_name (buf, NULL, (PSID) pi->psid)))
debug_printf ("Couldn't retrieve SID locally!");
}
/* If that failes, too, as a last resort try to get the SID from
the logon server. */
if (!ret && !(ret = lookup_name(pi->username, pi->logsrv,
- (PSID)pi->sidbuf)))
+ (PSID)pi->psid)))
debug_printf ("Couldn't retrieve SID from '%s'!", pi->logsrv);
/* If we have a SID, try to get the corresponding Cygwin user name
@@ -144,7 +144,7 @@ internal_getlogin (_pinfo *pi)
char psidbuf[MAX_SID_LEN];
PSID psid = (PSID) psidbuf;
- pi->psid = (PSID) pi->sidbuf;
+ pi->use_psid = 1;
if (!strcasematch (pi->username, "SYSTEM")
&& pi->domain[0] && pi->logsrv[0])
{