Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
565896e3
Commit
565896e3
authored
Sep 15, 2014
by
Steven Murray
Browse files
Added utils::setProcessNameAndCmdLine()
parent
5fc8b16d
Changes
2
Hide whitespace changes
Inline
Side-by-side
castor/utils/utils.cpp
View file @
565896e3
...
...
@@ -410,3 +410,44 @@ std::string castor::utils::serrnoToString(const int serrnoValue) throw() {
return
oss
.
str
();
}
}
//------------------------------------------------------------------------------
// setProcessNameAndCmdLine
//------------------------------------------------------------------------------
void
castor
::
utils
::
setProcessNameAndCmdLine
(
char
*
const
argv0
,
const
std
::
string
&
name
)
{
try
{
setProcessName
(
name
);
setCmdLine
(
argv0
,
name
);
}
catch
(
castor
::
exception
::
Exception
&
ne
)
{
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to set process name and command-line"
": "
<<
ne
.
getMessage
().
str
();
}
}
//------------------------------------------------------------------------------
// setProcessName
//------------------------------------------------------------------------------
void
castor
::
utils
::
setProcessName
(
const
std
::
string
&
name
)
{
char
buf
[
16
];
strncpy
(
buf
,
name
.
c_str
(),
sizeof
(
buf
));
buf
[
sizeof
(
buf
)
-
1
]
=
'\0'
;
if
(
prctl
(
PR_SET_NAME
,
buf
))
{
const
std
::
string
errMsg
=
errnoToString
(
errno
);
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to set process name: "
<<
errMsg
;
throw
ex
;
}
}
//------------------------------------------------------------------------------
// setCmdLine
//------------------------------------------------------------------------------
void
castor
::
utils
::
setCmdLine
(
char
*
const
argv0
,
const
std
::
string
&
cmdLine
)
throw
()
{
const
size_t
argv0Len
=
strlen
(
argv0
);
strncpy
(
argv0
,
cmdLine
.
c_str
(),
argv0Len
);
argv0
[
argv0Len
]
=
'\0'
;
}
castor/utils/utils.hpp
View file @
565896e3
...
...
@@ -242,6 +242,48 @@ std::string errnoToString(const int errnoValue) throw();
*/
std
::
string
serrnoToString
(
const
int
serrnoValue
)
throw
();
/**
* Sets both the process name and the command-line to the specified value.
*
* The command-line is set by modifiying argv[0] and the process name is
* modified using prctl(PR_SET_NAME, ...). Please note that the length of
* argv[0] cannot be changed and that prctl(PR_SET_NAME, ...) is limited to
* 15 characters plus the null terminator.
*
* @param argv0 In/out paramater: A pointer to argv[0].
* @param name The new name of the process. If the name is too long for either
* the command-line or the process name then it will truncated. Any truncation
* for argv[0] will be independent of any truncation for process name if argv[0]
* is not 15 characters in length.
*/
void
setProcessNameAndCmdLine
(
char
*
const
argv0
,
const
std
::
string
&
name
);
/**
* Sets the process name to the specified value.
*
* The process name is modified using prctl(PR_SET_NAME, ...). Please note that
* prctl(PR_SET_NAME, ...) is limited to 15 characters plus the null terminator.
*
* @param name The new name of the process. If the new name is longer than 15
* characters then it will be truncated.
*/
void
setProcessName
(
const
std
::
string
&
name
);
/**
* Sets both the process name and the command-line to the specified value.
*
* The command-line is set by modifiying argv[0] and the process name is
* modified using prctl(PR_SET_NAME, ...). Please note that the length of
* argv[0] cannot be changed and that prctl(PR_SET_NAME, ...) is limited to
* 15 characters plus the null terminator.
*
* @param argv0 In/out paramater: A pointer to argv[0].
* @param cmdLine The new command-line. If the new command-line is longer than
* argv[0] then it will be truncated.
*/
void
setCmdLine
(
char
*
const
argv0
,
const
std
::
string
&
cmdLine
)
throw
();
}
// namespace utils
}
// namespace castor
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment