Skip to content

Commit

Permalink
fix: handle stdio in Tizen
Browse files Browse the repository at this point in the history
This hijacks inputs for stdio streams when running on Tizen.
That's because stdio is piped to dlog in Tizen apps.

Signed-off-by: Daeyeon Jeong <[email protected]>
  • Loading branch information
daeyeon committed Mar 13, 2024
1 parent c4fe819 commit d646cc6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
30 changes: 19 additions & 11 deletions deps/node/lib/internal/bootstrap/switches/is_main_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,27 @@ const { guessHandleType } = internalBinding('util');
function createWritableStdioStream(fd) {
let stream;
// Note stream._type is used for test-module-load-list.js

// @lwnode
if (process.lwnode) {
// The handle type guessed of stdout(1) or stderr(2) can be PIPE on tizen.
if (process.lwnode.hasSystemInfo('tizen') && (fd === 1 || fd === 2)) {
const { Writable } = require('stream');
stream = new Writable({
write(chunk, encoding, callback) {
process.lwnode._print(chunk.toString());
callback();
}
});
// For supporting legacy API we put the FD here.
stream.fd = fd;
stream._isStdio = true;
return stream;
}
}

switch (guessHandleType(fd)) {
case 'TTY':
// @lwnode
if (process.lwnode) {
const { Writable } = require('stream');
stream = new Writable({
write(chunk, encoding, callback) {
process.lwnode._print(chunk.toString());
callback();
}
});
break;
}
const tty = require('tty');
stream = new tty.WriteStream(fd);
stream._type = 'tty';
Expand Down
17 changes: 9 additions & 8 deletions deps/node/src/lwnode/aul-event-receiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ bool AULEventReceiver::start(int argc, char* argv[]) {

if (hasAulArguments(argc, argv)) {
isEventReceiverRunning_ = true;
initLoggerOutput();

aul_launch_init(aulEventHandler, nullptr);
aul_launch_argv_handler(argc, argv);

char appid[kMaxPackageNameSize + 1];
aul_app_get_appid_bypid(getpid(), appid, kMaxPackageNameSize);
appid_ = appid;

LWNODE_DEV_LOG("appid: ", appid_);
initLoggerOutput(appid_);

LWNODE_DEV_LOG("appid:", appid_);

aul_launch_init(aulEventHandler, nullptr);
aul_launch_argv_handler(argc, argv);

char* path = app_get_resource_path();
if (uv_chdir(path) != 0) {
Expand All @@ -110,9 +111,9 @@ bool AULEventReceiver::isEventReceiverRunning() {
return isEventReceiverRunning_;
}

void AULEventReceiver::initLoggerOutput() {
if (!appid_.empty()) {
LogKind::user()->tag = appid_;
void AULEventReceiver::initLoggerOutput(const std::string tag) {
if (!tag.empty()) {
LogKind::user()->tag = tag;
}

LogOption::setDefaultOutputInstantiator([&]() {
Expand Down
2 changes: 1 addition & 1 deletion deps/node/src/lwnode/aul-event-receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AULEventReceiver {
}
#endif

void initLoggerOutput();
void initLoggerOutput(const std::string tag = "");
bool isEventReceiverRunning();

private:
Expand Down
3 changes: 3 additions & 0 deletions src/api/utils/logger/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ void DlogOut::flush(std::stringstream& ss,
std::shared_ptr<Output::Config> config) {
auto c =
config ? std::static_pointer_cast<DLogConfig>(config) : LogKind::lwnode();

// TODO: handle the case where users manually select a logging method.

#ifdef HOST_TIZEN
dlog_print(DLOG_INFO, c->tag.c_str(), "%s", ss.str().c_str());
#else
Expand Down

0 comments on commit d646cc6

Please sign in to comment.