mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-01 12:00:35 +08:00
* cygheap.cc (creturn): Set appropriate errno when out of memory.
(ccalloc): Only issue system_printf when debugging. * dtable.cc (dtable::extend): Only allocate 100 * the incremental growth size max. Set errno appropriately. (dtable::build_fhandler): Check for error from set_name. * fhandler.cc (fhandler_base::set_name): Set errno and return error on OOM. * fhandler.h (fhandler_base::set_name): Change to bool. * fhandler_process.cc (format_process_stat): Fix formatting. * resource.cc (getrlimit): Return greater of OPEN_MAX or fd table size. * sysconf.cc (sysconf): Ditto.
This commit is contained in:
parent
a42408549f
commit
4d782b426a
@ -1,3 +1,16 @@
|
|||||||
|
2003-07-08 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* cygheap.cc (creturn): Set appropriate errno when out of memory.
|
||||||
|
(ccalloc): Only issue system_printf when debugging.
|
||||||
|
* dtable.cc (dtable::extend): Only allocate 100 * the incremental growth
|
||||||
|
size max. Set errno appropriately.
|
||||||
|
(dtable::build_fhandler): Check for error from set_name.
|
||||||
|
* fhandler.cc (fhandler_base::set_name): Set errno and return error on OOM.
|
||||||
|
* fhandler.h (fhandler_base::set_name): Change to bool.
|
||||||
|
* fhandler_process.cc (format_process_stat): Fix formatting.
|
||||||
|
* resource.cc (getrlimit): Return greater of OPEN_MAX or fd table size.
|
||||||
|
* sysconf.cc (sysconf): Ditto.
|
||||||
|
|
||||||
2003-07-07 Christopher Faylor <cgf@redhat.com>
|
2003-07-07 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* rmsym: Don't use ranlib.
|
* rmsym: Don't use ranlib.
|
||||||
|
@ -285,7 +285,7 @@ creturn (cygheap_types x, cygheap_entry * c, unsigned len)
|
|||||||
{
|
{
|
||||||
if (!c)
|
if (!c)
|
||||||
{
|
{
|
||||||
__seterrno ();
|
set_errno (ENOMEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
c->type = x;
|
c->type = x;
|
||||||
@ -348,8 +348,10 @@ ccalloc (cygheap_types x, DWORD n, DWORD size)
|
|||||||
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
|
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
|
||||||
if (c)
|
if (c)
|
||||||
memset (c->data, 0, n);
|
memset (c->data, 0, n);
|
||||||
|
#ifdef DEBUGGING
|
||||||
if (!c)
|
if (!c)
|
||||||
system_printf ("ccalloc returned NULL");
|
system_printf ("ccalloc returned NULL");
|
||||||
|
#endif
|
||||||
return creturn (x, c, n);
|
return creturn (x, c, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,18 +65,25 @@ dtable::extend (int howmuch)
|
|||||||
if (howmuch <= 0)
|
if (howmuch <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (new_size > (100 * NOFILE_INCR))
|
||||||
|
{
|
||||||
|
set_errno (EMFILE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try to allocate more space for fd table. We can't call realloc ()
|
/* Try to allocate more space for fd table. We can't call realloc ()
|
||||||
here to preserve old table if memory allocation fails */
|
here to preserve old table if memory allocation fails */
|
||||||
|
|
||||||
if (!(newfds = (fhandler_base **) ccalloc (HEAP_ARGV, new_size, sizeof newfds[0])))
|
if (!(newfds = (fhandler_base **) ccalloc (HEAP_ARGV, new_size, sizeof newfds[0])))
|
||||||
{
|
{
|
||||||
debug_printf ("calloc failed");
|
debug_printf ("calloc failed");
|
||||||
|
set_errno (ENOMEM);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (fds)
|
if (fds)
|
||||||
{
|
{
|
||||||
memcpy (newfds, fds, size * sizeof (fds[0]));
|
|
||||||
cfree (fds);
|
cfree (fds);
|
||||||
|
memcpy (newfds, fds, size * sizeof (fds[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
size = new_size;
|
size = new_size;
|
||||||
@ -404,7 +411,8 @@ dtable::build_fhandler (int fd, DWORD dev, char *unix_name,
|
|||||||
for (p = (char *) win32_name; (p = strchr (p, '/')); p++)
|
for (p = (char *) win32_name; (p = strchr (p, '/')); p++)
|
||||||
*p = '\\';
|
*p = '\\';
|
||||||
}
|
}
|
||||||
fh->set_name (unix_name, win32_name, fh->get_unit ());
|
if (!fh->set_name (unix_name, win32_name, fh->get_unit ()))
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
debug_printf ("fd %d, fh %p", fd, fh);
|
debug_printf ("fd %d, fh %p", fd, fh);
|
||||||
return fd >= 0 ? (fds[fd] = fh) : fh;
|
return fd >= 0 ? (fds[fd] = fh) : fh;
|
||||||
|
@ -149,11 +149,11 @@ fhandler_base::get_readahead_into_buffer (char *buf, size_t buflen)
|
|||||||
in cases where the name is really required, the filename wouldn't ever
|
in cases where the name is really required, the filename wouldn't ever
|
||||||
be too long (e.g. devices or some such).
|
be too long (e.g. devices or some such).
|
||||||
The unix_path_name is also used by virtual fhandlers. */
|
The unix_path_name is also used by virtual fhandlers. */
|
||||||
void
|
bool
|
||||||
fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit)
|
fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit)
|
||||||
{
|
{
|
||||||
if (unix_path == NULL || !*unix_path)
|
if (unix_path == NULL || !*unix_path)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (win32_path)
|
if (win32_path)
|
||||||
win32_path_name = cstrdup (win32_path);
|
win32_path_name = cstrdup (win32_path);
|
||||||
@ -161,6 +161,7 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit
|
|||||||
{
|
{
|
||||||
const char *fmt = get_native_name ();
|
const char *fmt = get_native_name ();
|
||||||
char *w = (char *) cmalloc (HEAP_STR, strlen (fmt) + 16);
|
char *w = (char *) cmalloc (HEAP_STR, strlen (fmt) + 16);
|
||||||
|
if (w)
|
||||||
__small_sprintf (w, fmt, unit);
|
__small_sprintf (w, fmt, unit);
|
||||||
win32_path_name = w;
|
win32_path_name = w;
|
||||||
}
|
}
|
||||||
@ -168,7 +169,8 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit
|
|||||||
if (win32_path_name == NULL)
|
if (win32_path_name == NULL)
|
||||||
{
|
{
|
||||||
system_printf ("fatal error. strdup failed");
|
system_printf ("fatal error. strdup failed");
|
||||||
exit (ENOMEM);
|
set_errno (ENOMEM);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (unix_path_name == NULL);
|
assert (unix_path_name == NULL);
|
||||||
@ -183,6 +185,7 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit
|
|||||||
{
|
{
|
||||||
char *p = cstrdup (win32_path_name);
|
char *p = cstrdup (win32_path_name);
|
||||||
unix_path_name = p;
|
unix_path_name = p;
|
||||||
|
if (p)
|
||||||
while ((p = strchr (p, '\\')) != NULL)
|
while ((p = strchr (p, '\\')) != NULL)
|
||||||
*p++ = '/';
|
*p++ = '/';
|
||||||
if (unix_path)
|
if (unix_path)
|
||||||
@ -192,9 +195,12 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit
|
|||||||
if (unix_path_name == NULL)
|
if (unix_path_name == NULL)
|
||||||
{
|
{
|
||||||
system_printf ("fatal error. strdup failed");
|
system_printf ("fatal error. strdup failed");
|
||||||
exit (ENOMEM);
|
free ((void *) win32_path_name);
|
||||||
|
set_errno (ENOMEM);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
namehash = hash_path_name (0, win32_path_name);
|
namehash = hash_path_name (0, win32_path_name);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect if we are sitting at EOF for conditions where Windows
|
/* Detect if we are sitting at EOF for conditions where Windows
|
||||||
|
@ -171,7 +171,7 @@ class fhandler_base
|
|||||||
HANDLE read_state;
|
HANDLE read_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_name (const char * unix_path, const char *win32_path = NULL, int unit = 0);
|
bool set_name (const char * unix_path, const char *win32_path = NULL, int unit = 0);
|
||||||
|
|
||||||
virtual fhandler_base& operator =(fhandler_base &x);
|
virtual fhandler_base& operator =(fhandler_base &x);
|
||||||
fhandler_base (DWORD dev, int unit = 0);
|
fhandler_base (DWORD dev, int unit = 0);
|
||||||
|
@ -400,7 +400,9 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
|
|||||||
state = 'T';
|
state = 'T';
|
||||||
else if (wincap.is_winnt ())
|
else if (wincap.is_winnt ())
|
||||||
state = get_process_state (p->dwProcessId);
|
state = get_process_state (p->dwProcessId);
|
||||||
if (wincap.is_winnt ())
|
if (!wincap.is_winnt ())
|
||||||
|
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
HANDLE hProcess;
|
HANDLE hProcess;
|
||||||
@ -462,6 +464,8 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
|
|||||||
fault_count = vmc.PageFaultCount;
|
fault_count = vmc.PageFaultCount;
|
||||||
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
|
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
|
||||||
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
|
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
|
||||||
|
start_time = (put.CreateTime.QuadPart - stodi.BootTime.QuadPart) * HZ / 10000000ULL;
|
||||||
|
#if 0
|
||||||
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;
|
||||||
@ -471,17 +475,15 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
|
|||||||
* Note: some older versions of procps are broken and can't cope
|
* Note: some older versions of procps are broken and can't cope
|
||||||
* with process start times > time(NULL).
|
* with process start times > time(NULL).
|
||||||
*/
|
*/
|
||||||
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
|
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
|
||||||
|
#endif
|
||||||
priority = pbi.BasePriority;
|
priority = pbi.BasePriority;
|
||||||
unsigned page_size = getpagesize ();
|
unsigned page_size = getpagesize ();
|
||||||
vmsize = vmc.PagefileUsage;
|
vmsize = vmc.PagefileUsage;
|
||||||
vmrss = vmc.WorkingSetSize / page_size;
|
vmrss = vmc.WorkingSetSize / page_size;
|
||||||
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
|
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
|
|
||||||
}
|
|
||||||
return __small_sprintf (destbuf, "%d (%s) %c "
|
return __small_sprintf (destbuf, "%d (%s) %c "
|
||||||
"%d %d %d %d %d "
|
"%d %d %d %d %d "
|
||||||
"%lu %lu %lu %lu %lu %lu %lu "
|
"%lu %lu %lu %lu %lu %lu %lu "
|
||||||
|
@ -137,6 +137,8 @@ getrlimit (int resource, struct rlimit *rlp)
|
|||||||
break;
|
break;
|
||||||
case RLIMIT_NOFILE:
|
case RLIMIT_NOFILE:
|
||||||
rlp->rlim_cur = getdtablesize ();
|
rlp->rlim_cur = getdtablesize ();
|
||||||
|
if (rlp->rlim_cur < OPEN_MAX)
|
||||||
|
rlp->rlim_cur = OPEN_MAX;
|
||||||
break;
|
break;
|
||||||
case RLIMIT_CORE:
|
case RLIMIT_CORE:
|
||||||
rlp->rlim_cur = rlim_core;
|
rlp->rlim_cur = rlim_core;
|
||||||
|
@ -35,7 +35,12 @@ sysconf (int in)
|
|||||||
case _SC_OPEN_MAX:
|
case _SC_OPEN_MAX:
|
||||||
return getdtablesize ();
|
return getdtablesize ();
|
||||||
case _SC_PAGESIZE:
|
case _SC_PAGESIZE:
|
||||||
return getpagesize ();
|
{
|
||||||
|
long max = getdtablesize ();
|
||||||
|
if (max < OPEN_MAX)
|
||||||
|
max = OPEN_MAX;
|
||||||
|
return max;
|
||||||
|
}
|
||||||
case _SC_CLK_TCK:
|
case _SC_CLK_TCK:
|
||||||
return CLOCKS_PER_SEC;
|
return CLOCKS_PER_SEC;
|
||||||
case _SC_JOB_CONTROL:
|
case _SC_JOB_CONTROL:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user