changeset 4931:26be3efbd346

6437648 svc.configd will dump core if svc_nonpersist.db fails the integrity check 6571620 svccfg repository command should fail if the given file doesn't exist
author pjung
date Thu, 23 Aug 2007 00:53:10 -0700
parents 7e43c592ee98
children cac85bf517af
files usr/src/cmd/svc/configd/backend.c usr/src/cmd/svc/svccfg/svccfg.y usr/src/cmd/svc/svccfg/svccfg_libscf.c
diffstat 3 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/svc/configd/backend.c	Wed Aug 22 17:10:01 2007 -0700
+++ b/usr/src/cmd/svc/configd/backend.c	Thu Aug 23 00:53:10 2007 -0700
@@ -1274,7 +1274,7 @@
 				    "%s\n", db_file, fname);
 			else
 				configd_critical(
-				    "%s: integrity check failed: %s\n",
+				    "%s: integrity check failed.\n",
 				    db_file);
 		} else {
 			(void) fprintf(stderr,
--- a/usr/src/cmd/svc/svccfg/svccfg.y	Wed Aug 22 17:10:01 2007 -0700
+++ b/usr/src/cmd/svc/svccfg/svccfg.y	Thu Aug 23 00:53:10 2007 -0700
@@ -18,8 +18,9 @@
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
- *
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -188,11 +189,26 @@
 	}
 	| SCC_EXTRACT error terminator	{ synerr(SCC_EXTRACT); return(0); }
 
-repository_cmd : SCC_REPOSITORY SCV_WORD terminator
+repository_cmd: SCC_REPOSITORY SCV_WORD terminator
 	{
-		lscf_set_repository($2);
+		if (strcmp($2, "-f") == 0) {
+			synerr(SCC_REPOSITORY);
+			return(0);
+		}
+		lscf_set_repository($2, 0);
 		free($2);
 	}
+	| SCC_REPOSITORY SCV_WORD SCV_WORD terminator
+	{
+		if (strcmp($2, "-f") == 0) {
+			lscf_set_repository($3, 1);
+			free($2);
+			free($3);
+		} else {
+			synerr(SCC_REPOSITORY);
+			return(0);
+		}
+	}
 	| SCC_REPOSITORY error terminator   { synerr(SCC_REPOSITORY); return(0); }
 
 inventory_cmd : SCC_INVENTORY SCV_WORD terminator
--- a/usr/src/cmd/svc/svccfg/svccfg_libscf.c	Wed Aug 22 17:10:01 2007 -0700
+++ b/usr/src/cmd/svc/svccfg/svccfg_libscf.c	Thu Aug 23 00:53:10 2007 -0700
@@ -796,14 +796,25 @@
 }
 
 void
-lscf_set_repository(const char *repfile)
+lscf_set_repository(const char *repfile, int force)
 {
 	repository_teardown();
 
-	if (est->sc_repo_filename != NULL)
+	if (est->sc_repo_filename != NULL) {
 		free((void *)est->sc_repo_filename);
-
-	est->sc_repo_filename = safe_strdup(repfile);
+		est->sc_repo_filename = NULL;
+	}
+
+	if ((force == 0) && (access(repfile, R_OK) != 0)) {
+		/*
+		 * Repository file does not exist
+		 * or has no read permission.
+		 */
+		warn(gettext("Cannot access \"%s\": %s\n"),
+		    repfile, strerror(errno));
+	} else {
+		est->sc_repo_filename = safe_strdup(repfile);
+	}
 
 	lscf_prep_hndl();
 }