From 9b60ec677047daf836c2679294bc1f87c9c76141 Mon Sep 17 00:00:00 2001 From: Manuel Teira Paz Date: Tue, 10 Mar 2009 08:12:13 +0000 Subject: 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 --- cpp/src/qpid/sys/solaris/SystemInfo.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'cpp') 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 #include #include +#include #include +#include +#include +#include +#include using namespace std; @@ -56,12 +61,12 @@ static const string LOCALHOST("127.0.0.1"); void SystemInfo::getLocalIpAddresses(uint16_t port, std::vector
&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 -- cgit v1.2.1