aboutsummaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2024-08-30 22:07:12 +0200
committerFlorian Weimer <fweimer@redhat.com>2024-08-30 22:30:05 +0200
commit3844cdc33093dbe1e33ddb831eada9bdb4a482b9 (patch)
tree477bde2e73c514ffefdf8480496c5eaa12f0c67c /io
parent424d97be50488beb6196c0ff0bc3dfeb87b4281c (diff)
downloadglibc-3844cdc33093dbe1e33ddb831eada9bdb4a482b9.zip
glibc-3844cdc33093dbe1e33ddb831eada9bdb4a482b9.tar.gz
glibc-3844cdc33093dbe1e33ddb831eada9bdb4a482b9.tar.bz2
io: Fix destructive nature of tst-fchmod-errors
We must not change the permissions of /dev/null if running as root. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'io')
-rw-r--r--io/tst-fchmod-errors.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/io/tst-fchmod-errors.c b/io/tst-fchmod-errors.c
index ee15300..bf2a4c5 100644
--- a/io/tst-fchmod-errors.c
+++ b/io/tst-fchmod-errors.c
@@ -18,8 +18,10 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdio.h>
#include <support/check.h>
#include <support/xunistd.h>
+#include <unistd.h>
static int
do_test (void)
@@ -27,9 +29,14 @@ do_test (void)
{
/* Permissions on /dev/null (the opened descriptor) cannot be changed. */
int fd = xopen ("/dev/null", O_RDWR, 0);
- errno = 0;
- TEST_COMPARE (fchmod (fd, 0), -1);
- TEST_COMPARE (errno, EPERM);
+ if (getuid () == 0)
+ puts ("info: /dev/null fchmod test skipped because of root privileges");
+ else
+ {
+ errno = 0;
+ TEST_COMPARE (fchmod (fd, 0), -1);
+ TEST_COMPARE (errno, EPERM);
+ }
xclose (fd);
/* Now testing an invalid file descriptor. */