diff options
author | Manuel Teira Paz <mteira@apache.org> | 2009-03-10 08:12:13 +0000 |
---|---|---|
committer | Manuel Teira Paz <mteira@apache.org> | 2009-03-10 08:12:13 +0000 |
commit | 9b60ec677047daf836c2679294bc1f87c9c76141 (patch) | |
tree | cad1af23aa77a3e1e7ee6cc9e66955ecbc056307 /cpp | |
parent | 267a601b03f4655d866b06a6f5d24ef127c0e3f1 (diff) | |
download | qpid-python-9b60ec677047daf836c2679294bc1f87c9c76141.tar.gz |
qpid/sys/solaris/SystemInfo.cpp
- Add a processName() solaris implementation
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@752015 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rwxr-xr-x | cpp/src/qpid/sys/solaris/SystemInfo.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/cpp/src/qpid/sys/solaris/SystemInfo.cpp b/cpp/src/qpid/sys/solaris/SystemInfo.cpp index 4501462767..0075a89021 100755 --- a/cpp/src/qpid/sys/solaris/SystemInfo.cpp +++ b/cpp/src/qpid/sys/solaris/SystemInfo.cpp @@ -33,7 +33,12 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <stdio.h> #include <errno.h> +#include <limits.h> +#include <procfs.h> +#include <fcntl.h> +#include <sys/types.h> using namespace std; @@ -56,12 +61,12 @@ static const string LOCALHOST("127.0.0.1"); void SystemInfo::getLocalIpAddresses(uint16_t port, std::vector<Address> &addrList) { - int s = socket (PF_INET, SOCK_STREAM, 0); + int s = socket(PF_INET, SOCK_STREAM, 0); for (int i=1;;i++) { struct lifreq ifr; ifr.lifr_index = i; if (::ioctl(s, SIOCGIFADDR, &ifr) < 0) { - continue; + break; } struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.lifr_addr; std::string addr(inet_ntoa(sin->sin_addr)); @@ -99,6 +104,20 @@ uint32_t SystemInfo::getParentProcessId() return (uint32_t) ::getppid(); } +string SystemInfo::getProcessName() +{ + psinfo processInfo; + char procfile[PATH_MAX]; + int fd; + string value; + snprintf(procfile, PATH_MAX, "/proc/%d/psinfo", getProcessId()); + if ((fd = open(procfile, O_RDONLY)) >= 0) { + if (read(fd, (void *) &processInfo, sizeof(processInfo)) == sizeof(processInfo)) { + value = processInfo.pr_fname; + } + } + return value; +} }} // namespace qpid::sys |