Skip to contentSkip to conversation

add version option to newrole

PATCH In review Glauber de Oliveira Costa 3 participants 5 messages Feb 8, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add version option to newrole

When trying to isolate a problem today, I missed a lot an version option (-v or such). This simple patch adds such an option.

If it's of interest, such an option may be added to whole policycoreutils package. (IMHO, it would be useful). With this possibility in mind, I decided to implement the version string in a separate version.h file, that could be included by other packages too.

Patch follows.

newrole/newrole.c +9 -3
diff -upNr policycoreutils-1.29.18/newrole/newrole.c policycoreutils-1.29.18.mine/newrole/newrole.c
@@ -10,7 +10,7 @@
  *
  * USAGE:
  *
- * newrole [ -r role ] [ -t type ] [ -l level ] [ -- args ]
+ * newrole [ -r role ] [ -t type ] [ -l level ] [ -v ] [ -- args ]
  *
  * BUILD OPTIONS:
  *
@@ -82,9 +82,10 @@
 #ifndef PACKAGE
 #define PACKAGE "policycoreutils"   /* the name of this package lang translation */
 #endif
+#include "version.h"
 
 /* USAGE_STRING describes the command-line args of this program. */
-#define USAGE_STRING "USAGE: newrole [ -r role ] [ -t type ] [ -l level ] [ -- args ]"
+#define USAGE_STRING "USAGE: newrole [ -r role ] [ -t type ] [ -l level ] [ -v ] [ -- args ]"
 
 #define DEFAULT_CONTEXT_SIZE 255  /* first guess at context size */
 
@@ -417,6 +418,7 @@ int main( int argc, char *argv[] ) {
     { "role", 1, 0, 'r' },
     { "type", 1, 0, 't' },
     { "level", 1, 0, 'l' },
+    { "version", 0, 0, 'v' },
     { NULL, 0, 0, 0 }
   };
   char *role_s = NULL;               /* role spec'd by user in argv[] */
@@ -465,11 +467,15 @@ int main( int argc, char *argv[] ) {
   }
 
   while (1) {
-    clflag=getopt_long(argc,argv,"r:t:l:",long_options,&flag_index);
+    clflag=getopt_long(argc,argv,"r:t:l:v",long_options,&flag_index);
     if (clflag == -1)
 	break;
     
     switch( clflag ) {
+    case 'v':
+	printf("newrole version %s\n",VERSION);
+	exit(0);
+	break;
     case 'r':
       /* If role_s is already set, the user spec'd multiple roles - bad. */
       if( role_s ) {
newrole/version.h +4 -0
diff -upNr policycoreutils-1.29.18/newrole/version.h policycoreutils-1.29.18.mine/newrole/version.h
@@ -0,0 +1,4 @@
+
+#ifndef VERSION
+#define VERSION "1.29.18"
+#endif
#1 lore raw
Quoted 9 lines · Glauber de Oliveira Costa

When trying to isolate a problem today, I missed a lot an version option (-v or such). This simple patch adds such an option.

If it's of interest, such an option may be added to whole policycoreutils package. (IMHO, it would be useful). With this possibility in mind, I decided to implement the version string in a separate version.h file, that could be included by other packages too.

Patch follows.

If we were going to do this, I'd auto-generate version.h from the already existing VERSION file, or just have the Makefile add -DVERSION= with the contents of the already existing VERSION file. Otherwise, we have to update both files. And this would only tell you the upstream base version, not the complete package version. Why not just run rpm -q -f /usr/bin/newrole? And rpm -V -f /usr/bin/newrole to check that it is unmodified from the package-provided version.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
In reply to Glauber de Oliveira Costa

newrole/newrole.c line 16

Quoted 10 lines
newrole/newrole.c +1 -1
@@ -10,7 +10,7 @@
 *
 * USAGE:
 *
- * newrole [ -r role ] [ -t type ] [ -l level ] [ -- args ]
+ * newrole [ -r role ] [ -t type ] [ -l level ] [ -v ] [ -- args ]
 *
 * BUILD OPTIONS:
 *

Args doesn't sound descriptive to me.

newrole/version.h line 4

Quoted 12 lines

diff -upNr policycoreutils-1.29.18/newrole/version.h policycoreutils-1.29.18.mine/newrole/version.h
--- policycoreutils-1.29.18/newrole/version.h 1969-12-31 21:00:00.000000000
-0300
+++ policycoreutils-1.29.18.mine/newrole/version.h 2006-02-07
16:15:47.000000000
-0200

newrole/version.h +4 -0
@@ -0,0 +1,4 @@
+
+#ifndef VERSION
+#define VERSION "1.29.18"
+#endif

Version is traditionally kept in config.h or the makefiles. The version isn't unique to newrole. there are other apps in the same package that have the same version number. If we do one, we should do them all and put the definition in a central location like the toplevel Makefile.

-Steve

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--
This message was distributed to subscribers of the selinux mailing 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 Stephen Smalley

Em Quarta 08 Fevereiro 2006 10:43, Stephen Smalley escreveu:

Quoted 11 lines · Glauber de Oliveira Costa
Quoted 9 lines

When trying to isolate a problem today, I missed a lot an version option (-v or such). This simple patch adds such an option.

If it's of interest, such an option may be added to whole policycoreutils package. (IMHO, it would be useful). With this possibility in mind, I decided to implement the version string in a separate version.h file, that could be included by other packages too.

Patch follows.

Quoted 7 lines

If we were going to do this, I'd auto-generate version.h from the already existing VERSION file, or just have the Makefile add -DVERSION= with the contents of the already existing VERSION file. Otherwise, we have to update both files. And this would only tell you the upstream base version, not the complete package version. Why not just run rpm -q -f /usr/bin/newrole? And rpm -V -f /usr/bin/newrole to check that it is unmodified from the package-provided version.

Thank you for your comments Stephen,

Agreed, auto-generating it from VERSION file would be my choice. I'll rewrite it this way. About running rpm --whatever, this does not work in all environments. Debian based distributions does not have this options (although they have their own dpkg versions of it), and there are always the scenario in which one may be experimenting with installations directly from source, in which package managers are not involved at all. After all, version options are quite common in programs in general.

glauber.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
In reply to Steve G

Steve, thanks a lot for your comments,

Em Quarta 08 Fevereiro 2006 11:06, Steve G escreveu:

Quoted 11 lines

newrole/newrole.c line 16

Quoted 9 lines
newrole/newrole.c +1 -1
@@ -10,7 +10,7 @@
 *
 * USAGE:
 *
- * newrole [ -r role ] [ -t type ] [ -l level ] [ -- args ]
+ * newrole [ -r role ] [ -t type ] [ -l level ] [ -v ] [ -- args ]
 *
 * BUILD OPTIONS:
 *

Args doesn't sound descriptive to me.

What do you suggest instead? -v is what is commonly associated with version options in most programs.

Quoted 9 lines
Quoted 9 lines

diff -upNr policycoreutils-1.29.18/newrole/version.h policycoreutils-1.29.18.mine/newrole/version.h
--- policycoreutils-1.29.18/newrole/version.h 1969-12-31
21:00:00.000000000 -0300
+++ policycoreutils-1.29.18.mine/newrole/version.h 2006-02-07
16:15:47.000000000
-0200

newrole/version.h +1 -0
@@ -0,0 +1,4 @@
+
Quoted 8 lines

newrole/version.h line 4

Quoted 3 lines
newrole/version.h +3 -0
+#ifndef VERSION
+#define VERSION "1.29.18"
+#endif

Version is traditionally kept in config.h or the makefiles. The version isn't unique to newrole. there are other apps in the same package that have the same version number. If we do one, we should do them all and put the definition in a central location like the toplevel Makefile.

See my mail. I stated that if the option is of interest, I may implement it in these other packages. This first patch was just an initial attempt. A version.h (though auto-generated as Stephen suggested) is still my choice. But I'll take a look about putting it in the Makefile. My main concern is being able to compile it from newrole (or whatever) directory, not from the top level one.

Quoted 1 line

-Steve

Thanks again,

glauber.

Quoted 4 lines

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.