[PATCH v2 4/4] watchkey: skip if CONFIG_WATCH_QUEUE not set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Debian does not set CONFIG_WATCH_QUEUE, whereby pipe2(2) returns ENOPKG
for the option O_NOTIFICATION_PIPE.

Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>
---
v2:
   return ENOPKG when availability check fails
---
 tests/watchkey/test       | 11 ++++++++++-
 tests/watchkey/watchkey.c | 16 ++++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/tests/watchkey/test b/tests/watchkey/test
index f61ff78..3faba51 100755
--- a/tests/watchkey/test
+++ b/tests/watchkey/test
@@ -16,7 +16,16 @@ BEGIN {
         $v = " ";
     }
 
-    plan tests => 2;
+    $result = system "runcon -t test_watchkey_t $basedir/watchkey $v -c";
+
+    # check if O_NOTIFICATION_PIPE is supported - ENOPKG
+    if ( $result >> 8 eq 65 ) {
+        plan skip_all =>
+"pipe2(2) does not support O_NOTIFICATION_PIPE; CONFIG_WATCH_QUEUE probably not set";
+    }
+    else {
+        plan tests => 2;
+    }
 }
 
 $result = system "runcon -t test_watchkey_t $basedir/watchkey $v";
diff --git a/tests/watchkey/watchkey.c b/tests/watchkey/watchkey.c
index c7f3274..c5db313 100644
--- a/tests/watchkey/watchkey.c
+++ b/tests/watchkey/watchkey.c
@@ -27,8 +27,9 @@ static long keyctl_watch_key(int key, int watch_fd, int watch_id)
 static void print_usage(char *progname)
 {
 	fprintf(stderr,
-		"usage:  %s [-v]\n"
+		"usage:  %s [-cv]\n"
 		"Where:\n\t"
+		"-c  Check for availability.\n"
 		"-v  Print information.\n", progname);
 	exit(-1);
 }
@@ -37,10 +38,14 @@ int main(int argc, char **argv)
 {
 	int opt, fd, pipefd[2], result, save_errno;
 	char *context;
+	bool check = false;
 	bool verbose = false;
 
-	while ((opt = getopt(argc, argv, "v")) != -1) {
+	while ((opt = getopt(argc, argv, "cv")) != -1) {
 		switch (opt) {
+		case 'c':
+			check = true;
+			break;
 		case 'v':
 			verbose = true;
 			break;
@@ -60,6 +65,13 @@ int main(int argc, char **argv)
 		free(context);
 	}
 
+	if (check) {
+		result = pipe2(pipefd, O_NOTIFICATION_PIPE);
+		if (!result || errno != ENOPKG)
+			exit(0);
+		exit(ENOPKG);
+	}
+
 	result = pipe2(pipefd, O_NOTIFICATION_PIPE);
 	if (result < 0) {
 		fprintf(stderr, "Failed to create pipe2(2): %s\n",
-- 
2.36.1




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux