commit: 4ee7e06a57c9f47242d27ca3284c34389b7bd09a
parent f5211f99058183bea84be9463f3e579981881d33
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 19 Sep 2024 18:47:37 +0200
cmd/chown: unify error message formatting
Diffstat:
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/cmd/chown.c b/cmd/chown.c
@@ -54,7 +54,11 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
assert(errno == 0);
if(fstatat(fd, name, &stats, stat_opts) != 0)
{
- fprintf(stderr, "%s: Failed getting status for '%s': %s\n", argv0, acc_path, strerror(errno));
+ fprintf(stderr,
+ "%s: error: Failed getting status for '%s': %s\n",
+ argv0,
+ acc_path,
+ strerror(errno));
errno = 0;
return 1;
}
@@ -69,7 +73,7 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
if(fchownat(fd, name, user, group, chown_opts) != 0)
{
fprintf(stderr,
- "%s: Failed setting ownership to '%d:%d' for '%s': %s\n",
+ "%s: error: Failed setting ownership to '%d:%d' for '%s': %s\n",
argv0,
user,
group,
@@ -104,8 +108,11 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
int dir = openat(fd, name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if(dir == -1)
{
- fprintf(
- stderr, "%s: Couldn't open '%s' as directory: %s\n", argv0, acc_path, strerror(errno));
+ fprintf(stderr,
+ "%s: error: Couldn't open '%s' as directory: %s\n",
+ argv0,
+ acc_path,
+ strerror(errno));
errno = 0;
return 1;
}
@@ -115,7 +122,7 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
if(dirp == NULL)
{
fprintf(stderr,
- "%s: Couldn't get DIR entry for opened '%s': %s\n",
+ "%s: error: Couldn't get DIR entry for opened '%s': %s\n",
argv0,
acc_path,
strerror(errno));
@@ -131,8 +138,11 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
{
if(errno == 0) break;
- fprintf(
- stderr, "%s: Failed reading directory '%s': %s\n", argv0, acc_path, strerror(errno));
+ fprintf(stderr,
+ "%s: error: Failed reading directory '%s': %s\n",
+ argv0,
+ acc_path,
+ strerror(errno));
closedir(dirp); // FIXME: unhandled error
errno = 0;
return 1;
@@ -146,7 +156,7 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
if(snprintf(new_path, PATH_MAX, "%s/%s", acc_path, dp->d_name) < 0)
{
fprintf(stderr,
- "%s: Couldn't concatenate '%s' into parent '%s', skipping to next entry: %s",
+ "%s: error: Couldn't concatenate '%s' into parent '%s', skipping to next entry: %s",
argv0,
name,
acc_path,
@@ -169,7 +179,7 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo
if(closedir(dirp) != 0)
{
fprintf(stderr,
- "%s: Deallocating directory entry for '%s' failed: %s\n",
+ "%s: error: Deallocating directory entry for '%s' failed: %s\n",
argv0,
acc_path,
strerror(errno));
@@ -190,7 +200,8 @@ usage(void)
fprintf(stderr, "Usage: %s [-h | -R [-H|-L|-P]] group file...\n", argv0);
else
{
- fprintf(stderr, "%s: Unknown utility '%s' expected either chown or chgrp\n", argv0, argv0);
+ fprintf(
+ stderr, "%s: error: Unknown utility '%s' expected either chown or chgrp\n", argv0, argv0);
exit(1);
}
}
@@ -241,11 +252,11 @@ main(int argc, char *argv[])
opt_v = true;
break;
case ':':
- fprintf(stderr, "%s: Error: Missing operand for option: '-%c'\n", argv0, optopt);
+ fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt);
usage();
return 1;
case '?':
- fprintf(stderr, "%s: Error: Unrecognised option: '-%c'\n", argv0, optopt);
+ fprintf(stderr, "%s: error: Unrecognised option: '-%c'\n", argv0, optopt);
usage();
return 1;
default:
@@ -261,7 +272,7 @@ main(int argc, char *argv[])
if(argc < 2)
{
- fprintf(stderr, "%s: Expects >=2 arguments, %d given\n", argv0, argc);
+ fprintf(stderr, "%s: error: Expects >=2 arguments, %d given\n", argv0, argc);
usage();
return 1;
}
@@ -284,7 +295,8 @@ main(int argc, char *argv[])
}
else
{
- fprintf(stderr, "%s: Unknown utility '%s' expected either chown or chgrp\n", argv0, argv0);
+ fprintf(
+ stderr, "%s: error: Unknown utility '%s' expected either chown or chgrp\n", argv0, argv0);
return 1;
}
diff --git a/test-cmd/chown.t b/test-cmd/chown.t
@@ -8,7 +8,7 @@
$ test ! -f enoent
$ chown nobody:nogroup enoent
- chown: Failed getting status for 'enoent': No such file or directory
+ chown: error: Failed getting status for 'enoent': No such file or directory
[1]
$ touch id_unchanged