Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 1 | From dd11ed66640f79143e42d778b58fdd5a61fb5836 Mon Sep 17 00:00:00 2001 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | From: Alexander Kanavin <alex.kanavin@gmail.com> |
| 3 | Date: Wed, 26 Aug 2015 16:25:45 +0300 |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 4 | Subject: [PATCH] Our pre/postinsts expect $D to be set when running in a |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | sysroot and don't expect a chroot. This matches up our system expectations |
| 6 | with what dpkg does. |
| 7 | |
| 8 | Upstream-Status: Inappropriate [OE Specific] |
| 9 | |
| 10 | RP 2011/12/07 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | ALIMON 2016/05/26 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | ALIMON 2017/02/21 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 13 | KKang 2019/02/20 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | --- |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 15 | src/script.c | 53 +++------------------------------------------------- |
| 16 | 1 file changed, 3 insertions(+), 50 deletions(-) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | |
| 18 | diff --git a/src/script.c b/src/script.c |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 19 | index abe65b6f7..621ff9b27 100644 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | --- a/src/script.c |
| 21 | +++ b/src/script.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 22 | @@ -96,58 +96,11 @@ setexecute(const char *path, struct stat *stab) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 23 | static const char * |
| 24 | maintscript_pre_exec(struct command *cmd) |
| 25 | { |
| 26 | - const char *admindir = dpkg_db_get_dir(); |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | - const char *changedir; |
| 28 | - size_t instdirlen = strlen(instdir); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | - |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 30 | - if (instdirlen > 0 && in_force(FORCE_SCRIPT_CHROOTLESS)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | - changedir = instdir; |
| 32 | - else |
| 33 | - changedir = "/"; |
| 34 | - |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 35 | - if (instdirlen > 0 && !in_force(FORCE_SCRIPT_CHROOTLESS)) { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | - int rc; |
| 37 | - |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | - if (strncmp(admindir, instdir, instdirlen) != 0) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | - ohshit(_("admindir must be inside instdir for dpkg to work properly")); |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 40 | - if (setenv("DPKG_ADMINDIR", admindir + instdirlen, 1) < 0) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | - ohshite(_("unable to setenv for subprocesses")); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 42 | - if (setenv("DPKG_ROOT", "", 1) < 0) |
| 43 | - ohshite(_("unable to setenv for subprocesses")); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | - |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 45 | - rc = chroot(instdir); |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 46 | - if (rc && in_force(FORCE_NON_ROOT) && errno == EPERM) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 47 | - ohshit(_("not enough privileges to change root " |
| 48 | - "directory with --force-not-root, consider " |
| 49 | - "using --force-script-chrootless?")); |
| 50 | - else if (rc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | - ohshite(_("failed to chroot to '%.250s'"), instdir); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 52 | + if (*instdir) { |
| 53 | + setenv("D", instdir, 1); |
| 54 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | - /* Switch to a known good directory to give the maintainer script |
| 56 | - * a saner environment, also needed after the chroot(). */ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | - if (chdir(changedir)) |
| 58 | - ohshite(_("failed to chdir to '%.255s'"), changedir); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | - 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 71 | - } |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 72 | - if (instdirlen == 0 || in_force(FORCE_SCRIPT_CHROOTLESS)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | - return cmd->filename; |
| 74 | - |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 75 | - if (strlen(cmd->filename) < instdirlen) |
| 76 | - internerr("maintscript name '%s' length < instdir length %zd", |
| 77 | - cmd->filename, instdirlen); |
| 78 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 79 | - return cmd->filename + instdirlen; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | + return cmd->filename; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | -- |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 85 | 2.17.1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 86 | |