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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Fri Aug 22 02:26:48 UTC 2008


Author: nekral-guest
Date: 2008-08-22 02:26:46 +0000 (Fri, 22 Aug 2008)
New Revision: 2278

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/grpck.c
   upstream/trunk/src/grpconv.c
Log:
	* src/grpck.c: Added function fail_exit(). Check failure to unlock
	files. Report errors to stderr and syslog, but continue.
	* src/grpconv.c: Check failure to unlock files. Report errors to
	stderr and syslog, but continue.

Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-08-22 02:24:29 UTC (rev 2277)
+++ upstream/trunk/ChangeLog	2008-08-22 02:26:46 UTC (rev 2278)
@@ -1,5 +1,12 @@
 2008-08-18  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/grpck.c: Added function fail_exit(). Check failure to unlock
+	files. Report errors to stderr and syslog, but continue.
+	* src/grpconv.c: Check failure to unlock files. Report errors to
+	stderr and syslog, but continue.
+
+2008-08-18  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/passwd.c: Check failure to unlock files. Report errors to
 	stderr and syslog, but continue.
 

Modified: upstream/trunk/src/grpck.c
===================================================================
--- upstream/trunk/src/grpck.c	2008-08-22 02:24:29 UTC (rev 2277)
+++ upstream/trunk/src/grpck.c	2008-08-22 02:26:46 UTC (rev 2278)
@@ -72,12 +72,15 @@
 static const char *sgr_file = SGROUP_FILE;
 static bool use_system_sgr_file = true;
 static bool is_shadow = false;
+static bool sgr_locked = false;
 #endif
+static bool gr_locked = false;
 /* Options */
 static bool read_only = false;
 static bool sort_mode = false;
 
 /* local function prototypes */
+static void fail_exit (int status);
 static void usage (void);
 static void delete_member (char **, const char *);
 static void process_flags (int argc, char **argv);
@@ -100,6 +103,34 @@
 #endif
 
 /*
+ * fail_exit - exit with an error code after unlocking files
+ */
+static void fail_exit (int status)
+{
+	if (gr_locked) {
+		if (gr_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
+			/* continue */
+		}
+	}
+
+#ifdef	SHADOWGRP
+	if (sgr_locked) {
+		if (sgr_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
+			/* continue */
+		}
+	}
+#endif
+
+	closelog ();
+
+	exit (status);
+}
+
+/*
  * usage - print syntax message and exit
  */
 static void usage (void)
@@ -214,16 +245,18 @@
 			fprintf (stderr,
 			         _("%s: cannot lock %s; try again later.\n"),
 			         Prog, grp_file);
-			closelog ();
-			exit (E_CANT_LOCK);
+			fail_exit (E_CANT_LOCK);
 		}
+		gr_locked = true;
 #ifdef	SHADOWGRP
-		if (is_shadow && (sgr_lock () == 0)) {
-			fprintf (stderr,
-			         _("%s: cannot lock %s; try again later.\n"),
-			         Prog, sgr_file);
-			closelog ();
-			exit (E_CANT_LOCK);
+		if (is_shadow) {
+			if (sgr_lock () == 0) {
+				fprintf (stderr,
+				         _("%s: cannot lock %s; try again later.\n"),
+				         Prog, sgr_file);
+				fail_exit (E_CANT_LOCK);
+			}
+			sgr_locked = true;
 		}
 #endif
 	}
@@ -238,8 +271,7 @@
 		if (use_system_grp_file) {
 			SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
 		}
-		closelog ();
-		exit (E_CANT_OPEN);
+		fail_exit (E_CANT_OPEN);
 	}
 #ifdef	SHADOWGRP
 	if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
@@ -248,8 +280,7 @@
 		if (use_system_sgr_file) {
 			SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
 		}
-		closelog ();
-		exit (E_CANT_OPEN);
+		fail_exit (E_CANT_OPEN);
 	}
 #endif
 }
@@ -271,13 +302,13 @@
 		if (gr_close () == 0) {
 			fprintf (stderr, _("%s: failure while writing changes to %s\n"),
 			         Prog, grp_file);
-			exit (E_CANT_UPDATE);
+			fail_exit (E_CANT_UPDATE);
 		}
 #ifdef	SHADOWGRP
 		if (is_shadow && (sgr_close () == 0)) {
 			fprintf (stderr, _("%s: failure while writing changes to %s\n"),
 			         Prog, sgr_file);
-			exit (E_CANT_UPDATE);
+			fail_exit (E_CANT_UPDATE);
 		}
 #endif
 	}
@@ -286,11 +317,23 @@
 	 * Don't be anti-social - unlock the files when you're done.
 	 */
 #ifdef	SHADOWGRP
-	if (is_shadow) {
-		sgr_unlock ();
+	if (sgr_locked) {
+		if (sgr_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
+			/* continue */
+		}
+		sgr_locked = false;
 	}
 #endif
-	(void) gr_unlock ();
+	if (gr_locked) {
+		if (gr_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
+			/* continue */
+		}
+		gr_locked = false;
+	}
 }
 
 /*
@@ -552,7 +595,7 @@
 						         _
 						         ("%s: can't update shadow entry for %s\n"),
 						         Prog, sg.sg_name);
-						exit (E_CANT_UPDATE);
+						fail_exit (E_CANT_UPDATE);
 					}
 					/* remove password from /etc/group */
 					gr = *grp;
@@ -562,7 +605,7 @@
 						         _
 						         ("%s: can't update entry for group %s\n"),
 						         Prog, gr.gr_name);
-						exit (E_CANT_UPDATE);
+						fail_exit (E_CANT_UPDATE);
 					}
 				}
 			} else {

Modified: upstream/trunk/src/grpconv.c
===================================================================
--- upstream/trunk/src/grpconv.c	2008-08-22 02:24:29 UTC (rev 2277)
+++ upstream/trunk/src/grpconv.c	2008-08-22 02:26:46 UTC (rev 2278)
@@ -62,11 +62,21 @@
 static void fail_exit (int status)
 {
 	if (gr_locked) {
-		gr_unlock ();
+		if (gr_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
+			/* continue */
+		}
 	}
+
 	if (sgr_locked) {
-		sgr_unlock ();
+		if (sgr_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
+			/* continue */
+		}
 	}
+
 	exit (status);
 }
 
@@ -186,8 +196,18 @@
 		         Prog, gr_dbname ());
 		fail_exit (3);
 	}
-	sgr_unlock ();
-	gr_unlock ();
+	if (sgr_unlock () == 0) {
+		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
+		SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
+		/* continue */
+	}
+	sgr_locked = false;
+	if (gr_unlock () == 0) {
+		fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
+		SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
+		/* continue */
+	}
+	gr_locked = false;
 
 	nscd_flush_cache ("group");
 




More information about the Pkg-shadow-commits mailing list