Commit da401078 authored by Guy M. Broome's avatar Guy M. Broome Committed by Hisham Muhammad
Browse files

Solaris: fix malloc() / free() issues with zone name handling

parent 3f7622a3
...@@ -34,10 +34,10 @@ typedef enum SolarisProcessFields { ...@@ -34,10 +34,10 @@ typedef enum SolarisProcessFields {
typedef struct SolarisProcess_ { typedef struct SolarisProcess_ {
Process super; Process super;
int kernel; int kernel;
zoneid_t zoneid; zoneid_t zoneid;
char zname[ZONENAME_MAX+1]; char* zname;
taskid_t taskid; taskid_t taskid;
projid_t projid; projid_t projid;
poolid_t poolid; poolid_t poolid;
......
...@@ -26,10 +26,10 @@ typedef enum SolarisProcessFields { ...@@ -26,10 +26,10 @@ typedef enum SolarisProcessFields {
typedef struct SolarisProcess_ { typedef struct SolarisProcess_ {
Process super; Process super;
int kernel; int kernel;
zoneid_t zoneid; zoneid_t zoneid;
char zname[ZONENAME_MAX+1]; char* zname;
taskid_t taskid; taskid_t taskid;
projid_t projid; projid_t projid;
poolid_t poolid; poolid_t poolid;
......
...@@ -7,8 +7,8 @@ in the source distribution for its full text. ...@@ -7,8 +7,8 @@ in the source distribution for its full text.
*/ */
#include "ProcessList.h" #include "ProcessList.h"
#include "SolarisProcessList.h"
#include "SolarisProcess.h" #include "SolarisProcess.h"
#include "SolarisProcessList.h"
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -31,7 +31,7 @@ in the source distribution for its full text. ...@@ -31,7 +31,7 @@ in the source distribution for its full text.
#include <kstat.h> #include <kstat.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/zone.h> #include <zone.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/sysconf.h> #include <sys/sysconf.h>
...@@ -72,15 +72,17 @@ static void setCommand(Process* process, const char* command, int len) { ...@@ -72,15 +72,17 @@ static void setCommand(Process* process, const char* command, int len) {
process->commLen = len; process->commLen = len;
} }
static void setZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
char* zname;
if ( sproc->zoneid == 0 ) { if ( sproc->zoneid == 0 ) {
strncpy( sproc->zname, "global ", 11); zname = xStrdup("global ");
} else if ( kd == NULL ) { } else if ( kd == NULL ) {
strncpy( sproc->zname, "unknown ", 11); zname = xStrdup("unknown ");
} else { } else {
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
strncpy( sproc->zname, ks->ks_name, strlen(ks->ks_name) ); zname = xStrdup(ks->ks_name);
} }
return zname;
} }
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
...@@ -325,7 +327,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { ...@@ -325,7 +327,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->nlwp = _psinfo.pr_nlwp; proc->nlwp = _psinfo.pr_nlwp;
proc->session = _pstatus.pr_sid; proc->session = _pstatus.pr_sid;
setCommand(proc,_psinfo.pr_fname,PRFNSZ); setCommand(proc,_psinfo.pr_fname,PRFNSZ);
setZoneName(spl->kd,sproc); sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
proc->majflt = _prusage.pr_majf; proc->majflt = _prusage.pr_majf;
proc->minflt = _prusage.pr_minf; proc->minflt = _prusage.pr_minf;
proc->m_resident = (_psinfo.pr_rssize)/8; proc->m_resident = (_psinfo.pr_rssize)/8;
...@@ -354,7 +356,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { ...@@ -354,7 +356,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->nlwp = _psinfo.pr_nlwp; proc->nlwp = _psinfo.pr_nlwp;
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
setCommand(proc,_psinfo.pr_fname,PRFNSZ); setCommand(proc,_psinfo.pr_fname,PRFNSZ);
setZoneName(spl->kd,sproc); sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
proc->majflt = _prusage.pr_majf; proc->majflt = _prusage.pr_majf;
proc->minflt = _prusage.pr_minf; proc->minflt = _prusage.pr_minf;
proc->m_resident = (_psinfo.pr_rssize)/8; proc->m_resident = (_psinfo.pr_rssize)/8;
......
...@@ -15,7 +15,7 @@ in the source distribution for its full text. ...@@ -15,7 +15,7 @@ in the source distribution for its full text.
#include <kstat.h> #include <kstat.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/zone.h> #include <zone.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/sysconf.h> #include <sys/sysconf.h>
...@@ -44,10 +44,14 @@ typedef struct SolarisProcessList_ { ...@@ -44,10 +44,14 @@ typedef struct SolarisProcessList_ {
CPUData* cpus; CPUData* cpus;
} SolarisProcessList; } SolarisProcessList;
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc);
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* this); void ProcessList_delete(ProcessList* this);
void ProcessList_goThroughEntries(ProcessList* this); void ProcessList_goThroughEntries(ProcessList* this);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment