[Bug 191974] |ln -sF| never calls rmdir(2) on target_file == target_dir, only target_dir/basename

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Jul 20 06:51:04 UTC 2014


bycn82 at gmail.com changed:

           What    |Removed                     |Added
                 CC|                            |bycn82 at gmail.com

--- Comment #1 from bycn82 at gmail.com ---
I checked the source code of the ln, I agree with him, something wrong there! 

the main logic are here.
    switch(argc) {
    case 0:
        /* NOTREACHED */
    case 1:                /* ln source */
        exit(linkit(argv[0], ".", 1));
    case 2:                /* ln source target */
        exit(linkit(argv[0], argv[1], 0));
        /* ln source1 source2 directory */

I did the below test with my explanation.

root at FBHead:~ # uname -a
FreeBSD FBHead 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r268881: Sun Jul 20
01:32:21 UTC 2014     root at FBHead:/usr/obj/usr/src/sys/GENERIC  amd64

root at FBHead:~ # ln -s -F
usage: ln [-s [-F] | -L | -P] [-f | -i] [-hnv] source_file [target_file]
       ln [-s [-F] | -L | -P] [-f | -i] [-hnv] source_file ... target_dir
       link source_file target_file
the argc==0, so show the usage.

root at FBHead:~ # ln -s -F foo
root at FBHead:~ # ls -al foo
lrwxr-xr-x  1 root  wheel  3 Jul 20 04:42 foo -> foo

according to the logic, the argc==1, so it will call linkit(argv[0], ".", 1) so
the result will be foo->foo, it will be useless, because it will delete the
current foo and create the new foo soft link with link to itself!!!

root at FBHead:~ # rm foo
root at FBHead:~ # touch foo
root at FBHead:~ # mkdir bar
root at FBHead:~ # ln -s -F foo bar
root at FBHead:~ # ls -al bar/foo 
lrwxr-xr-x  1 root  wheel  3 Jul 20 04:47 bar/foo -> foo
here the argc==2, so it will call linkit(argv[0], argv[1], 0)
and the 3rd parameter "0" means the argv[1] is not a directory!!
anyway, the result is not correct, 

root at FBHead:~ # ln -s -F foo1 foo2 bar
in this case, the argc is not 0 1 2 , so it will be go to default: and
continue, actually it will just loop the parameters and call linkit, the result
will be same as previous one.

all this are not make sense!!! the -F in the man page also bullshit! I think
all this features are the same on other systems for example Linux or other BSD
systems. because the code are not new created. already there for long long !!!

anyway, I dont recommend to make changes in the source code immediately, but
update the document first. make it clear about how it works. what do you guys
think ?

You are receiving this mail because:
You are the assignee for the bug.

More information about the freebsd-bugs mailing list