| Use link(2) or unlink(2) directly if ln(1) or rm(1) was started with such names. |
| |
| diff -ru --exclude-from freebsd-src-diff-exclude-names /var/tmp/freebsd-src/usr/src/bin/ln/ln.c freebsd-10.3/usr/src/bin/ln/ln.c |
| --- /var/tmp/freebsd-src/usr/src/bin/ln/ln.c 2016-03-25 09:10:00.000000000 +0800 |
| +++ freebsd-10.3/usr/src/bin/ln/ln.c 2017-02-07 20:47:39.995446910 +0800 |
| @@ -91,7 +91,13 @@ |
| argv += optind; |
| if (argc != 2) |
| usage(); |
| - exit(linkit(argv[0], argv[1], 0)); |
| + //exit(linkit(argv[0], argv[1], 0)); |
| + // The link(2) syscall should be used directly |
| + if(link(argv[0], argv[1]) < 0) { |
| + fprintf(stderr, "link: %s -> %s: %s\n", argv[0], argv[1], strerror(errno)); |
| + return 1; |
| + } |
| + return 0; |
| } |
| |
| while ((ch = getopt(argc, argv, "FLPfhinsvw")) != -1) |
| diff -ru --exclude-from freebsd-src-diff-exclude-names /var/tmp/freebsd-src/usr/src/bin/rm/rm.c freebsd-10.3/usr/src/bin/rm/rm.c |
| --- /var/tmp/freebsd-src/usr/src/bin/rm/rm.c 2016-03-25 09:10:00.000000000 +0800 |
| +++ freebsd-10.3/usr/src/bin/rm/rm.c 2017-02-07 20:40:56.956521533 +0800 |
| @@ -105,8 +105,14 @@ |
| argv += optind; |
| if (argc != 1) |
| usage(); |
| - rm_file(&argv[0]); |
| - exit(eval); |
| + //rm_file(&argv[0]); |
| + //exit(eval); |
| + // If this program is called 'unlink', then the unlink(2) syscall should be used directly |
| + if(unlink(*argv) < 0) { |
| + perror(*argv); |
| + return 1; |
| + } |
| + return 0; |
| } |
| |
| Pflag = rflag = xflag = 0; |