mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-31 15:38:33 +00:00
Use proper API to read /proc/mounts.
This commit is contained in:
@@ -610,6 +610,7 @@ void SysTraceGetExternalName( uint64_t thread, const char*& threadName, const ch
|
||||
# include <fcntl.h>
|
||||
# include <inttypes.h>
|
||||
# include <limits>
|
||||
# include <mntent.h>
|
||||
# include <poll.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
@@ -774,45 +775,23 @@ static const char* ReadFile( const char* base, const char* path )
|
||||
|
||||
static char* GetTraceFsPath()
|
||||
{
|
||||
int fd = open( "/proc/mounts", O_RDONLY );
|
||||
if( fd < 0 ) return nullptr;
|
||||
auto f = setmntent( "/proc/mounts", "r" );
|
||||
if( !f ) return nullptr;
|
||||
|
||||
constexpr size_t BufSize = 64 * 1024;
|
||||
auto tmp = (char*)tracy_malloc( BufSize );
|
||||
const auto cnt = read( fd, tmp, BufSize-1 );
|
||||
close( fd );
|
||||
if( cnt < 0 )
|
||||
char* ret = nullptr;
|
||||
while( auto ent = getmntent( f ) )
|
||||
{
|
||||
tracy_free( tmp );
|
||||
return nullptr;
|
||||
}
|
||||
tmp[cnt] = '\0';
|
||||
|
||||
auto ptr = tmp;
|
||||
while( *ptr )
|
||||
{
|
||||
if( strncmp( ptr, "tracefs ", 8 ) == 0 )
|
||||
if( strcmp( ent->mnt_fsname, "tracefs" ) == 0 )
|
||||
{
|
||||
ptr += 8;
|
||||
auto end = ptr;
|
||||
while( *end && *end != ' ' ) end++;
|
||||
if( !*end )
|
||||
{
|
||||
tracy_free( tmp );
|
||||
return nullptr;
|
||||
}
|
||||
const auto len = end - ptr;
|
||||
auto ret = (char*)tracy_malloc( len+1 );
|
||||
memcpy( ret, ptr, len );
|
||||
auto len = strlen( ent->mnt_dir );
|
||||
ret = (char*)tracy_malloc( len + 1 );
|
||||
memcpy( ret, ent->mnt_dir, len );
|
||||
ret[len] = '\0';
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
while( *ptr && *ptr != '\n' ) ptr++;
|
||||
if( *ptr ) ptr++;
|
||||
}
|
||||
|
||||
tracy_free( tmp );
|
||||
return nullptr;
|
||||
endmntent( f );
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SysTraceStart( int64_t& samplingPeriod )
|
||||
|
||||
Reference in New Issue
Block a user