Skip to content

Commit

Permalink
Consistency check on number of threads (solves issue #232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atoptool committed Feb 4, 2023
1 parent 72f361d commit ca9d6d9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions photoproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ photoproc(struct tstat *tasklist, int maxtask)
unsigned long
counttasks(void)
{
unsigned long nr=0;
unsigned long nrproc=0, nrthread=0;
char linebuf[256];
FILE *fp;
DIR *dirp;
Expand All @@ -383,7 +383,7 @@ counttasks(void)
{
if ( fgets(linebuf, sizeof(linebuf), fp) != NULL)
{
if ( sscanf(linebuf, "%*f %*f %*f %*d/%lu", &nr) < 1)
if ( sscanf(linebuf, "%*f %*f %*f %*d/%lu", &nrthread) < 1)
mcleanstop(53, "wrong /proc/loadavg\n");
}
else
Expand Down Expand Up @@ -412,15 +412,19 @@ counttasks(void)
** count subdirectory names under /proc starting with a digit
*/
if (isdigit(entp->d_name[0]))
nr++;
nrproc++;
}

closedir(dirp);

if ( chdir(origdir) == -1)
mcleanstop(53, "cannot change to %s\n", origdir);

return nr;
if (nrthread < nrproc)
mcleanstop(53, "#threads (%ld) < #procs (%ld)\n",
nrthread, nrproc);

return nrproc + nrthread;
}

/*
Expand Down

0 comments on commit ca9d6d9

Please sign in to comment.