Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Enable a cross-install scriptlet helper. |
| 2 | |
| 3 | The helper is called from outside of the chroot with the arguments: |
| 4 | |
| 5 | <root> <prog> <script> <arg1> [<arg2> ... <argN>] |
| 6 | |
| 7 | The helper script is used by oe-core to facilitate shell script actions that |
| 8 | can not be run from within a chroot on a foreign target system during a |
| 9 | cross install. |
| 10 | |
| 11 | Upstream-Status: Pending |
| 12 | |
| 13 | Signed-off-by: Mark Hatle <mark.hatle@windriver.com> |
| 14 | |
| 15 | Index: rpm-5.4.14/lib/psm.c |
| 16 | =================================================================== |
| 17 | --- rpm-5.4.14.orig/lib/psm.c |
| 18 | +++ rpm-5.4.14/lib/psm.c |
| 19 | @@ -806,6 +806,10 @@ static rpmRC runScript(rpmpsm psm, Heade |
| 20 | int xx; |
| 21 | int i; |
| 22 | |
| 23 | +#ifdef RPM_VENDOR_OE |
| 24 | + const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL); |
| 25 | +#endif |
| 26 | + |
| 27 | if (psm->sstates != NULL && ix >= 0 && ix < RPMSCRIPT_MAX) |
| 28 | ssp = psm->sstates + ix; |
| 29 | if (ssp != NULL) |
| 30 | @@ -872,14 +876,29 @@ assert(he->p.str != NULL); |
| 31 | (F_ISSET(psm, UNORDERED) ? "a" : "")); |
| 32 | |
| 33 | if (Phe->p.argv == NULL) { |
| 34 | - argv = (const char **) alloca(5 * sizeof(*argv)); |
| 35 | - argv[0] = "/bin/sh"; |
| 36 | - argc = 1; |
| 37 | + argv = (const char **) alloca(7 * sizeof(*argv)); |
| 38 | + argc = 0; |
| 39 | + } else { |
| 40 | + argv = (const char **) alloca((Phe->c + 6) * sizeof(*argv)); |
| 41 | + argc = 0; |
| 42 | + } |
| 43 | + |
| 44 | +#ifdef RPM_VENDOR_OE |
| 45 | + if (scriptletWrapper && *scriptletWrapper) { |
| 46 | + argv[argc++] = scriptletWrapper; |
| 47 | + argv[argc] = rpmtsRootDir(ts); |
| 48 | + if (!argv[argc] || !*argv[argc]) |
| 49 | + argv[argc] = "/"; |
| 50 | + argc++; |
| 51 | + } |
| 52 | +#endif |
| 53 | + |
| 54 | + if (Phe->p.argv == NULL) { |
| 55 | + argv[argc++] = "/bin/sh"; |
| 56 | ldconfig_done = 0; |
| 57 | } else { |
| 58 | - argv = (const char **) alloca((Phe->c + 4) * sizeof(*argv)); |
| 59 | - memcpy(argv, Phe->p.argv, Phe->c * sizeof(*argv)); |
| 60 | - argc = Phe->c; |
| 61 | + memcpy((argv + argc), Phe->p.argv, Phe->c * sizeof(*argv)); |
| 62 | + argc += Phe->c; |
| 63 | ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path) |
| 64 | ? 1 : 0); |
| 65 | } |
| 66 | @@ -930,7 +949,12 @@ assert(he->p.str != NULL); |
| 67 | goto exit; |
| 68 | |
| 69 | if (rpmIsDebug() && |
| 70 | - (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash"))) |
| 71 | + (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")) |
| 72 | +#ifdef RPM_VENDOR_OE |
| 73 | + || (scriptletWrapper && *scriptletWrapper && !strcmp(argv[1], "/bin/sh")) |
| 74 | + || (scriptletWrapper && *scriptletWrapper && !strcmp(argv[1], "/bin/bash")) |
| 75 | +#endif |
| 76 | + ) |
| 77 | { |
| 78 | static const char set_x[] = "set -x\n"; |
| 79 | nw = Fwrite(set_x, sizeof(set_x[0]), sizeof(set_x)-1, fd); |
| 80 | @@ -1065,12 +1089,22 @@ assert(he->p.str != NULL); |
| 81 | |
| 82 | { const char * rootDir = rpmtsRootDir(ts); |
| 83 | if (!rpmtsChrootDone(ts) && rootDir != NULL && |
| 84 | +#ifdef RPM_VENDOR_OE |
| 85 | + !(scriptletWrapper && *scriptletWrapper) && |
| 86 | +#endif |
| 87 | !(rootDir[0] == '/' && rootDir[1] == '\0')) |
| 88 | { |
| 89 | /*@-modobserver@*/ |
| 90 | xx = Chroot(rootDir); |
| 91 | /*@=modobserver@*/ |
| 92 | } |
| 93 | +#ifdef RPM_VENDOR_OE |
| 94 | + if (!rpmtsChrootDone(ts) && rootDir != NULL && |
| 95 | + (scriptletWrapper && *scriptletWrapper) && |
| 96 | + !(rootDir[0] == '/' && rootDir[1] == '\0')) |
| 97 | + xx = Chdir(rootDir); |
| 98 | + else |
| 99 | +#endif |
| 100 | xx = Chdir("/"); |
| 101 | rpmlog(RPMLOG_DEBUG, D_("%s: %s(%s)\texecv(%s) pid %d\n"), |
| 102 | psm->stepName, sln, NVRA, |
| 103 | @@ -2985,6 +3019,13 @@ assert(psm->te != NULL); |
| 104 | case PSM_SCRIPT: /* Run current package scriptlets. */ |
| 105 | /* XXX running %verifyscript/%sanitycheck doesn't have psm->te */ |
| 106 | { rpmtxn _parent = (psm && psm->te ? psm->te->txn : NULL); |
| 107 | + |
| 108 | +#ifdef RPM_VENDOR_OE |
| 109 | + const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL); |
| 110 | + if (scriptletWrapper && *scriptletWrapper) |
| 111 | + rc = rpmpsmNext(psm, PSM_CHROOT_OUT); |
| 112 | +#endif |
| 113 | + |
| 114 | xx = rpmtxnBegin(rpmtsGetRdb(ts), _parent, NULL); |
| 115 | rc = runInstScript(psm); |
| 116 | if (rc) |
| 117 | @@ -2992,11 +3033,24 @@ assert(psm->te != NULL); |
| 118 | else |
| 119 | xx = rpmtxnCommit(rpmtsGetRdb(ts)->db_txn); |
| 120 | rpmtsGetRdb(ts)->db_txn = NULL; |
| 121 | +#ifdef RPM_VENDOR_OE |
| 122 | + if (scriptletWrapper && *scriptletWrapper) |
| 123 | + rc = rpmpsmNext(psm, PSM_CHROOT_IN); |
| 124 | +#endif |
| 125 | } break; |
| 126 | case PSM_TRIGGERS: |
| 127 | /* Run triggers in other package(s) this package sets off. */ |
| 128 | if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) break; |
| 129 | +#ifdef RPM_VENDOR_OE |
| 130 | + const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL); |
| 131 | + if (scriptletWrapper && *scriptletWrapper) |
| 132 | + rc = rpmpsmNext(psm, PSM_CHROOT_OUT); |
| 133 | +#endif |
| 134 | rc = runTriggers(psm); |
| 135 | +#ifdef RPM_VENDOR_OE |
| 136 | + if (scriptletWrapper && *scriptletWrapper) |
| 137 | + rc = rpmpsmNext(psm, PSM_CHROOT_IN); |
| 138 | +#endif |
| 139 | break; |
| 140 | case PSM_IMMED_TRIGGERS: |
| 141 | /* Run triggers in this package other package(s) set off. */ |
| 142 | @@ -3006,7 +3060,18 @@ assert(psm->te != NULL); |
| 143 | F_SET(psm, GOTTRIGGERS); |
| 144 | } |
| 145 | if (psm->triggers != NULL) |
| 146 | +#ifdef RPM_VENDOR_OE |
| 147 | + { |
| 148 | + const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL); |
| 149 | + if (scriptletWrapper && *scriptletWrapper) |
| 150 | + rc = rpmpsmNext(psm, PSM_CHROOT_OUT); |
| 151 | +#endif |
| 152 | rc = runImmedTriggers(psm); |
| 153 | +#ifdef RPM_VENDOR_OE |
| 154 | + if (scriptletWrapper && *scriptletWrapper) |
| 155 | + rc = rpmpsmNext(psm, PSM_CHROOT_IN); |
| 156 | + } |
| 157 | +#endif |
| 158 | break; |
| 159 | |
| 160 | case PSM_RPMIO_FLAGS: |