Skip to content

Commit d646cc6

Browse files
committed
fix: handle stdio in Tizen
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]>
1 parent c4fe819 commit d646cc6

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

deps/node/lib/internal/bootstrap/switches/is_main_thread.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,27 @@ const { guessHandleType } = internalBinding('util');
4141
function createWritableStdioStream(fd) {
4242
let stream;
4343
// Note stream._type is used for test-module-load-list.js
44+
45+
// @lwnode
46+
if (process.lwnode) {
47+
// The handle type guessed of stdout(1) or stderr(2) can be PIPE on tizen.
48+
if (process.lwnode.hasSystemInfo('tizen') && (fd === 1 || fd === 2)) {
49+
const { Writable } = require('stream');
50+
stream = new Writable({
51+
write(chunk, encoding, callback) {
52+
process.lwnode._print(chunk.toString());
53+
callback();
54+
}
55+
});
56+
// For supporting legacy API we put the FD here.
57+
stream.fd = fd;
58+
stream._isStdio = true;
59+
return stream;
60+
}
61+
}
62+
4463
switch (guessHandleType(fd)) {
4564
case 'TTY':
46-
// @lwnode
47-
if (process.lwnode) {
48-
const { Writable } = require('stream');
49-
stream = new Writable({
50-
write(chunk, encoding, callback) {
51-
process.lwnode._print(chunk.toString());
52-
callback();
53-
}
54-
});
55-
break;
56-
}
5765
const tty = require('tty');
5866
stream = new tty.WriteStream(fd);
5967
stream._type = 'tty';

deps/node/src/lwnode/aul-event-receiver.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ bool AULEventReceiver::start(int argc, char* argv[]) {
7575

7676
if (hasAulArguments(argc, argv)) {
7777
isEventReceiverRunning_ = true;
78-
initLoggerOutput();
79-
80-
aul_launch_init(aulEventHandler, nullptr);
81-
aul_launch_argv_handler(argc, argv);
8278

8379
char appid[kMaxPackageNameSize + 1];
8480
aul_app_get_appid_bypid(getpid(), appid, kMaxPackageNameSize);
8581
appid_ = appid;
8682

87-
LWNODE_DEV_LOG("appid: ", appid_);
83+
initLoggerOutput(appid_);
84+
85+
LWNODE_DEV_LOG("appid:", appid_);
86+
87+
aul_launch_init(aulEventHandler, nullptr);
88+
aul_launch_argv_handler(argc, argv);
8889

8990
char* path = app_get_resource_path();
9091
if (uv_chdir(path) != 0) {
@@ -110,9 +111,9 @@ bool AULEventReceiver::isEventReceiverRunning() {
110111
return isEventReceiverRunning_;
111112
}
112113

113-
void AULEventReceiver::initLoggerOutput() {
114-
if (!appid_.empty()) {
115-
LogKind::user()->tag = appid_;
114+
void AULEventReceiver::initLoggerOutput(const std::string tag) {
115+
if (!tag.empty()) {
116+
LogKind::user()->tag = tag;
116117
}
117118

118119
LogOption::setDefaultOutputInstantiator([&]() {

deps/node/src/lwnode/aul-event-receiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AULEventReceiver {
3737
}
3838
#endif
3939

40-
void initLoggerOutput();
40+
void initLoggerOutput(const std::string tag = "");
4141
bool isEventReceiverRunning();
4242

4343
private:

src/api/utils/logger/logger.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ void DlogOut::flush(std::stringstream& ss,
2626
std::shared_ptr<Output::Config> config) {
2727
auto c =
2828
config ? std::static_pointer_cast<DLogConfig>(config) : LogKind::lwnode();
29+
30+
// TODO: handle the case where users manually select a logging method.
31+
2932
#ifdef HOST_TIZEN
3033
dlog_print(DLOG_INFO, c->tag.c_str(), "%s", ss.str().c_str());
3134
#else

0 commit comments

Comments
 (0)