Re: [LTP] [PATCH v2 5/5] swapon03: Remove grep dependency

Petr Vorel
2025-11-14T12:09:58Z

> Hi!
> > This change requires to normalize TMPDIR via realpath() otherwise grep will
> > fail. Either in the test or in the library [1] (I'll submit it separately, no
> > need to be part of Wei's cleanup).

> I was wondering if we can avoid matching the full path. Maybe we can
> just do strstr() on the line from the /proc/mounts matching the filename
> before we attempt to do the scanf().

Do you mean to use full swap file path from /proc/mounts, i.e.
/tmp/LTP_swaNzeMJr/mntpoint/testswap, /tmp/LTP_swamEVVAc/mntpoint/testswap03,
... (example from run which created /tmp/LTP_swamEVVAc with all swap files,
cleanup interrupted by ctrl+C and following one which created /tmp/LTP_swaNzeMJr
single swap file only):

# cat /proc/swaps
Filename Type Size Used Priority
/dev/vda3 partition 2098152 0 -2
/tmp/LTP_swaNzeMJr/mntpoint/testswap file 1004 0 -25
/tmp/LTP_swamEVVAc/mntpoint/testswap03 file 1000 0 -3
/tmp/LTP_swamEVVAc/mntpoint/testswap04 file 1000 0 -4
/tmp/LTP_swamEVVAc/mntpoint/testswap05 file 1000 0 -5
/tmp/LTP_swamEVVAc/mntpoint/testswap06 file 1000 0 -6
/tmp/LTP_swamEVVAc/mntpoint/testswap07 file 996 0 -7
/tmp/LTP_swamEVVAc/mntpoint/testswap08 file 996 0 -8
/tmp/LTP_swamEVVAc/mntpoint/testswap09 file 996 0 -9
/tmp/LTP_swamEVVAc/mntpoint/testswap10 file 1000 0 -10
/tmp/LTP_swamEVVAc/mntpoint/testswap11 file 1000 0 -11
/tmp/LTP_swamEVVAc/mntpoint/testswap12 file 1000 0 -12
/tmp/LTP_swamEVVAc/mntpoint/testswap13 file 1000 0 -13
/tmp/LTP_swamEVVAc/mntpoint/testswap14 file 1000 0 -14
/tmp/LTP_swamEVVAc/mntpoint/testswap15 file 1000 0 -15
/tmp/LTP_swamEVVAc/mntpoint/testswap16 file 996 0 -16
/tmp/LTP_swamEVVAc/mntpoint/testswap17 file 996 0 -17
/tmp/LTP_swamEVVAc/mntpoint/testswap18 file 996 0 -18
/tmp/LTP_swamEVVAc/mntpoint/testswap19 file 1000 0 -19
/tmp/LTP_swamEVVAc/mntpoint/testswap20 file 1000 0 -20
/tmp/LTP_swamEVVAc/mntpoint/testswap21 file 1000 0 -21
/tmp/LTP_swamEVVAc/mntpoint/testswap22 file 1000 0 -22
/tmp/LTP_swamEVVAc/mntpoint/testswap23 file 1000 0 -23
/tmp/LTP_swamEVVAc/mntpoint/testswap file 1000 0 -24

This way would swapoff all LTP swaps including possible previous ones.

Kind regards,
Petr