Public bug reported:

Using uutils `chmod -R` with an invalid mode will spam standard error
with duplicate diagnostics.

Using `strace` to inject a successful return value from ioctl, so that
it the pipe into `wc` is treated as a terminal, we can see 31504 lines
are emitted to standard error:

```
$ lsb_release -rd
Description:    Ubuntu 26.10
Release:        26.10
$ chmod --version
chmod (uutils coreutils) 0.12.0
$ strace -e inject=ioctl:retval=0 -o /dev/null chmod -R invalid 
/home/collin/coreutils/ 2>&1 | wc -l
31504
```

It seems the warning is printed for every visited file:

```
$ strace -e inject=ioctl:retval=0 -o /dev/null chmod -R invalid 
/home/collin/coreutils/ 2>&1 | grep -F 'Help' | wc -l
3938
$ find /home/collin/coreutils | wc -l
3938
```

This also means that uutils `chmod` can take an unreasonably long time
to execute, depending on the number of files visited. Here are the
results from a minimal Docker image:

```
$ time chmod -R invalid /
[...]

real    0m4.364s
user    0m1.264s
sys     0m2.514s
$ strace -c chmod -R invalid /
[...]
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ------------------
 50.44    5.548258           9    615432           write
 19.83    2.181529          10    211320       218 statx
 10.14    1.115335           5    205144           umask
  8.50    0.935452           9    102582           newfstatat
  6.07    0.667635           6    102574           ioctl
  1.94    0.213929          10     20560           getdents64
  1.18    0.129649          12     10271         8 openat
  0.76    0.083392           8     10263           close
  0.60    0.066164           6     10262           fstat
  0.53    0.058565           5     10252           lseek
  0.00    0.000170           6        27           read
  0.00    0.000056           9         6           brk
  0.00    0.000034           3         9           rt_sigaction
  0.00    0.000022          22         1           munmap
  0.00    0.000019          19         1           readlink
  0.00    0.000018           6         3           sigaltstack
  0.00    0.000017           5         3           fcntl
  0.00    0.000014           0        52           mmap
  0.00    0.000014           1        13           mprotect
  0.00    0.000010           5         2         2 access
  0.00    0.000008           8         1           poll
  0.00    0.000007           7         1           sched_getaffinity
  0.00    0.000006           3         2           prlimit64
  0.00    0.000005           5         1           gettid
  0.00    0.000002           1         2           rt_sigprocmask
  0.00    0.000001           0         3           getrandom
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         2         1 statfs
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         1           set_tid_address
  0.00    0.000000           0         1           set_robust_list
  0.00    0.000000           0         1           rseq
------ ----------- ----------- --------- --------- ------------------
100.00   11.000311           8   1298794       229 total
```

In this case, GNU coreutils properly realizes there is nothing to do and
simply exits:

```
$ time gnuchmod -R invalid /
gnuchmod: invalid mode: 'invalid'
Try 'gnuchmod --help' for more information.

real    0m0.006s
user    0m0.000s
sys     0m0.002s
$ strace -c gnuchmod -R invalid /
gnuchmod: invalid mode: 'invalid'
Try 'gnuchmod --help' for more information.
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 55.00    0.000253         253         1           execve
 11.74    0.000054           6         8           mmap
  5.43    0.000025           6         4           write
  4.57    0.000021           7         3           mprotect
  3.70    0.000017           4         4           close
  3.48    0.000016           8         2           openat
  2.83    0.000013           4         3           brk
  2.83    0.000013           6         2           newfstatat
  1.74    0.000008           4         2           fstat
  1.74    0.000008           4         2           getrandom
  1.09    0.000005           5         1         1 access
  0.87    0.000004           4         1           read
  0.87    0.000004           4         1           fcntl
  0.87    0.000004           4         1           set_tid_address
  0.87    0.000004           4         1           set_robust_list
  0.87    0.000004           4         1           prlimit64
  0.87    0.000004           4         1           rseq
  0.65    0.000003           3         1           arch_prctl
------ ----------- ----------- --------- --------- ----------------
100.00    0.000460          11        39         1 total
```

** Affects: rust-coreutils (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2170507

Title:
  uutils `chmod -R` with an invalid mode spams standard error

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/rust-coreutils/+bug/2170507/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to