Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b662d53

Browse files
committedMay 16, 2024·
allocate make a std::vector<const char*> and pass .data() of that vector to commands.Run()
1 parent 0c54647 commit b662d53

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed
 

‎examples/fabric-admin/commands/interactive/InteractiveCommands.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ void ClearLine()
6262

6363
void ENFORCE_FORMAT(3, 0) LoggingCallback(const char * module, uint8_t category, const char * msg, va_list args)
6464
{
65+
if (sLogFile == nullptr)
66+
{
67+
return;
68+
}
69+
6570
uint64_t timeMs = chip::System::SystemClock().GetMonotonicMilliseconds64().count();
6671
uint64_t seconds = timeMs / 1000;
6772
uint64_t milliseconds = timeMs % 1000;
6873

6974
flockfile(sLogFile);
7075

71-
// Portable thread and process identifiers
72-
auto pid = static_cast<unsigned long>(getpid());
73-
auto tid = static_cast<unsigned long>(pthread_self());
74-
75-
fprintf(sLogFile, "[%llu.%06llu][%lu:%lu] CHIP:%s: ", static_cast<unsigned long long>(seconds),
76-
static_cast<unsigned long long>(milliseconds), pid, tid, module);
76+
fprintf(sLogFile, "[%llu.%06llu] CHIP:%s: ", static_cast<unsigned long long>(seconds),
77+
static_cast<unsigned long long>(milliseconds), module);
7778
vfprintf(sLogFile, msg, args);
7879
fprintf(sLogFile, "\n");
7980
fflush(sLogFile);

‎examples/fabric-admin/main.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,8 @@ int main(int argc, char * argv[])
4141
// Insert "interactive" and "start" after the executable name
4242
args.insert(args.begin() + 1, "interactive");
4343
args.insert(args.begin() + 2, "start");
44-
45-
// Update argc and argv to reflect the new arguments
46-
argc = static_cast<int>(args.size());
47-
for (size_t i = 0; i < args.size(); ++i)
48-
{
49-
argv[i] = const_cast<char *>(args[i].c_str());
50-
}
5144
}
5245

53-
// const char * args[] = { argv[0], "interactive", "start" };
5446
ExampleCredentialIssuerCommands credIssuerCommands;
5547
Commands commands;
5648

@@ -59,5 +51,11 @@ int main(int argc, char * argv[])
5951
registerClusters(commands, &credIssuerCommands);
6052
registerCommandsSubscriptions(commands, &credIssuerCommands);
6153

62-
return commands.Run(argc, argv);
54+
std::vector<char *> c_args;
55+
for (auto & arg : args)
56+
{
57+
c_args.push_back(const_cast<char *>(arg.c_str()));
58+
}
59+
60+
return commands.Run(static_cast<int>(c_args.size()), c_args.data());
6361
}

0 commit comments

Comments
 (0)
Please sign in to comment.