Skip to content

Commit aeb119e

Browse files
committed
Don't ignore failed pre-install/post-install scripts/lua files in pkg-register(8) (freebsd#2073)
When a package is registered through pkg-register(8) the return codes of pre-install and post-install scripts and lua files are ignored. Now they are respected as with pkg-add(8). This fixes freebsd#2073
1 parent 705dff9 commit aeb119e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

libpkg/pkg_ports.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
13321332

13331333
if (!testing) {
13341334
/* Execute pre-install scripts */
1335-
pkg_lua_script_run(pkg, PKG_LUA_PRE_INSTALL, false);
1336-
pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL, false, false);
1335+
if ((rc = pkg_lua_script_run(pkg, PKG_LUA_PRE_INSTALL, false)) != EPKG_OK)
1336+
goto cleanup;
1337+
if ((rc = pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL, false, false)) != EPKG_OK)
1338+
goto cleanup;
13371339

13381340
if (input_path != NULL) {
13391341
pkg_register_cleanup_callback(pkg_rollback_cb, pkg);
@@ -1347,8 +1349,10 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
13471349
}
13481350

13491351
/* Execute post-install scripts */
1350-
pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, false);
1351-
pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, false, false);
1352+
if ((rc = pkg_lua_script_run(pkg, PKG_LUA_POST_INSTALL, false)) != EPKG_OK)
1353+
goto cleanup;
1354+
if ((rc = pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL, false, false)) != EPKG_OK)
1355+
goto cleanup;
13521356
}
13531357

13541358
if (rc == EPKG_OK) {

tests/frontend/install.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tests_init \
66
metalog \
77
reinstall \
88
pre_script_fail \
9-
post_script_ignored \
9+
post_script_fail \
1010
install_missing_dep
1111

1212
test_setup()
@@ -150,7 +150,7 @@ EOF
150150
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
151151
}
152152

153-
post_script_ignored_body()
153+
post_script_fail_body()
154154
{
155155
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
156156
cat << EOF >> test.ucl
@@ -167,7 +167,7 @@ EOF
167167

168168
atf_check -o ignore \
169169
-e inline:"${PROGNAME}: POST-INSTALL script failed\n" \
170-
-s exit:0 \
170+
-s exit:3 \
171171
pkg -o REPOS_DIR="/dev/null" install -y ${TMPDIR}/test-1.pkg
172172
}
173173

tests/frontend/lua.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pkg: lua script failed\n"
221221
mkdir -p ${TMPDIR}/target
222222
atf_check \
223223
-e inline:"${ERR}" \
224-
-s exit:0 \
224+
-s exit:3 \
225225
pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg
226226
}
227227

0 commit comments

Comments
 (0)