2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-12-17 20:14:19 +00:00
|
|
|
File: AuPaths.cpp
|
2021-09-13 20:11:12 +00:00
|
|
|
Date: 2021-7-14
|
2021-06-27 21:25:29 +00:00
|
|
|
Author: Reece
|
|
|
|
***/
|
2021-09-30 14:57:41 +00:00
|
|
|
#include <Source/RuntimeInternal.hpp>
|
2022-12-17 20:14:19 +00:00
|
|
|
#include "AuPaths.hpp"
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
2021-06-27 21:25:29 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define _USE_GET_CWD
|
|
|
|
#endif
|
|
|
|
|
2023-09-12 19:48:35 +00:00
|
|
|
#include <Source/IO/FS/FS.hpp>
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
namespace Aurora::Process
|
|
|
|
{
|
2024-06-29 15:06:42 +00:00
|
|
|
static AuString gCachedModule, gCachedPartialPath, gCachedFullPath;
|
|
|
|
static AuInitOnce gInitOnce;
|
|
|
|
|
|
|
|
void ForceReplacePathHack(const AuString &path)
|
|
|
|
{
|
|
|
|
static AuInitOnce gInitOnce2;
|
|
|
|
gInitOnce2.Call([&]()
|
|
|
|
{
|
|
|
|
AuResetMember(gCachedModule);
|
|
|
|
AuResetMember(gCachedPartialPath);
|
|
|
|
AuResetMember(gCachedFullPath, path);
|
|
|
|
AuResetMember(gInitOnce);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
AUKN_SYM bool GetWorkingDirectory(AuString &path)
|
|
|
|
{
|
2023-12-22 00:17:19 +00:00
|
|
|
#if !defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
if (!AuTryResize(path, 0x4000))
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-22 00:17:19 +00:00
|
|
|
#endif
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
std::wstring eh;
|
2023-12-22 00:17:19 +00:00
|
|
|
if (!AuTryResize(eh, 0x4000))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
auto length = ::GetCurrentDirectoryW(eh.size(), eh.data());
|
|
|
|
if (length == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-22 00:17:19 +00:00
|
|
|
path = AuMove(Locale::ConvertFromWChar(eh.data(), length));
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2023-12-22 00:17:19 +00:00
|
|
|
try
|
2023-09-12 19:48:35 +00:00
|
|
|
{
|
2023-12-22 00:17:19 +00:00
|
|
|
if (!path.ends_with(AuFS::kPathSplitter))
|
|
|
|
{
|
|
|
|
path += AuFS::kPathSplitter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
SysPushErrorCatch();
|
|
|
|
return false;
|
2023-09-12 19:48:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
#elif defined(AURORA_PLATFORM_ANDROID)
|
2021-09-06 10:58:08 +00:00
|
|
|
|
|
|
|
// TODO: consider pulling internal storage package directory
|
2021-06-27 21:25:29 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
#elif defined(_USE_GET_CWD)
|
|
|
|
|
|
|
|
if (getcwd(path.data(), path.size()) == nullptr)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-26 21:01:29 +00:00
|
|
|
path.resize(strlen(path.data())); // downsize shouldn't throw
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2023-09-12 19:48:35 +00:00
|
|
|
if (!path.ends_with(AuFS::kPathSplitter))
|
|
|
|
{
|
|
|
|
path += AuFS::kPathSplitter;
|
|
|
|
}
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetModulePathSlow(AuString &path, char &splitter)
|
|
|
|
{
|
|
|
|
path.clear();
|
|
|
|
splitter = 0;
|
|
|
|
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
// TODO: BSD alternative sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
wchar_t chungus[0x4000];
|
|
|
|
auto len = GetModuleFileNameW(
|
|
|
|
NULL,
|
|
|
|
chungus,
|
2021-09-06 10:58:08 +00:00
|
|
|
AuArraySize(chungus)
|
2021-06-27 21:25:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = Aurora::Locale::ConvertFromWChar(chungus, len);
|
|
|
|
splitter = '\\';
|
|
|
|
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
if (AuEndsWith(path, ".dll"))
|
|
|
|
{
|
|
|
|
path.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
return true;
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#elif defined(AURORA_IS_XNU_DERIVED)
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
// TODO: _NSGetExecutablePath() or CFBundleCopyExecutableURL?
|
|
|
|
// i think it would make sense to use NS over CoreFoundation
|
|
|
|
// i think we're also going to have to use CF's libevent abstraction - runloop source
|
|
|
|
// to pass through kqueue structures with the mach window message loop, like how
|
|
|
|
// user32 has MsgWaitMultipleObjects.
|
|
|
|
// t. windows and loonix dev
|
|
|
|
//
|
|
|
|
// TODO: if macos >= 10.12 || quarantine xattr
|
|
|
|
// /Applications/<app name>
|
2021-09-06 10:58:08 +00:00
|
|
|
CFURLRef bundleURL = CFBundleCopyExecutableURL(CFBundleGetMainBundle());
|
|
|
|
CFStringRef pathRef = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
|
|
|
|
|
|
|
|
auto utf16length = CFStringGetLength(pathRef);
|
|
|
|
auto maxUtf8len = CFStringGetMaximumSizeForEncoding(utf16length, kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
path.resize(maxUtf8len);
|
|
|
|
|
|
|
|
if (!CFStringGetCString(pathRef, path.data(), maxUtf8len, kCFStringEncodingUTF8))
|
|
|
|
{
|
|
|
|
path.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
path.resize(std::strlen(path.c_str()));
|
2022-01-19 15:25:47 +00:00
|
|
|
splitter = '/';
|
2021-09-06 10:58:08 +00:00
|
|
|
|
|
|
|
#elif defined(AURORA_PLATFORM_ANDROID)
|
|
|
|
|
|
|
|
// SELinux gets in the way in some instances
|
|
|
|
// There is no reason we should be searching for the jre binary
|
|
|
|
// I'm also not convined pulling a cached apk path is the best thing to do here
|
2021-12-24 14:34:55 +00:00
|
|
|
// Why should we even bother pulling /system/bin/app_process?
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
#elif defined(AURORA_IS_POSIX_DERIVED)
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
static const AuList<AuString> procFsPaths = {
|
|
|
|
"/proc/self/exe",
|
|
|
|
"/proc/self/file",
|
|
|
|
"/proc/curproc/exe",
|
|
|
|
"/proc/curproc/file"
|
|
|
|
};
|
|
|
|
|
2022-04-13 11:38:26 +00:00
|
|
|
if (!AuTryResize(path, 8192))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
for (const auto &name : procFsPaths)
|
|
|
|
{
|
2022-04-13 11:38:26 +00:00
|
|
|
ssize_t count;
|
|
|
|
if ((count = readlink(name.c_str(), &path[0], path.size())) > 0)
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2022-04-13 11:38:26 +00:00
|
|
|
if (!AuTryResize(path, count))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-27 21:25:29 +00:00
|
|
|
splitter = '/';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-07-05 13:33:05 +00:00
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-12-13 18:11:35 +00:00
|
|
|
static bool GetModulePath(const AuString *&module, const AuString *&partialPath, const AuString *&fullPath)
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-22 00:17:19 +00:00
|
|
|
if (!AuThreading::InitOnceLocker::TryLock(&gInitOnce, true))
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-22 00:17:19 +00:00
|
|
|
gInitOnce.Wait();
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
2023-12-22 00:17:19 +00:00
|
|
|
else
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-23 03:24:21 +00:00
|
|
|
bool bFailed {};
|
|
|
|
|
2023-12-22 00:17:19 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
char spitter;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2024-06-29 15:06:42 +00:00
|
|
|
if (gCachedFullPath.size() ||
|
|
|
|
GetModulePathSlow(gCachedFullPath, spitter))
|
2023-12-22 00:17:19 +00:00
|
|
|
{
|
2024-06-29 15:06:42 +00:00
|
|
|
auto indexA = gCachedFullPath.find_last_of(spitter);
|
2023-12-22 00:17:19 +00:00
|
|
|
if (indexA != AuString::npos)
|
|
|
|
{
|
2024-06-29 15:06:42 +00:00
|
|
|
gCachedModule = gCachedFullPath.substr(indexA + 1);
|
|
|
|
gCachedPartialPath = gCachedFullPath.substr(0, indexA);
|
2023-12-23 03:24:21 +00:00
|
|
|
|
2024-06-29 15:06:42 +00:00
|
|
|
if (!gCachedPartialPath.ends_with(AuFS::kPathSplitter))
|
2023-12-23 03:24:21 +00:00
|
|
|
{
|
2024-06-29 15:06:42 +00:00
|
|
|
gCachedPartialPath += AuFS::kPathSplitter;
|
2023-12-23 03:24:21 +00:00
|
|
|
}
|
2023-12-22 00:17:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bFailed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bFailed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-22 00:17:19 +00:00
|
|
|
bFailed = true;
|
|
|
|
SysPushErrorCatch();
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
2023-12-22 00:17:19 +00:00
|
|
|
|
|
|
|
AuThreading::InitOnceLocker::Finish(&gInitOnce, bFailed);
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2023-12-23 03:24:21 +00:00
|
|
|
if (gInitOnce.IsUninitialized())
|
2023-09-12 19:48:35 +00:00
|
|
|
{
|
2023-12-22 00:17:19 +00:00
|
|
|
return false;
|
2023-09-12 19:48:35 +00:00
|
|
|
}
|
|
|
|
|
2024-06-29 15:06:42 +00:00
|
|
|
module = &gCachedModule;
|
|
|
|
fullPath = &gCachedFullPath;
|
|
|
|
partialPath = &gCachedPartialPath;
|
2021-06-27 21:25:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-02-14 04:05:32 +00:00
|
|
|
AUKN_SYM AuOptional<const AuString &> GetProcessName()
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
const AuString *pModule, *pPartial, *pFull;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-24 18:37:06 +00:00
|
|
|
try
|
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
if (GetModulePath(pModule, pPartial, pFull) &&
|
|
|
|
pModule &&
|
|
|
|
pModule->size())
|
2022-01-24 18:37:06 +00:00
|
|
|
{
|
2024-02-14 04:05:32 +00:00
|
|
|
return *pModule;
|
2022-01-24 18:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
SysPushErrorCatch();
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 04:05:32 +00:00
|
|
|
return {};
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 04:05:32 +00:00
|
|
|
AUKN_SYM AuOptional<const AuString &> GetProcessDirectory()
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
const AuString *pModule, *pPartial, *pFull;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-24 18:37:06 +00:00
|
|
|
try
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
if (GetModulePath(pModule, pPartial, pFull) &&
|
|
|
|
pPartial &&
|
|
|
|
pPartial->size())
|
2022-01-24 18:37:06 +00:00
|
|
|
{
|
2024-02-14 04:05:32 +00:00
|
|
|
return *pPartial;
|
2022-01-24 18:37:06 +00:00
|
|
|
}
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-24 18:37:06 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
static AuString cwd;
|
|
|
|
static AuInitOnce gInitOnce;
|
|
|
|
|
|
|
|
gInitOnce.Call([]()
|
|
|
|
{
|
|
|
|
GetWorkingDirectory(cwd);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (cwd.size())
|
|
|
|
{
|
2024-02-14 04:05:32 +00:00
|
|
|
return cwd;
|
2023-12-13 18:11:35 +00:00
|
|
|
}
|
2022-01-24 18:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
SysPushErrorCatch();
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 04:05:32 +00:00
|
|
|
return {};
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 04:05:32 +00:00
|
|
|
AUKN_SYM AuOptional<const AuString &> GetProcessFullPath()
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
const AuString *pModule, *pPartial, *pFull;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-24 18:37:06 +00:00
|
|
|
try
|
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
if (GetModulePath(pModule, pPartial, pFull) &&
|
|
|
|
pFull &&
|
|
|
|
pFull->size())
|
2022-01-24 18:37:06 +00:00
|
|
|
{
|
2024-02-14 04:05:32 +00:00
|
|
|
return *pFull;
|
2022-01-24 18:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-13 18:11:35 +00:00
|
|
|
SysPushErrorCatch();
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 04:05:32 +00:00
|
|
|
return {};
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
}
|