diff --git a/uppsrc/Core/Diag.h b/uppsrc/Core/Diag.h index 4e94b0eb3..2c518fb60 100644 --- a/uppsrc/Core/Diag.h +++ b/uppsrc/Core/Diag.h @@ -10,7 +10,7 @@ const char LOG_END = '\x1f'; enum LogOptions { LOG_FILE = 1, LOG_COUT = 2, LOG_CERR = 4, LOG_DBG = 8, LOG_SYS = 16, LOG_ELAPSED = 128, LOG_TIMESTAMP = 256, LOG_TIMESTAMP_UTC = 512, LOG_APPEND = 1024, LOG_ROTATE_GZIP = 2048, - LOG_COUTW = 4096, LOG_CERRW = 8192 + LOG_COUTW = 4096, LOG_CERRW = 8192, LOG_PROCESS_ID = 16384 }; inline int LOG_ROTATE(int x) { return x << 24; } diff --git a/uppsrc/Core/LocalProcess.cpp b/uppsrc/Core/LocalProcess.cpp index fb35e192e..be7afb30e 100644 --- a/uppsrc/Core/LocalProcess.cpp +++ b/uppsrc/Core/LocalProcess.cpp @@ -9,7 +9,7 @@ namespace Upp { #include #endif -#define LLOG(x) // DLOG(x) +#define LLOG(x) // DLOG(x) void LocalProcess::Init() { #ifdef PLATFORM_WIN32 @@ -231,7 +231,7 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool *cmd_out++ = '\0'; } } - + if(args.GetCount() == 0) return false; @@ -240,7 +240,7 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool String app_full = GetFileOnPath(args[0], getenv("PATH"), true); if(IsNull(app_full)) return false; - + Buffer arg0(app_full.GetCount() + 1); memcpy(~arg0, ~app_full, app_full.GetCount() + 1); args[0] = ~arg0; @@ -250,7 +250,7 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool if(spliterr && pipe(epipe)) return false; - + LLOG("\nLocalProcess::Start"); LLOG("rpipe[" << rpipe[0] << ", " << rpipe[1] << "]"); LLOG("wpipe[" << wpipe[0] << ", " << wpipe[1] << "]"); @@ -265,7 +265,7 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool } env.Add(NULL); } - + pid = fork(); // Warning: other threads are dead after this point, which means heap might be locked @@ -294,7 +294,7 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool LLOG("\tfork2, pid2 = " << (int)pid2 << ", getpid = " << (int)getpid()); if (pid2 < 0) { LLOG("fork2 failed"); - Exit(1); + abort(); } if (pid2) { LLOG("exiting intermediary process"); @@ -308,8 +308,8 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool } // we call exec instead of Exit, because exit doesn't behave nicelly with threads execl("/usr/bin/true", "[closing fork]", (char*)NULL); - // only call Exit when execl fails - Exit(0); + // only call abort when execl fails + abort(); // do not use exit here: it calls global destructors... } } @@ -337,10 +337,8 @@ bool LocalProcess::DoStart(const char *command, const Vector *arg, bool (void)!chdir(cd); // that (void)! strange thing is to silence GCC warning LLOG("running execve, app = " << app << ", #args = " << args.GetCount()); - if(envptr) { - env.Add(NULL); + if(envptr) execve(app_full, args.Begin(), (char *const *)env.Begin()); - } else execv(app_full, args.Begin()); LLOG("execve failed, errno = " << errno); @@ -506,7 +504,7 @@ bool LocalProcess::Read2(String& reso, String& rese) reso = FromOEMCharset(reso); rese = FromOEMCharset(rese); } - + return reso.GetCount() || rese.GetCount() || was_running; #endif #ifdef PLATFORM_POSIX @@ -668,4 +666,4 @@ String Sys(const char *cmd, const Vector& arg, bool convertcharset) return Sys(cmd, arg, r, convertcharset) ? String::GetVoid() : r; } -} +} \ No newline at end of file diff --git a/uppsrc/Core/Log.cpp b/uppsrc/Core/Log.cpp index 8ccca7e2a..82d7a51e1 100644 --- a/uppsrc/Core/Log.cpp +++ b/uppsrc/Core/Log.cpp @@ -174,6 +174,14 @@ void LogOut::Line(const char *s, int len, int depth) p += ll; prev_msecs = t; } +#ifdef PLATFORM_POSIX + if((options & LOG_PROCESS_ID) && line_begin) { + ll = snprintf(p, 600, "PID %d ", getpid()); + if(ll < 0) + return; + p += ll; + } +#endif if((options & (LOG_TIMESTAMP|LOG_TIMESTAMP_UTC)) && line_begin) { Time t = (options & LOG_TIMESTAMP_UTC) ? GetUtcTime() : GetSysTime(); ll = snprintf(p, 600, "%02d.%02d.%04d %02d:%02d:%02d ",