Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce shell count by one when configmgr used by using pipe directly #3812

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions bin/commands/internal/start/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import * as std from 'cm_std';
import * as os from 'cm_os';
import * as zos from 'zos';
import * as xplatform from 'xplatform';
import * as common from '../../../../libs/common';
import * as config from '../../../../libs/config';
import * as shell from '../../../../libs/shell';
import * as varlib from '../../../../libs/var';
import * as stringlib from '../../../../libs/string';
import * as java from '../../../../libs/java';
import * as fs from '../../../../libs/fs';
import * as component from '../../../../libs/component';
Expand Down Expand Up @@ -93,8 +95,27 @@ export function execute(componentId: string, runInBackground: boolean=false) {
} else {
// wait for all background subprocesses created by bin/start.sh exit
// re-source libs is necessary to reclaim shell functions since this will be executed in a new shell
//TODO does this do the same as the shell script before it?
shell.execSync('sh', '-c', `cd ${COMPONENT_DIR} ; cat "${fullPath}" | { echo ". \"${ZOWE_CONFIG.zowe.runtimeDirectory}/bin/libs/configmgr-index.sh\"" ; cat ; echo; echo wait; } | /bin/sh`);
const startScriptContents = `cd ${COMPONENT_DIR} ; . "${ZOWE_CONFIG.zowe.runtimeDirectory}/bin/libs/configmgr-index.sh" ; ${xplatform.loadFileUTF8(fullPath, xplatform.AUTO_DETECT)} ; wait;`;
const pipeArray = os.pipe();
if (!pipeArray) {
//TODO error message
common.printFormattedError("ZWELS", "zwe-internal-start-component", `Error ZWEL???E: Could not create pipe.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New error message or use existing. ZWEL0064E is generic, but referring to command.

return;
}
//TODO this will not work with unicode codepoints longer than a byte
Martin-Zeithaml marked this conversation as resolved.
Show resolved Hide resolved
const buf = new ArrayBuffer(startScriptContents.length);
const view = new Uint8Array(buf);
const ebcdicString = stringlib.asciiToEbcdic(startScriptContents);
for (let i = 0; i < startScriptContents.length; i++) {
view[i] = ebcdicString.charCodeAt(i);
}

os.write(pipeArray[1], buf, 0, startScriptContents.length);
os.close(pipeArray[1]);
os.exec(['/bin/sh'],
{block: true, usePath: true, stdin: pipeArray[0]});
os.close(pipeArray[0]);

}
} else {
common.printFormattedError("ZWELS", "zwe-internal-start-component", `Error ZWEL0172E: Component ${componentId} has commands.start defined but the file is missing.`);
Expand Down
Loading