POSIX 2024 added the -w option to tsort. Here is the description: -w Set the exit status to the number of cycles found in the input, or to an implementation-defined maximum if there are more cycles than that maximum. If no cycles are found, the exit status shall be zero unless another error occurs.
The rational adds some recommendations on behavior: At the time that the -w option was added to this standard, the only known implementation reported a maximum of 255 cycles via the exit status. This has the drawback that applications cannot distinguish, from the exit status, errors caused by cycles from other errors or (when tsort is executed from a shell) termination by a signal. Implementations are urged to set the implementation-defined maximum number of cycles reported via the exit status to at most 124, leaving values above that maximum through 125 for other errors, and leaving values 126 and greater to have the special meanings that the shell assigns to them. I'll have a look at implementing this behavior. But figured it was worth sending on bug-coreutils for tracking like the rest of the missing POSIX 2024 features. Collin [1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/tsort.html