[LTP] pty09: Cap RLIMIT_NOFILE-based slave PTY opens

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Thu Jul 9 12:33:23 CEST 2026


Hi Runli,

On Thu, 09 Jul 2026 15:49:23 +0800, Runli wrote:
> pty09: Cap RLIMIT_NOFILE-based slave PTY opens

>  	max_pid_num = limit.rlim_cur - count;
> +	if (max_pid_num > MAX_SLAVE_OPENS)
> +		max_pid_num = MAX_SLAVE_OPENS;
>  
>  	tst_res(TINFO, "Available number of pids: %u", max_pid_num);

After the cap fires, `max_pid_num` holds 4096 -- the test's self-imposed
limit -- but the TINFO label still says "Available number", which implies
the system's available FD count.

On a system where RLIMIT_NOFILE - open_fds is, say, 1048000, the output
would read "Available number of pids: 4096", which could mislead anyone
comparing it against the system limit.

Consider printing the uncapped available count and a separate note when
the cap applies, e.g.:

  tst_res(TINFO, "Available number of pids: %u (capped at %d)",
          max_pid_num, MAX_SLAVE_OPENS);

or split the TINFO into two calls -- one for the real available count
(computed before the cap), one confirming the cap was applied.

Verdict - Needs revision

Pre-existing issues:

1. `count_avail_pid()` and the variable `max_pid_num` both say "pid"
   but the code tracks file-descriptor slots, not PIDs.

2. In run(): `tst_res(TPASS, "pty has been opened %d times", max_pid_num)`
   uses %d for an unsigned int argument.

3. In run(): `int slavefd[max_pid_num]` is a VLA. If max_pid_num == 0
   (all FD slots occupied) the zero-length VLA is undefined behaviour.

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer


More information about the ltp mailing list