Option -f for /bin/ln broken

Hi,

trying to implement a atomic switch of a configuration through /bin/ln I found that the option '-f' is not working as expected. The example below shows that /bin/ln actually instead of updating the where f points to makes a link within f. That's not the behavior expected. On debian this actually makes f point to the new location.

root@Vx86:~# ln -v -s /etc/freeradius3 f
'f' -> '/etc/freeradius3'
root@Vx86:~# ls -al f
lrwxrwxrwx    1 root     root            16 Jun 26 07:51 f -> /etc/freeradius3
root@Vx86:~# ln -v -f -s /etc/freeradius3-md f
'f/freeradius3-md' -> '/etc/freeradius3-md'
root@Vx86:~# ls -al f
lrwxrwxrwx    1 root     root            16 Jun 26 07:51 f -> /etc/freeradius3
root@NW-ONPREM-CONTROLLER-Vx86:~# ls -al f/freeradius3-md
lrwxrwxrwx    1 root     root            19 Jun 26 07:51 freeradius3-md -> /etc/freeradius3-md

The release I'm testing with was build with the imagebuilder:

root@NW-ONPREM-CONTROLLER-Vx86:~# cat /etc/openwrt_release 
DISTRIB_ID='OpenWrt'
DISTRIB_RELEASE='21.02.0-rc3'
DISTRIB_REVISION='r16172-2aba3e9784'
DISTRIB_TARGET='x86/64'
DISTRIB_ARCH='x86_64'

any ideas?

Maybe this is a shortcoming in the default busybox ln?
In that case opkg update; opkg install coreutils-ln might get you a more complete ln binary...

root@turris:~# ls $( which ln ) -all
lrwxrwxrwx    1 root     root             7 May 14 13:11 /bin/ln -> busybox
root@turris:~# opkg install coreutils-ln
Installing coreutils-ln (8.30-2) to root...
Downloading https://repo.turris.cz/hbs/omnia/packages/packages/coreutils-ln_8.30-2_arm_cortex-a9_vfpv3-d16.ipk
Configuring coreutils-ln.
root@turris:~# ls $( which ln ) -all
lrwxrwxrwx    1 root     root            15 Jun 26 11:44 /bin/ln -> /usr/bin/gnu-ln
2 Likes

my fault. I was missing the option -T to ln since i am dealing with directories:

from ln --help

  -T, --no-target-directory   treat LINK_NAME as a normal file always

that actually does solve the problem. I can now easily atomically switch between directories.

root@nglr-d1000m-testme-schroty:~/test# ls -al
drwxr-xr-x    4 root     root          1024 Jun 27 18:34 .
drwxr-xr-x    1 root     root          1024 Jun 27 18:32 ..
lrwxrwxrwx    1 root     root             9 Jun 27 18:34 etc -> etc-2020/
drwxr-xr-x    2 root     root          1024 Jun 27 18:33 etc-2020
drwxr-xr-x    2 root     root          1024 Jun 27 18:34 etc-3302
root@nglr-d1000m-testme-schroty:~/test# ln -T -s etc-3302/ etc
ln: failed to create symbolic link 'etc': File exists
root@nglr-d1000m-testme-schroty:~/test# ln -f -T -s etc-3302/ etc
root@nglr-d1000m-testme-schroty:~/test# ls -al
drwxr-xr-x    4 root     root          1024 Jun 27 18:34 .
drwxr-xr-x    1 root     root          1024 Jun 27 18:32 ..
lrwxrwxrwx    1 root     root             9 Jun 27 18:34 etc -> etc-3302/
drwxr-xr-x    2 root     root          1024 Jun 27 18:33 etc-2020
drwxr-xr-x    2 root     root          1024 Jun 27 18:34 etc-3302
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.