Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Feb 2012 15:32:02 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r232184 - head/tools/regression/fifo/fifo_misc
Message-ID:  <201202261532.q1QFW285071424@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Feb 26 15:32:02 2012
New Revision: 232184
URL: http://svn.freebsd.org/changeset/base/232184

Log:
  Check fchmod()/fchown() in fifo_misc test.

Modified:
  head/tools/regression/fifo/fifo_misc/fifo_misc.c

Modified: head/tools/regression/fifo/fifo_misc/fifo_misc.c
==============================================================================
--- head/tools/regression/fifo/fifo_misc/fifo_misc.c	Sun Feb 26 15:14:29 2012	(r232183)
+++ head/tools/regression/fifo/fifo_misc/fifo_misc.c	Sun Feb 26 15:32:02 2012	(r232184)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2005 Robert N. M. Watson
+ * Copyright (c) 2012 Jilles Tjoelker
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -223,6 +224,97 @@ test_ioctl(void)
 	cleanfifo("testfifo", reader_fd, writer_fd);
 }
 
+/*
+ * fchmod(2)/fchown(2) on FIFO should work.
+ */
+static void
+test_chmodchown(void)
+{
+	struct stat sb;
+	int reader_fd, writer_fd;
+	uid_t u;
+	gid_t g;
+
+	makefifo("testfifo", __func__);
+
+	if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) < 0) {
+		warn("%s: openfifo", __func__);
+		cleanfifo("testfifo", -1, -1);
+		exit(-1);
+	}
+
+	if (fchmod(reader_fd, 0666) != 0) {
+		warn("%s: fchmod", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (stat("testfifo", &sb) != 0) {
+		warn("%s: stat", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if ((sb.st_mode & 0777) != 0666) {
+		warnx("%s: stat chmod result", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (fstat(writer_fd, &sb) != 0) {
+		warn("%s: fstat", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if ((sb.st_mode & 0777) != 0666) {
+		warnx("%s: fstat chmod result", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (fchown(reader_fd, -1, -1) != 0) {
+		warn("%s: fchown 1", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	u = geteuid();
+	if (u == 0)
+		u = 1;
+	g = getegid();
+	if (fchown(reader_fd, u, g) != 0) {
+		warn("%s: fchown 2", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+	if (stat("testfifo", &sb) != 0) {
+		warn("%s: stat", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (sb.st_uid != u || sb.st_gid != g) {
+		warnx("%s: stat chown result", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (fstat(writer_fd, &sb) != 0) {
+		warn("%s: fstat", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (sb.st_uid != u || sb.st_gid != g) {
+		warnx("%s: fstat chown result", __func__);
+		cleanfifo("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	cleanfifo("testfifo", -1, -1);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -238,6 +330,7 @@ main(int argc, char *argv[])
 	test_lseek();
 	test_truncate();
 	test_ioctl();
+	test_chmodchown();
 
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202261532.q1QFW285071424>