blob: 9ca7262eb93bbe1472d9b855035bedbc76232719 [file] [log] [blame]
Brad Bishop96ff1982019-08-19 13:50:42 -04001From dd11ed66640f79143e42d778b58fdd5a61fb5836 Mon Sep 17 00:00:00 2001
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Wed, 26 Aug 2015 16:25:45 +0300
Brad Bishop96ff1982019-08-19 13:50:42 -04004Subject: [PATCH] Our pre/postinsts expect $D to be set when running in a
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005 sysroot and don't expect a chroot. This matches up our system expectations
6 with what dpkg does.
7
8Upstream-Status: Inappropriate [OE Specific]
9
10RP 2011/12/07
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011ALIMON 2016/05/26
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012ALIMON 2017/02/21
Brad Bishop19323692019-04-05 15:28:33 -040013KKang 2019/02/20
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014---
Brad Bishop96ff1982019-08-19 13:50:42 -040015 src/script.c | 53 +++-------------------------------------------------
16 1 file changed, 3 insertions(+), 50 deletions(-)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017
18diff --git a/src/script.c b/src/script.c
Brad Bishop96ff1982019-08-19 13:50:42 -040019index abe65b6f7..621ff9b27 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020--- a/src/script.c
21+++ b/src/script.c
Brad Bishop19323692019-04-05 15:28:33 -040022@@ -96,58 +96,11 @@ setexecute(const char *path, struct stat *stab)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060023 static const char *
24 maintscript_pre_exec(struct command *cmd)
25 {
26- const char *admindir = dpkg_db_get_dir();
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027- const char *changedir;
28- size_t instdirlen = strlen(instdir);
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029-
Brad Bishop96ff1982019-08-19 13:50:42 -040030- if (instdirlen > 0 && in_force(FORCE_SCRIPT_CHROOTLESS))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031- changedir = instdir;
32- else
33- changedir = "/";
34-
Brad Bishop96ff1982019-08-19 13:50:42 -040035- if (instdirlen > 0 && !in_force(FORCE_SCRIPT_CHROOTLESS)) {
Brad Bishop19323692019-04-05 15:28:33 -040036- int rc;
37-
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038- if (strncmp(admindir, instdir, instdirlen) != 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039- ohshit(_("admindir must be inside instdir for dpkg to work properly"));
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040- if (setenv("DPKG_ADMINDIR", admindir + instdirlen, 1) < 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041- ohshite(_("unable to setenv for subprocesses"));
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042- if (setenv("DPKG_ROOT", "", 1) < 0)
43- ohshite(_("unable to setenv for subprocesses"));
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044-
Brad Bishop19323692019-04-05 15:28:33 -040045- rc = chroot(instdir);
Brad Bishop96ff1982019-08-19 13:50:42 -040046- if (rc && in_force(FORCE_NON_ROOT) && errno == EPERM)
Brad Bishop19323692019-04-05 15:28:33 -040047- ohshit(_("not enough privileges to change root "
48- "directory with --force-not-root, consider "
49- "using --force-script-chrootless?"));
50- else if (rc)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051- ohshite(_("failed to chroot to '%.250s'"), instdir);
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052+ if (*instdir) {
53+ setenv("D", instdir, 1);
54 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055- /* Switch to a known good directory to give the maintainer script
56- * a saner environment, also needed after the chroot(). */
Patrick Williamsc0f7c042017-02-23 20:41:17 -060057- if (chdir(changedir))
58- ohshite(_("failed to chdir to '%.255s'"), changedir);
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059- if (debug_has_flag(dbg_scripts)) {
60- struct varbuf args = VARBUF_INIT;
61- const char **argv = cmd->argv;
62-
63- while (*++argv) {
64- varbuf_add_char(&args, ' ');
65- varbuf_add_str(&args, *argv);
66- }
67- varbuf_end_str(&args);
68- debug(dbg_scripts, "fork/exec %s (%s )", cmd->filename,
69- args.buf);
70- varbuf_destroy(&args);
Patrick Williamsc0f7c042017-02-23 20:41:17 -060071- }
Brad Bishop96ff1982019-08-19 13:50:42 -040072- if (instdirlen == 0 || in_force(FORCE_SCRIPT_CHROOTLESS))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073- return cmd->filename;
74-
Brad Bishop19323692019-04-05 15:28:33 -040075- if (strlen(cmd->filename) < instdirlen)
76- internerr("maintscript name '%s' length < instdir length %zd",
77- cmd->filename, instdirlen);
78
Brad Bishop6e60e8b2018-02-01 10:27:11 -050079- return cmd->filename + instdirlen;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080+ return cmd->filename;
81 }
82
83 /**
84--
Brad Bishop96ff1982019-08-19 13:50:42 -0400852.17.1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086