(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-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>
* rmsym: Don't use ranlib.
{
if (!c)
{
- __seterrno ();
+ set_errno (ENOMEM);
return NULL;
}
c->type = x;
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
if (c)
memset (c->data, 0, n);
+#ifdef DEBUGGING
if (!c)
system_printf ("ccalloc returned NULL");
+#endif
return creturn (x, c, n);
}
if (howmuch <= 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 ()
here to preserve old table if memory allocation fails */
if (!(newfds = (fhandler_base **) ccalloc (HEAP_ARGV, new_size, sizeof newfds[0])))
{
debug_printf ("calloc failed");
+ set_errno (ENOMEM);
return 0;
}
if (fds)
{
- memcpy (newfds, fds, size * sizeof (fds[0]));
cfree (fds);
+ memcpy (newfds, fds, size * sizeof (fds[0]));
}
size = new_size;
for (p = (char *) win32_name; (p = strchr (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);
return fd >= 0 ? (fds[fd] = fh) : fh;
in cases where the name is really required, the filename wouldn't ever
be too long (e.g. devices or some such).
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)
{
if (unix_path == NULL || !*unix_path)
- return;
+ return false;
if (win32_path)
win32_path_name = cstrdup (win32_path);
{
const char *fmt = get_native_name ();
char *w = (char *) cmalloc (HEAP_STR, strlen (fmt) + 16);
- __small_sprintf (w, fmt, unit);
+ if (w)
+ __small_sprintf (w, fmt, unit);
win32_path_name = w;
}
if (win32_path_name == NULL)
{
system_printf ("fatal error. strdup failed");
- exit (ENOMEM);
+ set_errno (ENOMEM);
+ return false;
}
assert (unix_path_name == NULL);
{
char *p = cstrdup (win32_path_name);
unix_path_name = p;
- while ((p = strchr (p, '\\')) != NULL)
- *p++ = '/';
+ if (p)
+ while ((p = strchr (p, '\\')) != NULL)
+ *p++ = '/';
if (unix_path)
cfree ((void *) unix_path);
}
if (unix_path_name == NULL)
{
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);
+ return true;
}
/* Detect if we are sitting at EOF for conditions where Windows
HANDLE read_state;
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);
fhandler_base (DWORD dev, int unit = 0);
state = 'T';
else if (wincap.is_winnt ())
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;
HANDLE hProcess;
ret, RtlNtStatusToDosError (ret));
return 0;
}
- fault_count = vmc.PageFaultCount;
- utime = put.UserTime.QuadPart * HZ / 10000000ULL;
- stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
+ fault_count = vmc.PageFaultCount;
+ utime = put.UserTime.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)
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL;
* Note: some older versions of procps are broken and can't cope
* with process start times > time(NULL).
*/
- start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
- priority = pbi.BasePriority;
- unsigned page_size = getpagesize ();
- vmsize = vmc.PagefileUsage;
- vmrss = vmc.WorkingSetSize / page_size;
- vmmaxrss = ql.MaximumWorkingSetSize / page_size;
- }
- else
- {
- start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
+ start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
+#endif
+ priority = pbi.BasePriority;
+ unsigned page_size = getpagesize ();
+ vmsize = vmc.PagefileUsage;
+ vmrss = vmc.WorkingSetSize / page_size;
+ vmmaxrss = ql.MaximumWorkingSetSize / page_size;
}
+
return __small_sprintf (destbuf, "%d (%s) %c "
"%d %d %d %d %d "
"%lu %lu %lu %lu %lu %lu %lu "
break;
case RLIMIT_NOFILE:
rlp->rlim_cur = getdtablesize ();
+ if (rlp->rlim_cur < OPEN_MAX)
+ rlp->rlim_cur = OPEN_MAX;
break;
case RLIMIT_CORE:
rlp->rlim_cur = rlim_core;
case _SC_OPEN_MAX:
return getdtablesize ();
case _SC_PAGESIZE:
- return getpagesize ();
+ {
+ long max = getdtablesize ();
+ if (max < OPEN_MAX)
+ max = OPEN_MAX;
+ return max;
+ }
case _SC_CLK_TCK:
return CLOCKS_PER_SEC;
case _SC_JOB_CONTROL: