summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rpm/rpm/rpm-scriptletexechelper.patch
blob: 8a9e712acff37fcfbdd974bcfadbbe21106f9be7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Enable a cross-install scriptlet helper.

The helper is called from outside of the chroot with the arguments:

<root> <prog> <script> <arg1> [<arg2> ... <argN>]

The helper script is used by oe-core to facilitate shell script actions that
can not be run from within a chroot on a foreign target system during a
cross install.

Upstream-Status: Pending

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>

Index: rpm-5.4.9/lib/psm.c
===================================================================
--- rpm-5.4.9.orig/lib/psm.c
+++ rpm-5.4.9/lib/psm.c
@@ -801,6 +801,10 @@ static rpmRC runScript(rpmpsm psm, Heade
     int xx;
     int i;
 
+#ifdef RPM_VENDOR_POKY
+    const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL);
+#endif
+    
     if (psm->sstates != NULL && ix >= 0 && ix < RPMSCRIPT_MAX)
 	ssp = psm->sstates + ix;
     if (ssp != NULL)
@@ -867,14 +871,29 @@ assert(he->p.str != NULL);
 		(F_ISSET(psm, UNORDERED) ? "a" : ""));
 
     if (Phe->p.argv == NULL) {
-	argv = (const char **) alloca(5 * sizeof(*argv));
-	argv[0] = "/bin/sh";
-	argc = 1;
+	argv = (const char **) alloca(7 * sizeof(*argv));
+	argc = 0;
+    } else {
+	argv = (const char **) alloca((Phe->c + 6) * sizeof(*argv));
+	argc = 0;
+    }
+
+#ifdef RPM_VENDOR_POKY
+    if (scriptletWrapper && *scriptletWrapper) {
+	argv[argc++] = scriptletWrapper;
+	argv[argc] = rpmtsRootDir(ts);
+	if (!argv[argc] || !*argv[argc])
+	   argv[argc] = "/";
+	argc++;
+    }
+#endif
+
+    if (Phe->p.argv == NULL) {
+	argv[argc++] = "/bin/sh";
 	ldconfig_done = 0;
     } else {
-	argv = (const char **) alloca((Phe->c + 4) * sizeof(*argv));
-	memcpy(argv, Phe->p.argv, Phe->c * sizeof(*argv));
-	argc = Phe->c;
+	memcpy((argv + argc), Phe->p.argv, Phe->c * sizeof(*argv));
+	argc += Phe->c;
 	ldconfig_done = (ldconfig_path && !strcmp(argv[0], ldconfig_path)
 		? 1 : 0);
     }
@@ -925,7 +944,12 @@ assert(he->p.str != NULL);
 	    goto exit;
 
 	if (rpmIsDebug() &&
-	    (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
+	    (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash"))
+#ifdef RPM_VENDOR_POKY
+	    || (scriptletWrapper && *scriptletWrapper && !strcmp(argv[1], "/bin/sh"))
+	    || (scriptletWrapper && *scriptletWrapper && !strcmp(argv[1], "/bin/bash"))
+#endif
+	   )
 	{
 	    static const char set_x[] = "set -x\n";
 	    nw = Fwrite(set_x, sizeof(set_x[0]), sizeof(set_x)-1, fd);
@@ -1060,12 +1084,22 @@ assert(he->p.str != NULL);
 
 	{   const char * rootDir = rpmtsRootDir(ts);
 	    if (!rpmtsChrootDone(ts) && rootDir != NULL &&
+#ifdef RPM_VENDOR_POKY
+		!(scriptletWrapper && *scriptletWrapper) &&
+#endif
 		!(rootDir[0] == '/' && rootDir[1] == '\0'))
 	    {
 		/*@-modobserver@*/
 		xx = Chroot(rootDir);
 		/*@=modobserver@*/
 	    }
+#ifdef RPM_VENDOR_POKY
+	    if (!rpmtsChrootDone(ts) && rootDir != NULL &&
+		(scriptletWrapper && *scriptletWrapper) &&
+		!(rootDir[0] == '/' && rootDir[1] == '\0'))
+		xx = Chdir(rootDir);
+	    else 
+#endif
 	    xx = Chdir("/");
 	    rpmlog(RPMLOG_DEBUG, D_("%s: %s(%s)\texecv(%s) pid %d\n"),
 			psm->stepName, sln, NVRA,
@@ -2977,6 +3011,13 @@ assert(psm->te != NULL);
     case PSM_SCRIPT:	/* Run current package scriptlets. */
 	/* XXX running %verifyscript/%sanitycheck doesn't have psm->te */
     {	rpmtxn _parent = (psm && psm->te ? psm->te->txn : NULL);
+
+#ifdef RPM_VENDOR_POKY
+        const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL);
+	if (scriptletWrapper && *scriptletWrapper)
+	     rc = rpmpsmNext(psm, PSM_CHROOT_OUT);
+#endif
+
 	xx = rpmtxnBegin(rpmtsGetRdb(ts), _parent, NULL);
 	rc = runInstScript(psm);
 	if (rc)
@@ -2984,11 +3025,24 @@ assert(psm->te != NULL);
 	else
 	     xx = rpmtxnCommit(rpmtsGetRdb(ts)->db_txn);
 	rpmtsGetRdb(ts)->db_txn = NULL;
+#ifdef RPM_VENDOR_POKY
+	if (scriptletWrapper && *scriptletWrapper)
+	     rc = rpmpsmNext(psm, PSM_CHROOT_IN);
+#endif
     }	break;
     case PSM_TRIGGERS:
 	/* Run triggers in other package(s) this package sets off. */
 	if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)	break;
+#ifdef RPM_VENDOR_POKY
+        const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL);
+	if (scriptletWrapper && *scriptletWrapper)
+	     rc = rpmpsmNext(psm, PSM_CHROOT_OUT);
+#endif
 	rc = runTriggers(psm);
+#ifdef RPM_VENDOR_POKY
+	if (scriptletWrapper && *scriptletWrapper)
+	     rc = rpmpsmNext(psm, PSM_CHROOT_IN);
+#endif
 	break;
     case PSM_IMMED_TRIGGERS:
 	/* Run triggers in this package other package(s) set off. */
@@ -2998,7 +3052,18 @@ assert(psm->te != NULL);
 	    F_SET(psm, GOTTRIGGERS);
 	}
 	if (psm->triggers != NULL)
+#ifdef RPM_VENDOR_POKY
+	{
+            const char * scriptletWrapper = rpmExpand("%{?_cross_scriptlet_wrapper}", NULL);
+	    if (scriptletWrapper && *scriptletWrapper)
+	         rc = rpmpsmNext(psm, PSM_CHROOT_OUT);
+#endif
 	    rc = runImmedTriggers(psm);
+#ifdef RPM_VENDOR_POKY
+	    if (scriptletWrapper && *scriptletWrapper)
+	         rc = rpmpsmNext(psm, PSM_CHROOT_IN);
+	}
+#endif
 	break;
 
     case PSM_RPMIO_FLAGS: