Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/dialects/darwin/dlsof.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct lsof_context_dialect {
int nb_fds; /* bytes allocated to FDs */

# if DARWINV >= 900
int nb_threads; /* Threads bytes allocated */
int n_threads; /* Threads entries allocated */
uint64_t *threads; /* Thread buffer */
# endif /* DARWINV>=900 */

Expand All @@ -161,7 +161,7 @@ struct lsof_context_dialect {

# if DARWINV >= 900
# define Threads (ctx->dialect.threads)
# define NbThreads (ctx->dialect.nb_threads)
# define NThreads (ctx->dialect.n_threads)
# endif /* DARWINV>=900 */

# if defined(PROC_PIDLISTFILEPORTS)
Expand Down
26 changes: 8 additions & 18 deletions lib/dialects/darwin/dproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ static char copyright[] = "@(#) Copyright 2005-2007 Apple Inc. and Purdue "
#define PIDS_INCR (sizeof(int) * 32) /* PID space increment */
#define VIPS_INCR 16 /* Vips space increment */

#if DARWINV >= 900
# define THREADS_INCR (sizeof(uint64_t) * 32) /* Threads space increment */
#endif /* DARWINV>=900 */

#if defined(PROC_PIDLISTFILEPORTS)
# define FILEPORTS_INCR \
(sizeof(struct proc_fileportinfo) * 32) /* Fileports space increment \
Expand Down Expand Up @@ -692,30 +688,24 @@ static void process_threads(struct lsof_context *ctx, /* context */
int pid, /* PID */
uint32_t n) /* number of threads */
{
int i, nb, nt;
int i, nb, need, nt;
/*
* Make sure a thread buffer has been allocated.
*/
n += 10;
if (n > NbThreads) {
while (n > NbThreads) {
NbThreads += THREADS_INCR;
}
if (!Threads)
Threads = (uint64_t *)malloc((MALLOC_S)NbThreads);
else
Threads =
(uint64_t *)realloc((MALLOC_P *)Threads, (MALLOC_S)NbThreads);
if (!Threads) {
need = (int)n + 10;
if (need > NThreads) {
if (grow_array((void **)&Threads, &NThreads, sizeof(uint64_t),
need - NThreads)) {
(void)fprintf(stderr, "%s: can't allocate space for %d Threads\n",
Pn, (int)(NbThreads / sizeof(int *)));
Pn, need);
Error(ctx);
}
}
/*
* Get thread information for the process.
*/
nb = proc_pidinfo(pid, PROC_PIDLISTTHREADS, 0, Threads, NbThreads);
nb = proc_pidinfo(pid, PROC_PIDLISTTHREADS, 0, Threads,
(int)(NThreads * sizeof(uint64_t)));
if (nb <= 0) {
if (errno == ESRCH) {

Expand Down
Loading