PMGETCONTEXTHOSTNAME(3)
π PMGETCONTEXTHOSTNAME π
okay bestie, so this is from the Library Functions Manual of Performance Co-Pilot, and it's literally just "hey, what's the hostname for this PCP context?" energy. Three little functions, all vibing around the same question. Let's go π¦
β¨ NAME β¨
pmGetHostName, pmGetContextHostName, pmGetContextHostName_r β the trio that returns the hostname associated with a Performance Co-Pilot context. yes, all three, they're a package deal π
πΈ C SYNOPSIS πΈ
#include <pcp/pmapi.h>
int pmGetHostName(int id, char *buf, int buflen);
const char *pmGetContextHostName(int id);
char *pmGetContextHostName_r(int id, char *buf, int buflen);
cc ... -lpcp
note the -lpcp at the end, you have to link it, don't forget, it's giving "I forgot the linker flag" and we don't want that π
π DESCRIPTION π
So you've got a valid PCP context identifier β one you made earlier with pmNewContext(3) or pmDupContext(3) β and you want to know which host it's about. That's the whole plot.
pmGetContextHostName takes that id and hands you back the hostname associated with it. Simple. Iconic.
pmGetContextHostName_r does the exact same thing, but it stores the result in a user-supplied buffer β that's your buf, of length buflen β and honestly buflen should have room for at least MAXHOSTNAMELEN bytes. like, at minimum. give the girl some space π«Ά
pmGetHostName behaves similarly again, but it returns a status code</> to tell you success or failure instead of just yeeting the string at you.
okay now the part where it gets smart β¨
If the context id is associated with an archive source of data, then the hostname you get back is extracted from the archive label using pmGetArchiveLabel(3). cute, it read the label π
For live contexts, it will first try to grab the hostname from the PCP collector system using pmFetch(3) with the pmcd.hostname metric. and this is the good part: this is what lets client tools using this interface get an accurate host identifier even when there's port forwarding and tunnelled connections happening. no cap, tunnels would normally ruin the vibe but this handles it π₯
Should that not succeed, there's a fallback method. For local contexts β and "local" here means any of DSO, ``localhost'', or a Unix domain socket connection β a hostname will be sought via gethostname(3). For other contexts, the hostname extracted from the initial context host specification will be used instead. fallback queen π
π RETURN VALUE π
If id is not a valid PCP context identifier, the returned hostname is a zero length string. empty. nothing. ghosted. π
On failure, the return code of pmGetHostName is a negative PMAPI error code, which you can run through pmErrStr_r(3) for diagnostics about why it couldn't get the context hostname. that's your "what went wrong" translator, use it.
β οΈ NOTES β οΈ
pmGetContextHostNamereturns a pointer to a static buffer, so the returned value is only valid until the next call topmGetContextHostName. and therefore it is not thread-safe. bestie. be careful.
Multi-threaded applications should use pmGetHostName or pmGetContextHostName_r instead. those are the safe ones. pick them, protect your peace π§
π PCP ENVIRONMENT π
Environment variables with the prefix PCP_ are used to parameterize the file and directory names used by PCP. On each installation, the file /etc/pcp.conf contains the local values for these variables.
The $PCP_CONF variable may be used to specify an alternative configuration file, as described in pcp.conf(5).
Values for these variables may be obtained programmatically using the pmGetConfig(3) function. iykyk π
π SEE ALSO π
PCPIntro(1)PMAPI(3)gethostname(3)pmDupContext(3)pmErrStr_r(3)pmFetch(3)pmGetArchiveLabel(3)pmNewContext(3)pcp.conf(5)pcp.env(5)
and that's the whole page, bestie, you ate it π β¨
Performance Co-Pilot Β· PCP Β· PMGETCONTEXTHOSTNAME(3) β mwah, go get those hostnames ππ¦π
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2013,2020 Red Hat
- Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms