commit f5f43dbd5b577bae6ea80f52675c91c063df0548
parent 8f4b2e86892678a6916fffce142ac3807f563003
Author: Eivind Uggedal <eivind@uggedal.com>
Date: Fri, 8 May 2015 08:16:58 +0000
ln: exit non-zero when errors accured
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/ln.c b/ln.c
@@ -19,7 +19,8 @@ int
main(int argc, char *argv[])
{
char *fname, *to;
- int sflag = 0, fflag = 0, hasto = 0, dirfd = AT_FDCWD, flags = AT_SYMLINK_FOLLOW;
+ int sflag = 0, fflag = 0, hasto = 0, dirfd = AT_FDCWD, ret = 0,
+ flags = AT_SYMLINK_FOLLOW;
struct stat st, tost;
ARGBEGIN {
@@ -64,12 +65,14 @@ main(int argc, char *argv[])
if (!sflag) {
if (stat(*argv, &st) < 0) {
weprintf("stat %s:", *argv);
+ ret = 1;
continue;
} else if (fstatat(dirfd, to, &tost, AT_SYMLINK_NOFOLLOW) < 0) {
if (errno != ENOENT)
eprintf("stat %s:", to);
} else if (st.st_dev == tost.st_dev && st.st_ino == tost.st_ino) {
weprintf("%s and %s are the same file\n", *argv, *argv);
+ ret = 1;
continue;
}
}
@@ -78,8 +81,9 @@ main(int argc, char *argv[])
if ((!sflag ? linkat(AT_FDCWD, *argv, dirfd, to, flags)
: symlinkat(*argv, dirfd, to)) < 0) {
weprintf("%s %s <- %s:", fname, *argv, to);
+ ret = 1;
}
}
- return 0;
+ return ret;
}