Skip to content

Commit ba5feb8

Browse files
committed
Put back kal_process_wait, which a bulk edit had swallowed
⚠️⚠️ A REGEX SUBSTITUTION ACROSS A WHOLE FILE DELETED A FUNCTION I NEVER MEANT TO TOUCH, and nothing local noticed: this file still compiled, because a definition that is absent is not a compile error --- it is a link error, and only in a program that calls it. ⭐ What found it was the cross-link job in openkal-musl, three repositories away: ld64.lld: error: undefined symbol: _kal_process_wait ⇒ Restored from the branch point rather than retyped. The test file is updated for the 0.11 spawn record at the same time. The lesson is recorded rather than resolved: a multi-line pattern applied to a whole file can remove more than it matches, and the only thing that reports it is something that LINKS. This repository builds a library and does not link a program, so its own build could never have caught this.
1 parent 1391c77 commit ba5feb8

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/process.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,30 @@ void kal_process_channel_close(kal_stream s) {
229229
// Starting a program that receives exactly the directories named.
230230

231231
// One program, whatever unit it is in --- the unit has its own operation below,
232+
int kal_process_wait(kal_process h, int* status, int* terminated_by_environment) {
233+
if (h.h == 0) return kal_err_invalid;
234+
int st = 0;
235+
for (;;) {
236+
const okm_long r = okm::sys(okm::nr_wait4, static_cast<okm_long>(h.h),
237+
reinterpret_cast<okm_long>(&st), 0, 0);
238+
if (okm::interrupted(r)) continue;
239+
if (okm::failed(r)) return okm::translate(r);
240+
break;
241+
}
242+
// The encoding is the kernel's: the low seven bits name the signal that
243+
// ended the program and are zero when it ended by returning, in which case
244+
// the next eight bits are what it returned.
245+
const int signalled = st & 0x7f;
246+
if (signalled == 0) {
247+
if (status) *status = (st >> 8) & 0xff;
248+
if (terminated_by_environment) *terminated_by_environment = 0;
249+
} else {
250+
if (status) *status = signalled;
251+
if (terminated_by_environment) *terminated_by_environment = 1;
252+
}
253+
return kal_ok;
254+
}
255+
232256
// so this one's meaning never turns on how the program was started.
233257
int kal_process_terminate(kal_process h) {
234258
if (h.h == 0) return kal_err_invalid;

tests/conformance_process_task.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ int main() {
6363
check(have_root, "a directory covering the file system is supplied");
6464

6565
if (have_root) {
66+
// How every start below is described. `work' is the same directory as
67+
// `base' --- a caller that does not care passes it, openkal having no
68+
// ambient working directory for a default to mean.
69+
const kal_spawn how{ slash, slash, nullptr, nullptr, 0, 0 };
70+
6671
// The program that succeeds and the program that fails are at
6772
// different places on different systems. The test locates them rather
6873
// than assuming, because assuming would make it a test of one system.
@@ -104,7 +109,7 @@ int main() {
104109
const kal_uintptr lens[] = { 7 };
105110
int rc = kal_err_invalid;
106111
if (t >= 0)
107-
rc = kal_process_spawn(slash, true_paths[t], true_lens[t], argv, lens, 1,
112+
rc = kal_process_spawn(&how, true_paths[t], true_lens[t], argv, lens, 1,
108113
nullptr, nullptr, 0, nullptr, &p);
109114
check(rc == kal_ok, "a program is started");
110115
if (rc == kal_ok) {
@@ -128,7 +133,7 @@ int main() {
128133
const char* qargv[] = { "openkal" };
129134
int qrc = kal_err_invalid;
130135
if (fpath >= 0)
131-
qrc = kal_process_spawn(slash, false_paths[fpath], false_lens[fpath], qargv, lens, 1,
136+
qrc = kal_process_spawn(&how, false_paths[fpath], false_lens[fpath], qargv, lens, 1,
132137
nullptr, nullptr, 0, nullptr, &q);
133138
check(qrc == kal_ok, "the program that fails is started");
134139
if (qrc == kal_ok) {
@@ -171,7 +176,7 @@ int main() {
171176
const kal_uintptr rlens[] = { 22, 2, script_len };
172177
int rrc = kal_err_invalid;
173178
if (sh >= 0)
174-
rrc = kal_process_spawn(slash, sh_paths[sh], sh_lens[sh], rargv, rlens, 3,
179+
rrc = kal_process_spawn(&how, sh_paths[sh], sh_lens[sh], rargv, rlens, 3,
175180
nullptr, nullptr, 0, nullptr, &r);
176181
check(rrc == kal_ok, "a shell is started");
177182
if (rrc == kal_ok) {
@@ -185,7 +190,9 @@ int main() {
185190

186191
// A name that ascends is refused here as it is in the file system.
187192
kal_process bad{};
188-
check(kal_process_spawn(kal::fs::working(), "../bin/true", 11,
193+
const kal_spawn escape{ kal::fs::working(), kal::fs::working(),
194+
nullptr, nullptr, 0, 0 };
195+
check(kal_process_spawn(&escape, "../bin/true", 11,
189196
nullptr, nullptr, 0, nullptr, nullptr, 0, nullptr, &bad)
190197
!= kal_ok, "an ascending program name is refused");
191198

0 commit comments

Comments
 (0)