From owner-freebsd-bugs Sun Jul 12 17:00:28 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA08063 for freebsd-bugs-outgoing; Sun, 12 Jul 1998 17:00:28 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA08053 for ; Sun, 12 Jul 1998 17:00:24 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id RAA11702; Sun, 12 Jul 1998 17:00:01 -0700 (PDT) Received: from mail.camalott.com (root@mail.camalott.com [208.203.140.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA07868 for ; Sun, 12 Jul 1998 16:59:09 -0700 (PDT) (envelope-from joelh@gnu.org) Received: from detlev.UUCP (tex-69.camalott.com [208.229.74.69]) by mail.camalott.com (8.8.7/8.8.5) with ESMTP id SAA31901 for ; Sun, 12 Jul 1998 18:59:48 -0500 Received: (from joelh@localhost) by detlev.UUCP (8.8.8/8.8.8) id SAA03409; Sun, 12 Jul 1998 18:55:03 -0500 (CDT) (envelope-from joelh) Message-Id: <199807122355.SAA03409@detlev.UUCP> Date: Sun, 12 Jul 1998 18:55:03 -0500 (CDT) From: Joel Ray Holveck Reply-To: joelh@gnu.org To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: bin/7265: [patch] Improvement of ln(1) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 7265 >Category: bin >Synopsis: A warning flag is added to ln(1). >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jul 12 17:00:01 PDT 1998 >Last-Modified: >Originator: Joel Ray Holveck >Organization: Little to none. >Release: FreeBSD 3.0-CURRENT i386 >Environment: June 28 3.0-current. >Description: It is easy at 4:00 AM to give, to ln -s, a target relative to the current path rather than the source's path. (source and target are here used as in the source, ie, the source and target of the eventual resulting symlink.) No facilities are provided to allow for warnings. (For more information, please see the flamefest^H^H^H^H^H^H^H^H^H^H thread in freebsd-current entitled 'Improvemnet of ln(1).' Note that the fix proposed here is markedly different than what was originally proposed by the originator of said thread, as well as my own proposal.) >How-To-Repeat: # cd /usr # ln -s src/sys /sys # cd /sys /sys: No such file or directory. (Emit the anguished wails of a tired sysadmin who thinks he's just lost his kernel source. Repeating this last step is optional.) >Fix: A new flag, -w, is proposed. If the symlink created would be invalid, and the -w flag is specified, a warning is emitted to stderr. ----- cut here ----- *** ln.1-orig Sun Jul 12 18:02:09 1998 --- ln.1 Sun Jul 12 18:36:43 1998 *************** *** 72,77 **** --- 72,79 ---- Unlink any already existing file, permitting the link to occur. .It Fl s Create a symbolic link. + .It Fl w + Warn if the target of a symbolic link does not currently exist. .El .Pp By default *** ln.c-orig Sun Jul 12 18:02:06 1998 --- ln.c Sun Jul 12 18:42:42 1998 *************** *** 57,62 **** --- 57,63 ---- int fflag; /* Unlink existing files. */ int sflag; /* Symbolic, not hard, link. */ + int wflag; /* Warn if dest does not exist. */ /* System link call. */ int (*linkf) __P((const char *, const char *)); *************** *** 73,79 **** int ch, exitval; char *sourcedir; ! while ((ch = getopt(argc, argv, "fs")) != -1) switch (ch) { case 'f': fflag = 1; --- 74,80 ---- int ch, exitval; char *sourcedir; ! while ((ch = getopt(argc, argv, "fsw")) != -1) switch (ch) { case 'f': fflag = 1; *************** *** 81,86 **** --- 82,90 ---- case 's': sflag = 1; break; + case 'w': + wflag = 1; + break; case '?': default: usage(); *************** *** 117,123 **** { struct stat sb; int exists; ! char *p, path[MAXPATHLEN]; if (!sflag) { /* If target doesn't exist, quit now. */ --- 121,127 ---- { struct stat sb; int exists; ! char *p, path[MAXPATHLEN], *st, wbuf[MAXPATHLEN]; if (!sflag) { /* If target doesn't exist, quit now. */ *************** *** 146,151 **** --- 150,183 ---- exists = !lstat(source, &sb); /* + * If the target doesn't exist, and a symbolic link was + * requested, and -w was specified, give a warning. + */ + if (sflag && wflag) { + if (*target == '/') + /* Absolute target */ + st = target; + else { + /* Relative target */ + st = strdup(source); + if (!st) { + warnx("-w: Cannot allocate memory (continuing)"); + goto nowarn; + } + p = strrchr(st, '/'); + * (p ? p+1 : st) = '\0'; + (void)snprintf(wbuf, sizeof(wbuf), "%s%s", st, + target); + free(st); + st = wbuf; + } + if (stat(st, &sb)) + warn("warning: %s inaccessible relative to %s", + target, source); + } + nowarn: + + /* * If the file exists, and -f was specified, unlink it. * Attempt the link. */ *************** *** 160,166 **** usage() { (void)fprintf(stderr, "%s\n%s\n", ! "usage: ln [-fs] file1 file2", ! " ln [-fs] file ... directory"); exit(1); } --- 192,198 ---- usage() { (void)fprintf(stderr, "%s\n%s\n", ! "usage: ln [-fsw] file1 file2", ! " ln [-fsw] file ... directory"); exit(1); } ----- cut here ----- >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message