MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / GetProgramName

Method GetProgramName

jalib/jfilesystem.cpp:237–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237dmtcp::string
238jalib::Filesystem::GetProgramName()
239{
240 static dmtcp::string *value = NULL;
241
242 if (value == NULL) {
243 size_t len;
244 char cmdline[1024];
245 value = new (JALLOC_MALLOC(sizeof(dmtcp::string))) dmtcp::string(BaseName ( GetProgramPath() )); // uses /proc/self/exe
246 // We may rewrite "a.out" to "/lib/ld-linux.so.2 a.out". If so, find cmd.
247 if (!value->empty()
248 && jalib::elfInterpreter() != NULL
249 && *value == ResolveSymlink(jalib::elfInterpreter()) // e.g. /lib/ld-linux.so.2
250 && (len = _GetProgramCmdline(cmdline, sizeof(cmdline))) > 0
251 && len > strlen(cmdline) + 1 // more than one word in cmdline
252 && *(cmdline + strlen(cmdline) + 1) != '-') { // second word not a flag
253 *value = BaseName(cmdline + strlen(cmdline) + 1); // find second word
254 }
255 }
256 return *value;
257}
258
259dmtcp::string
260jalib::Filesystem::GetProgramPath()

Callers

nothing calls this directly

Calls 1

_GetProgramCmdlineFunction · 0.85

Tested by

no test coverage detected