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

This commit is contained in:
Guy M. Broome 2018-03-05 16:27:27 -05:00 committed by Hisham Muhammad
parent 76ef3682db
commit cefbe499db
4 changed files with 21 additions and 15 deletions

View File

@ -34,10 +34,10 @@ typedef enum SolarisProcessFields {
typedef struct SolarisProcess_ {
Process super;
int kernel;
Process super;
int kernel;
zoneid_t zoneid;
char zname[ZONENAME_MAX+1];
char* zname;
taskid_t taskid;
projid_t projid;
poolid_t poolid;

View File

@ -26,10 +26,10 @@ typedef enum SolarisProcessFields {
typedef struct SolarisProcess_ {
Process super;
int kernel;
Process super;
int kernel;
zoneid_t zoneid;
char zname[ZONENAME_MAX+1];
char* zname;
taskid_t taskid;
projid_t projid;
poolid_t poolid;

View File

@ -7,8 +7,8 @@ in the source distribution for its full text.
*/
#include "ProcessList.h"
#include "SolarisProcessList.h"
#include "SolarisProcess.h"
#include "SolarisProcessList.h"
#include <unistd.h>
#include <stdlib.h>
@ -31,7 +31,7 @@ in the source distribution for its full text.
#include <kstat.h>
#include <sys/param.h>
#include <sys/zone.h>
#include <zone.h>
#include <sys/uio.h>
#include <sys/resource.h>
#include <sys/sysconf.h>
@ -72,15 +72,17 @@ static void setCommand(Process* process, const char* command, int 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 ) {
strncpy( sproc->zname, "global ", 11);
zname = xStrdup("global ");
} else if ( kd == NULL ) {
strncpy( sproc->zname, "unknown ", 11);
zname = xStrdup("unknown ");
} else {
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) {
@ -325,7 +327,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->nlwp = _psinfo.pr_nlwp;
proc->session = _pstatus.pr_sid;
setCommand(proc,_psinfo.pr_fname,PRFNSZ);
setZoneName(spl->kd,sproc);
sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
proc->majflt = _prusage.pr_majf;
proc->minflt = _prusage.pr_minf;
proc->m_resident = (_psinfo.pr_rssize)/8;
@ -354,7 +356,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc->nlwp = _psinfo.pr_nlwp;
proc->user = UsersTable_getRef(this->usersTable, proc->st_uid);
setCommand(proc,_psinfo.pr_fname,PRFNSZ);
setZoneName(spl->kd,sproc);
sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
proc->majflt = _prusage.pr_majf;
proc->minflt = _prusage.pr_minf;
proc->m_resident = (_psinfo.pr_rssize)/8;

View File

@ -15,7 +15,7 @@ in the source distribution for its full text.
#include <kstat.h>
#include <sys/param.h>
#include <sys/zone.h>
#include <zone.h>
#include <sys/uio.h>
#include <sys/resource.h>
#include <sys/sysconf.h>
@ -44,10 +44,14 @@ typedef struct SolarisProcessList_ {
CPUData* cpus;
} SolarisProcessList;
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc);
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* this);
void ProcessList_goThroughEntries(ProcessList* this);
#endif