Skip to content

Commit

Permalink
no envp/args
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy committed Feb 3, 2025
1 parent c2e1abc commit 4dde6e4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 58 deletions.
57 changes: 3 additions & 54 deletions shared/src/native-src/library_config.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#include <iostream>
#include <string>
#include <sys/stat.h>

#include <vector>
#include <fstream>
#include "library_config.h"
#ifndef _WINDOWS
#include <datadog/library-config.h>
#include <unistd.h>
extern char **environ;
#endif
#include <datadog/common.h>

#endif
#include "util.h"

// TODO: change path to new location & add Windows
Expand All @@ -25,64 +18,20 @@ shared::LibraryConfig::to_char_slice(std::string const& str)
}

#ifndef _WINDOWS
ddog_Slice_CharSlice
shared::LibraryConfig::to_slice_char_slice(const std::vector<std::string>& vec) {
ddog_CharSlice* slices = new ddog_CharSlice[vec.size()];
for (size_t i = 0; i < vec.size(); i++) {
slices[i] = to_char_slice(vec[i]);
}
return {slices, vec.size()};
}

std::vector<shared::ConfigEntry>
shared::LibraryConfig::get_configuration(bool debug_logs)
{
// Get environment
std::vector<std::string> envp;
for (char **current = environ; *current; current++) {
envp.push_back(*current);
}

// Get args (by reading /proc/self/cmdline); linux only for now
// TODO: add MacOS support
std::vector<std::string> args;
#ifdef __linux__
std::ifstream cmdline("/proc/self/cmdline", std::ios::in);
if (cmdline) {
std::string arg;
char ch;
while (cmdline.get(ch)) {
if (ch == '\0') {
if (!arg.empty()) {
args.push_back(arg);
arg.clear();
}
} else {
arg.push_back(ch);
}
}
if (!arg.empty()) {
args.push_back(arg);
}
}
#endif

// Get configuration
ddog_ProcessInfo process_info{
.args = shared::LibraryConfig::to_slice_char_slice(args),
.envp = shared::LibraryConfig::to_slice_char_slice(envp),
.args = {nullptr, 0},
.envp = {nullptr, 0},
.language = shared::LibraryConfig::to_char_slice("dotnet"),
};

ddog_Configurator *configurator = ddog_library_configurator_new(debug_logs);
ddog_Result_VecLibraryConfig config_result = ddog_library_configurator_get_path(configurator, process_info, shared::LibraryConfig::to_char_slice(shared::LibraryConfig::config_path));
if (config_result.tag == DDOG_RESULT_VEC_LIBRARY_CONFIG_ERR_VEC_LIBRARY_CONFIG) {
ddog_Error err = config_result.err;
if (debug_logs) {
auto ddog_err = ddog_Error_message(&err);
std::string err_msg;
std::cerr << err_msg.assign(ddog_err.ptr, ddog_err.ptr + ddog_err.len) << std::endl;
}
ddog_Error_drop(&err);
return {};
}
Expand Down
3 changes: 0 additions & 3 deletions shared/src/native-src/library_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ typedef struct ConfigEntryFFI {
class LibraryConfig
{
private:
#ifndef _WINDOWS
static ddog_Slice_CharSlice to_slice_char_slice(const std::vector<std::string>& vec);
#endif
static ddog_CharSlice to_char_slice(const std::string& str);

public:
Expand Down
2 changes: 1 addition & 1 deletion tracer/build/_build/Build.Shared.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Version FindMinimumGlibcVersion(AbsolutePath libraryPath)

return output
.Where(x=>x.Contains("@GLIBC_"))
.Where(x => x.Contains("U "))
.Where(x=>x.Contains("U "))
.Select(x=> System.Version.Parse(x.Substring(x.IndexOf("@GLIBC_") + 7)))
.OrderDescending()
.FirstOrDefault();
Expand Down

0 comments on commit 4dde6e4

Please sign in to comment.