[Midnightbsd-cvs] src [7650] stable/0.8/lib/libmport/bundle_read_install_pkg.c: in several cases we are not properly setting an error condition so the library is not returning a failure of the installation.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 30 21:27:03 EDT 2016


Revision: 7650
          http://svnweb.midnightbsd.org/src/?rev=7650
Author:   laffer1
Date:     2016-07-30 21:27:03 -0400 (Sat, 30 Jul 2016)
Log Message:
-----------
in several cases we are not properly setting an error condition so the library is not returning a failure of the installation. fix that.

Modified Paths:
--------------
    stable/0.8/lib/libmport/bundle_read_install_pkg.c

Modified: stable/0.8/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- stable/0.8/lib/libmport/bundle_read_install_pkg.c	2016-07-31 01:25:45 UTC (rev 7649)
+++ stable/0.8/lib/libmport/bundle_read_install_pkg.c	2016-07-31 01:27:03 UTC (rev 7650)
@@ -56,14 +56,17 @@
 int
 mport_bundle_read_install_pkg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
 {
-    if (do_pre_install(mport, bundle, pkg) != MPORT_OK)
+    if (do_pre_install(mport, bundle, pkg) != MPORT_OK) {
         RETURN_CURRENT_ERROR;
+    }
 
-    if (do_actual_install(mport, bundle, pkg) != MPORT_OK)
+    if (do_actual_install(mport, bundle, pkg) != MPORT_OK) {
         RETURN_CURRENT_ERROR;
+    }
 
-    if (do_post_install(mport, bundle, pkg) != MPORT_OK)
+    if (do_post_install(mport, bundle, pkg) != MPORT_OK) {
         RETURN_CURRENT_ERROR;
+    }
 
     syslog(LOG_NOTICE, "%s-%s installed", pkg->name, pkg->version);
 
@@ -277,14 +280,20 @@
                            goto ERROR;
 		}
 	        if (fm_owner != NULL && fm_group != NULL && fm_owner[0] != '\0' && fm_group[0] != '\0') {
-			if (chown(data, mport_get_uid(fm_owner), mport_get_gid(fm_group)) == -1)
+			if (chown(data, mport_get_uid(fm_owner), mport_get_gid(fm_group)) == -1) {
+				SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 				goto ERROR;
+			}
                 } else if (fm_owner != NULL && fm_owner[0] != '\0') {
-			if (chown(data, mport_get_uid(fm_owner), group) == -1)
+			if (chown(data, mport_get_uid(fm_owner), group) == -1) {
+				SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 				goto ERROR;
+			}
                 } else if (fm_group != NULL && fm_group[0] != '\0') {
-			if (chown(data, owner, mport_get_gid(fm_group)) == -1)
+			if (chown(data, owner, mport_get_gid(fm_group)) == -1) {
+				SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 				goto ERROR;
+			}
                 }
 	
 		break;
@@ -313,8 +322,10 @@
                 if (mport_bundle_read_extract_next_file(bundle, entry) != MPORT_OK)
                     goto ERROR;
 
-                if (lstat(file, &sb))
+                if (lstat(file, &sb)) {
+		    SET_ERRORX(MPORT_ERR_FATAL, "Unable to stat file %s", file);
                     goto ERROR;
+		}
 
                 if (S_ISREG(sb.st_mode)) {
 		    if (type == ASSET_FILE_OWNER_MODE) {
@@ -323,46 +334,64 @@
 #ifdef DEBUG
 				fprintf(stderr, "owner %s and group %s\n", fm_owner, fm_group);
 #endif
-				if (chown(file, mport_get_uid(fm_owner), mport_get_gid(fm_group)) == -1)
+				if (chown(file, mport_get_uid(fm_owner), mport_get_gid(fm_group)) == -1) {
+					SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 					goto ERROR;
+				}
 			} else if (fm_owner != NULL && fm_owner[0] != '\0') {
 #ifdef DEBUG
 				fprintf(stderr, "owner %s\n", fm_owner);
 #endif
-				if (chown(file, mport_get_uid(fm_owner), group) == -1)
+				if (chown(file, mport_get_uid(fm_owner), group) == -1) {
+					SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 					goto ERROR;
+				}
 			} else if (fm_group != NULL && fm_group[0] != '\0') {
 #ifdef DEBUG
 				fprintf(stderr, "group %s\n", fm_group);
 #endif
-				if (chown(file, owner, mport_get_gid(fm_group)) == -1)
+				if (chown(file, owner, mport_get_gid(fm_group)) == -1) {
+					SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 					goto ERROR;
+				}
 			} else {
 				// use default.
-				 if (chown(file, owner, group) == -1)
+				if (chown(file, owner, group) == -1) {
+					SET_ERROR(MPORT_ERR_FATAL, "Unable to change owner");
 					goto ERROR;
+				}
 			}
 		    } else {
 			/* Set the owner and group */
-			if (chown(file, owner, group) == -1)
+			if (chown(file, owner, group) == -1) {
+				SET_ERRORX(MPORT_ERR_FATAL, "Unable to set permissions on file %s", file);
 				goto ERROR;
+			}
 		    }
 
                     /* Set the file permissions, assumes non NFSv4 */
                     if (mode != NULL) {
-                        if (stat(file, &sb))
+                        if (stat(file, &sb)) {
+			    SET_ERRORX(MPORT_ERR_FATAL, "Unable to stat file %s", file);
                             goto ERROR;
+			}
 			if (type == ASSET_FILE_OWNER_MODE && fm_mode != NULL) {
-                        	if ((set = setmode(fm_mode)) == NULL)
+                        	if ((set = setmode(fm_mode)) == NULL) {
+					SET_ERROR(MPORT_ERR_FATAL, "Unable to set mode");
 					goto ERROR;
+				}
 			} else {
-                        	if ((set = setmode(mode)) == NULL)
+                        	if ((set = setmode(mode)) == NULL) {
+					SET_ERROR(MPORT_ERR_FATAL, "Unable to set mode");
                             		goto ERROR;
+				}
 			}
                         newmode = getmode(set, sb.st_mode);
                         free(set);
-                        if (chmod(file, newmode))
+                        if (chmod(file, newmode)) {
+			    SET_ERROR(MPORT_ERR_FATAL, "Unable to set file permissions");
                             goto ERROR;
+			}
                     }
 
                     /* shell registration */
@@ -486,10 +515,13 @@
 
         sqlite3_reset(insert);
     }
+
     sqlite3_finalize(assets);
     sqlite3_finalize(insert);
-    if (mport_db_do(db, "UPDATE packages SET status='clean' WHERE pkg=%Q", pkg->name) != MPORT_OK)
+    if (mport_db_do(db, "UPDATE packages SET status='clean' WHERE pkg=%Q", pkg->name) != MPORT_OK) {
+        SET_ERROR(MPORT_ERR_FATAL, "Unable to mark package clean");
         goto ERROR;
+    }
     mport_pkgmeta_logevent(mport, pkg, "Installed");
 
     (mport->progress_free_cb)();



More information about the Midnightbsd-cvs mailing list