[Pkg-shadow-commits] r1574 - in upstream/trunk: . src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Mon Dec 31 14:52:52 UTC 2007


Author: nekral-guest
Date: 2007-12-31 14:52:52 +0000 (Mon, 31 Dec 2007)
New Revision: 1574

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/chsh.c
Log:
Split process_flags() out of main().


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2007-12-31 14:37:24 UTC (rev 1573)
+++ upstream/trunk/ChangeLog	2007-12-31 14:52:52 UTC (rev 1574)
@@ -1,5 +1,9 @@
 2007-12-31  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/chsh.c: Split process_flags() out of main().
+
+2007-12-31  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/chfn.c: New function: process_flags() split out of main().
 	The flags variables are now global.
 	* src/chfn.c: New functions: check_perms(), update_gecos(),

Modified: upstream/trunk/src/chsh.c
===================================================================
--- upstream/trunk/src/chsh.c	2007-12-31 14:37:24 UTC (rev 1573)
+++ upstream/trunk/src/chsh.c	2007-12-31 14:52:52 UTC (rev 1574)
@@ -71,6 +71,7 @@
 static void new_fields (void);
 static int check_shell (const char *);
 static int restricted_shell (const char *);
+static void process_flags (int argc, char **argv);
 
 /*
  * usage - print command line syntax and exit
@@ -168,6 +169,46 @@
 }
 
 /*
+ *  * process_flags - parse the command line options
+ *
+ *	It will not return if an error is encountered.
+ */
+static void process_flags (int argc, char **argv)
+{
+	int option_index = 0;
+	int c;
+	static struct option long_options[] = {
+		{"help", no_argument, NULL, 'h'},
+		{"shell", required_argument, NULL, 's'},
+		{NULL, 0, NULL, '\0'}
+	};
+
+	while ((c =
+		getopt_long (argc, argv, "hs:", long_options,
+		             &option_index)) != -1) {
+		switch (c) {
+		case 'h':
+			usage ();
+			break;
+		case 's':
+			sflg++;
+			STRFCPY (loginsh, optarg);
+			break;
+		default:
+			usage ();
+		}
+	}
+
+	/*
+	 * There should be only one remaining argument at most and it should
+	 * be the user's name.
+	 */
+	if (argc > (optind + 1)) {
+		usage ();
+	}
+}
+
+/*
  * chsh - this command controls changes to the user's shell
  *
  *	The only supported option is -s which permits the the login shell to
@@ -204,44 +245,10 @@
 
 	OPENLOG ("chsh");
 
-	/*
-	 * There is only one option, but use getopt() anyway to
-	 * keep things consistent.
-	 */
-	{
-		int option_index = 0;
-		int c;
-		static struct option long_options[] = {
-			{"help", no_argument, NULL, 'h'},
-			{"shell", required_argument, NULL, 's'},
-			{NULL, 0, NULL, '\0'}
-		};
+	/* parse the command line options */
+	process_flags (argc, argv);
 
-		while ((c =
-			getopt_long (argc, argv, "hs:", long_options,
-				     &option_index)) != -1) {
-			switch (c) {
-			case 'h':
-				usage ();
-				break;
-			case 's':
-				sflg++;
-				STRFCPY (loginsh, optarg);
-				break;
-			default:
-				usage ();
-			}
-		}
-	}
-
 	/*
-	 * There should be only one remaining argument at most and it should
-	 * be the user's name.
-	 */
-	if (argc > optind + 1)
-		usage ();
-
-	/*
 	 * Get the name of the user to check. It is either the command line
 	 * name, or the name getlogin() returns.
 	 */




More information about the Pkg-shadow-commits mailing list