Skip to content

Commit 90884fa

Browse files
committed
Fix compile errors: filepath shadow and struct field names
1 parent 31c0b94 commit 90884fa

1 file changed

Lines changed: 32 additions & 30 deletions

File tree

process/process_aix.go

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type PrSiginfo64 struct {
124124
SiImm int32 // immediate data
125125
SiStatus int32 // exit value or signal
126126
Pad1 uint32 // reserved for future use
127-
SiUid uint64 // real user id of sending process
127+
SiUID uint64 // real user id of sending process
128128
SiPid uint64 // sending process id
129129
SiAddr prptr64 // address of faulting instruction
130130
SiBand int64 // band event for SIGPOLL
@@ -250,8 +250,8 @@ type AIXPSInfo struct {
250250
Flag2 uint32 // process flags from proc struct p_flag2
251251
Nlwp uint32 // number of threads in process
252252
Pad1 uint32 // reserved for future use
253-
Uid uint64 // real user id
254-
Euid uint64 // effective user id
253+
UID uint64 // real user id
254+
EUID uint64 // effective user id
255255
Gid uint64 // real group id
256256
Egid uint64 // effective group id
257257
Pid uint64 // unique process id
@@ -402,7 +402,7 @@ func (p *Process) StatusWithContext(ctx context.Context) ([]string, error) {
402402
return []string{p.status}, nil
403403
}
404404

405-
func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
405+
func (p *Process) ForegroundWithContext(_ context.Context) (bool, error) {
406406
return false, common.ErrNotImplementedError
407407
}
408408

@@ -460,7 +460,7 @@ func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
460460
return nice, nil
461461
}
462462

463-
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
463+
func (p *Process) IOniceWithContext(_ context.Context) (int32, error) {
464464
return 0, common.ErrNotImplementedError
465465
}
466466

@@ -510,7 +510,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
510510
}
511511

512512
// getRlimitFromUlimit gets resource limits via ulimit command
513-
func (p *Process) getRlimitFromUlimit(ctx context.Context, gatherUsed bool) ([]RlimitStat, error) {
513+
func (p *Process) getRlimitFromUlimit(ctx context.Context, _ bool) ([]RlimitStat, error) {
514514
cmd := exec.CommandContext(ctx, "sh", "-c", "ulimit -a")
515515
output, err := cmd.Output()
516516
if err != nil {
@@ -600,7 +600,7 @@ func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, e
600600
}, nil
601601
}
602602

603-
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
603+
func (p *Process) NumCtxSwitchesWithContext(_ context.Context) (*NumCtxSwitchesStat, error) {
604604
// AIX ps doesn't have -Leo format. Try using -o format with THREAD output
605605
// Fallback: Use ps -m to get thread info which includes context switch data in some AIX versions
606606
// For now, return error as AIX doesn't expose this in standard ps
@@ -648,7 +648,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
648648
return cpuTimes, nil
649649
}
650650

651-
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
651+
func (p *Process) CPUAffinityWithContext(_ context.Context) ([]int32, error) {
652652
// AIX ps command does not support psr field specifier in System V style
653653
// Berkeley style ps doesn't provide CPU affinity information
654654
// This metric is not available on AIX
@@ -679,7 +679,7 @@ func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, e
679679
return pageFaults, nil
680680
}
681681

682-
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
682+
func (p *Process) ChildrenWithContext(_ context.Context) ([]*Process, error) {
683683
return nil, common.ErrNotImplementedError
684684
}
685685

@@ -705,13 +705,13 @@ func (p *Process) ConnectionsMaxWithContext(ctx context.Context, maxConn int) ([
705705
}
706706

707707
// getConnectionsUsingNetstat retrieves network connections using AIX netstat command.
708-
// DEPRECATED: Use net module's ConnectionsPidMaxWithContext instead
708+
// Deprecated: Use net module's ConnectionsPidMaxWithContext instead
709709
// This function is kept for backward compatibility but delegates to the net module
710710
func (p *Process) getConnectionsUsingNetstat(ctx context.Context, maxConn int) ([]net.ConnectionStat, error) {
711711
return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, maxConn)
712712
}
713713

714-
func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) {
714+
func (p *Process) MemoryMapsWithContext(ctx context.Context, _ bool) (*[]MemoryMapsStat, error) {
715715
// Use AIX procmap command to retrieve detailed memory address space maps
716716
// procmap provides information about memory regions including HEAP, STACK, TEXT, etc.
717717
pid := p.Pid
@@ -733,7 +733,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
733733
// 0 10000000 262144K r-- m KERTXT 10002
734734
// 10000000 1000ce95 51K r-x s MAINTEXT 8b8117 init
735735
// 200003d8 20036288 215K rw- sm MAINDATA 890192 init
736-
func (p *Process) parseMemoryMaps(output string) *[]MemoryMapsStat {
736+
func (_ *Process) parseMemoryMaps(output string) *[]MemoryMapsStat {
737737
maps := make([]MemoryMapsStat, 0)
738738
lines := strings.Split(output, "\n")
739739

@@ -802,20 +802,22 @@ func parseSizeField(sizeStr string) uint64 {
802802
sizeStr = strings.TrimSpace(sizeStr)
803803

804804
// Check for unit suffixes
805-
if strings.HasSuffix(sizeStr, "K") || strings.HasSuffix(sizeStr, "k") {
805+
if len(sizeStr) > 0 {
806+
lastChar := strings.ToLower(string(sizeStr[len(sizeStr)-1]))
806807
numStr := sizeStr[:len(sizeStr)-1]
807-
if num, err := strconv.ParseUint(numStr, 10, 64); err == nil {
808-
return num * 1024
809-
}
810-
} else if strings.HasSuffix(sizeStr, "M") || strings.HasSuffix(sizeStr, "m") {
811-
numStr := sizeStr[:len(sizeStr)-1]
812-
if num, err := strconv.ParseUint(numStr, 10, 64); err == nil {
813-
return num * 1024 * 1024
814-
}
815-
} else if strings.HasSuffix(sizeStr, "G") || strings.HasSuffix(sizeStr, "g") {
816-
numStr := sizeStr[:len(sizeStr)-1]
817-
if num, err := strconv.ParseUint(numStr, 10, 64); err == nil {
818-
return num * 1024 * 1024 * 1024
808+
switch lastChar {
809+
case "k":
810+
if num, err := strconv.ParseUint(numStr, 10, 64); err == nil {
811+
return num * 1024
812+
}
813+
case "m":
814+
if num, err := strconv.ParseUint(numStr, 10, 64); err == nil {
815+
return num * 1024 * 1024
816+
}
817+
case "g":
818+
if num, err := strconv.ParseUint(numStr, 10, 64); err == nil {
819+
return num * 1024 * 1024 * 1024
820+
}
819821
}
820822
}
821823

@@ -827,7 +829,7 @@ func parseSizeField(sizeStr string) uint64 {
827829
return 0
828830
}
829831

830-
func (p *Process) EnvironWithContext(ctx context.Context) ([]string, error) {
832+
func (p *Process) EnvironWithContext(_ context.Context) ([]string, error) {
831833
// AIX /proc does not expose environment variables in a standard text format
832834
// Envp in psinfo is a user-space pointer that is not directly accessible
833835
return nil, common.ErrNotImplementedError
@@ -849,7 +851,7 @@ func limitToUint(val string) (uint64, error) {
849851
}
850852

851853
// Get num_fds from /proc/(pid)/limits (not available in AIX)
852-
func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat, error) {
854+
func (p *Process) fillFromLimitsWithContext(_ context.Context) ([]RlimitStat, error) {
853855
// AIX /proc does not expose resource limits in a standard procfs location
854856
return nil, common.ErrNotImplementedError
855857
}
@@ -878,7 +880,7 @@ func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []*OpenFile
878880
var openfiles []*OpenFilesStat
879881
for _, fd := range fnames {
880882
fpath := filepath.Join(statPath, fd)
881-
filepath, err := os.Readlink(fpath)
883+
linkPath, err := os.Readlink(fpath)
882884
if err != nil {
883885
continue
884886
}
@@ -887,7 +889,7 @@ func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []*OpenFile
887889
return numFDs, openfiles, err
888890
}
889891
o := &OpenFilesStat{
890-
Path: filepath,
892+
Path: linkPath,
891893
Fd: t,
892894
}
893895
openfiles = append(openfiles, o)
@@ -1271,7 +1273,7 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error {
12711273
err = binary.Read(infoFile, binary.BigEndian, &aixPSinfo)
12721274
if err == nil {
12731275
// Extract UIDs: real UID, effective UID, saved UID (use effective as third), and fsuid (use effective)
1274-
p.uids = []uint32{uint32(aixPSinfo.Uid), uint32(aixPSinfo.Euid), uint32(aixPSinfo.Euid), uint32(aixPSinfo.Euid)}
1276+
p.uids = []uint32{uint32(aixPSinfo.UID), uint32(aixPSinfo.EUID), uint32(aixPSinfo.EUID), uint32(aixPSinfo.EUID)}
12751277
// Extract GIDs: real GID, effective GID, saved GID (use effective as third), and fsgid (use effective)
12761278
p.gids = []uint32{uint32(aixPSinfo.Gid), uint32(aixPSinfo.Egid), uint32(aixPSinfo.Egid), uint32(aixPSinfo.Egid)}
12771279
// Extract number of threads from Nlwp field

0 commit comments

Comments
 (0)