Skip to contentSkip to conversation

setfiles -q option?

DISCUSSION Russell Coker 2 participants 3 messages May 9, 2002 – May 14, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

Could we have a "-q" option to setfiles to make it not write out messages such as the following?

/usr/sbin/setfiles:  Running on a SELinux kernel, using new system calls
/usr/sbin/setfiles:  read 450 specifications
/usr/sbin/setfiles:  Done.

Having it write out messages if it's not running on a SE Linux kernel would still be useful. But when you install 100 new packages having the above three lines displayed 100 times is rather annoying...

Signature · 9 lines
If you send email to me or to a mailing list that I use which has >4 lines
of legalistic junk at the end then you are specifically authorizing me to do
whatever I wish with the message and all other messages from your domain, by
posting the message you agree that your long legalistic sig is void.

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 10 lines · Russell Coker

Could we have a "-q" option to setfiles to make it not write out messages such as the following?

/usr/sbin/setfiles:  Running on a SELinux kernel, using new system calls
/usr/sbin/setfiles:  read 450 specifications
/usr/sbin/setfiles:  Done.

Having it write out messages if it's not running on a SE Linux kernel would still be useful. But when you install 100 new packages having the above three lines displayed 100 times is rather annoying...

We could certainly add such an option. Or you could just redirect stdout to /dev/null.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
In reply to Russell Coker
Quoted 10 lines · Russell Coker

Could we have a "-q" option to setfiles to make it not write out messages such as the following?

/usr/sbin/setfiles:  Running on a SELinux kernel, using new system calls
/usr/sbin/setfiles:  read 450 specifications
/usr/sbin/setfiles:  Done.

Having it write out messages if it's not running on a SE Linux kernel would still be useful. But when you install 100 new packages having the above three lines displayed 100 times is rather annoying...

Patch attached, and committed to the sourceforge CVS.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: setfiles/setfiles.8
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/setfiles/setfiles.8,v retrieving revision 1.1.1.1
retrieving revision 1.2

setfiles.8 +4 -1
diff -u -r1.1.1.1 -r1.2
@@ -4,7 +4,7 @@
 
 .SH "SYNOPSIS"
 .B setfiles
-.I [\-d] [\-n] [\-s] [\-v] [\-R] [\-W] spec_file pathname...
+.I [\-d] [\-n] [\-q] [\-s] [\-v] [\-R] [\-W] spec_file pathname...
 
 .SH "DESCRIPTION"
 This manual page describes the
@@ -26,6 +26,9 @@
 .TP 
 .B \-n
 don't change any file labels.
+.TP 
+.B \-q
+suppress non-error output.
 .TP 
 .B \-s
 take a list of files from standard input instead of using a pathname on the

Index: setfiles/setfiles.c
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/setfiles/setfiles.c,v retrieving revision 1.1.1.3
retrieving revision 1.2

setfiles.c +20 -17
diff -u -r1.1.1.3 -r1.2
@@ -12,7 +12,7 @@
  * the user.  The program does not cross file system boundaries.
  *
  * USAGE:
- * setfiles [-dnsvRW] spec_file pathname...
+ * setfiles [-dnqsvRW] spec_file pathname...
  * 
  * -d   Show what specification matched each file.
  * -n	Do not change any file labels.
@@ -21,6 +21,7 @@
  * -R   Recreate the persistent label mappings from scratch.
  *      Must reboot to take affect.
  * -W   Warn about entries that have no matching file.
+ * -q   Be quiet (suppress non-error output).
  * spec_file	The specification file.
  * pathname...	The file systems to label.	
  *
@@ -86,6 +87,9 @@
 static int reset = 0;
 static int use_stdin = 0;
 
+static int quiet = 0;
+#define QPRINTF(args...) do { if (!quiet) printf(args); } while (0)
+
 /*
  * Program name and error message buffer.
  */
@@ -226,7 +230,7 @@
 		nel += len;
 	}
 
-	printf
+	QPRINTF
 	    ("%s:  hash table stats: %d elements, %d/%d buckets used, longest chain length %d\n",
 	     progname, nel, used, HASH_BUCKETS, longest);
 }
@@ -463,15 +467,11 @@
 	struct stat sb;
 
 	/* Process any options. */
-	while ((opt = getopt(argc, argv, "dmnsvRW")) > 0) {
+	while ((opt = getopt(argc, argv, "dnqsvRW")) > 0) {
 		switch (opt) {
 		case 'd':
 			debug = 1;
 			break;
-		case 'm':
-			/* This is now the default. 
-			   Accept it for compatibility. */
-			break;
 		case 'W':
 			warn_no_match = 1;
 			break;
@@ -488,6 +488,9 @@
 			use_stdin = 1;
 			add_assoc = 0;
 			break;
+		case 'q':
+			quiet = 1;
+			break;
 		}
 	}
 
@@ -497,7 +500,7 @@
 		if (optind != (argc - 1) || reset) {
 			/* Cannot mix with pathname arguments or -R option. */
 			fprintf(stderr,
-				"usage:  %s [-dnsvW] spec_file\n", argv[0]);
+				"usage:  %s [-dnqsvW] spec_file\n", argv[0]);
 			exit(1);
 		}
 		if (!flask_enabled) {
@@ -509,22 +512,22 @@
 	} else {
 		if (optind > (argc - 2)) {
 			fprintf(stderr,
-				"usage:  %s [-dnvRW] spec_file pathname...\n",
+				"usage:  %s [-dnqvRW] spec_file pathname...\n",
 				argv[0]);
 			exit(1);
 		}
 	}
 
 	if (reset) {
-		printf("%s:  Recreating persistent label mappings from scratch.\n", argv[0]);
+		QPRINTF("%s:  Recreating persistent label mappings from scratch.\n", argv[0]);
                 /* Do not use the new syscalls, even if running on SELinux,
 		   since they will access the old persistent label mappings. */
 		flask_enabled = 0; 
 	} else {
 		if (flask_enabled) 
-			printf("%s:  Running on a SELinux kernel, using new system calls\n", argv[0]);
+			QPRINTF("%s:  Running on a SELinux kernel, using new system calls\n", argv[0]);
 		else 
-			printf("%s:  Running on a non-SELinux kernel, directly accessing persistent label mapping\n", argv[0]);
+			QPRINTF("%s:  Running on a non-SELinux kernel, directly accessing persistent label mapping\n", argv[0]);
 	}
 
 	/* Open the specification file. */
@@ -689,7 +692,7 @@
 			exit(1);
 
 		if (pass == 0) {
-			printf("%s:  read %d specifications\n", argv[0],
+			QPRINTF("%s:  read %d specifications\n", argv[0],
 			       nspec);
 			if (nspec == 0)
 				exit(0);
@@ -744,7 +747,7 @@
 	{
 
 		if (flask_enabled) {
-			printf("%s:  labeling files under %s\n", argv[0],
+			QPRINTF("%s:  labeling files under %s\n", argv[0],
 			       argv[optind]);
 		} else {
 			sprintf(pathname, "%s/%s", argv[optind], ".");
@@ -754,7 +757,7 @@
 			else
 				context = spec[i].context;
 
-			printf("%s:  labeling files under %s (default file context %s)\n", argv[0],
+			QPRINTF("%s:  labeling files under %s (default file context %s)\n", argv[0],
 			       argv[optind], context);
 
 			psids = psidtab_init(argv[optind], context, FS_CONTEXT, reset);
@@ -808,9 +811,9 @@
 	}
 
 	if (!flask_enabled) {
-		printf("%s:  Done.  Please %sboot your SELinux kernel and then run 'make relabel' to relabel any files that were created during the shutdown.\n", argv[0], reset ? "re" : "");
+		QPRINTF("%s:  Done.  Please %sboot your SELinux kernel and then run 'make relabel' to relabel any files that were created during the shutdown.\n", argv[0], reset ? "re" : "");
 	} else {
-		printf("%s:  Done.\n", argv[0]);
+		QPRINTF("%s:  Done.\n", argv[0]);
 	}
 
 	exit(0);