Skip to content

Commit

Permalink
Remove bridging header - kinfo_proc bug fixed
Browse files Browse the repository at this point in the history
- Compiler crash fixed as of Swift 1.2, can do it all now in pure Swift :)
- Ref: #12
  • Loading branch information
beltex committed Feb 12, 2015
1 parent 9fef0ce commit 52829fb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 156 deletions.
12 changes: 0 additions & 12 deletions SystemKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
4C543D3B1A08399100C5D9B2 /* Battery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C543D3A1A08399100C5D9B2 /* Battery.swift */; };
4C6D98B81A3A8FF500BA2B36 /* IOReturn.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6D98B71A3A8FF500BA2B36 /* IOReturn.swift */; };
4C6D98B91A3A905E00BA2B36 /* IOReturn.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6D98B71A3A8FF500BA2B36 /* IOReturn.swift */; };
4C8004A31A23B53C00D57D90 /* kinfo_proc-bridge.c in Sources */ = {isa = PBXBuildFile; fileRef = 4C8004A11A23B53C00D57D90 /* kinfo_proc-bridge.c */; };
4C8004A41A23B53C00D57D90 /* kinfo_proc-bridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8004A21A23B53C00D57D90 /* kinfo_proc-bridge.h */; };
4C8004A51A23B58900D57D90 /* kinfo_proc-bridge.c in Sources */ = {isa = PBXBuildFile; fileRef = 4C8004A11A23B53C00D57D90 /* kinfo_proc-bridge.c */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -66,8 +63,6 @@
4C543D381A08398500C5D9B2 /* System.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = System.swift; sourceTree = "<group>"; };
4C543D3A1A08399100C5D9B2 /* Battery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Battery.swift; sourceTree = "<group>"; };
4C6D98B71A3A8FF500BA2B36 /* IOReturn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IOReturn.swift; sourceTree = "<group>"; };
4C8004A11A23B53C00D57D90 /* kinfo_proc-bridge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "kinfo_proc-bridge.c"; sourceTree = "<group>"; };
4C8004A21A23B53C00D57D90 /* kinfo_proc-bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "kinfo_proc-bridge.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -131,8 +126,6 @@
4C543D381A08398500C5D9B2 /* System.swift */,
4C4656631A678B9E0091A8CB /* Process.swift */,
4C6D98B71A3A8FF500BA2B36 /* IOReturn.swift */,
4C8004A11A23B53C00D57D90 /* kinfo_proc-bridge.c */,
4C8004A21A23B53C00D57D90 /* kinfo_proc-bridge.h */,
4C543D211A08396700C5D9B2 /* SystemKit.h */,
4C543D1F1A08396700C5D9B2 /* Supporting Files */,
);
Expand Down Expand Up @@ -172,7 +165,6 @@
buildActionMask = 2147483647;
files = (
4C543D221A08396700C5D9B2 /* SystemKit.h in Headers */,
4C8004A41A23B53C00D57D90 /* kinfo_proc-bridge.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -296,7 +288,6 @@
files = (
4C4656651A6790A40091A8CB /* Process.swift in Sources */,
4C6D98B91A3A905E00BA2B36 /* IOReturn.swift in Sources */,
4C8004A51A23B58900D57D90 /* kinfo_proc-bridge.c in Sources */,
4C4BE60E1A083A760085170A /* System.swift in Sources */,
4C4BE60F1A083A760085170A /* Battery.swift in Sources */,
4C4BE60A1A083A690085170A /* main.swift in Sources */,
Expand All @@ -310,7 +301,6 @@
4C543D391A08398500C5D9B2 /* System.swift in Sources */,
4C4656641A678B9E0091A8CB /* Process.swift in Sources */,
4C6D98B81A3A8FF500BA2B36 /* IOReturn.swift in Sources */,
4C8004A31A23B53C00D57D90 /* kinfo_proc-bridge.c in Sources */,
4C543D3B1A08399100C5D9B2 /* Battery.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -348,15 +338,13 @@
);
OTHER_SWIFT_FLAGS = "-D DEBUG";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SystemKit/kinfo_proc-bridge.h";
};
name = Debug;
};
4C4BE60C1A083A690085170A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SystemKit/kinfo_proc-bridge.h";
};
name = Release;
};
Expand Down
22 changes: 10 additions & 12 deletions SystemKit/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,25 @@ public struct ProcessAPI {


// BSD layer only stuff
var kinfoProc = kinfo_proc_systemkit(
p_stat: 0,
p_comm: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
e_ppid: 0,
e_pgid: 0,
uid: 0)
var kinfo = kinfo_proc()
var size = size_t(strideof(kinfo_proc))
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, pid]

kinfo_for_pid(pid, &kinfoProc)
// TODO: Error check
sysctl(&mib, u_int(mib.count), &kinfo, &size, nil, 0)

let command = withUnsafePointer(&kinfoProc.p_comm) {
let command = withUnsafePointer(&kinfo.kp_proc.p_comm) {
String.fromCString(UnsafePointer($0))!
}


list.append(ProcessInfo(pid : Int(pid),
ppid : Int(kinfoProc.e_ppid),
pgid : Int(kinfoProc.e_pgid),
uid : Int(kinfoProc.uid),
ppid : Int(kinfo.kp_eproc.e_ppid),
pgid : Int(kinfo.kp_eproc.e_pgid),
uid : Int(kinfo.kp_eproc.e_ucred.cr_uid),
command: command,
arch : arch(pid),
status : Int32(kinfoProc.p_stat)))
status : Int32(kinfo.kp_proc.p_stat)))

mach_port_deallocate(mach_task_self_, task)
}
Expand Down
24 changes: 0 additions & 24 deletions SystemKit/SystemKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,3 @@ FOUNDATION_EXPORT const unsigned char SystemKitVersionString[];

// In this header, you should import all the public headers of your framework
// using statements like #import <SystemKit/PublicHeader.h>


//------------------------------------------------------------------------------
// MARK: BRIDGE
//------------------------------------------------------------------------------


// This is copied from kinfo_proc-bridge.h. Temp fix, as frameworks don't allow
// bridging headers

#include <stdio.h>
#include <sys/sysctl.h>

// Temp simplified struct with only the things we need for now
typedef struct {
char p_stat; // S* process status
char p_comm[MAXCOMLEN + 1];
pid_t e_ppid; // Parent process id
// TODO: Why does kinfo_proc have this as pid_t? top works with it as gid_t
gid_t e_pgid; // Process group id
uid_t uid; // User ID
} kinfo_proc_systemkit;

int kinfo_for_pid(pid_t pid, kinfo_proc_systemkit *kinfo_sk);
63 changes: 0 additions & 63 deletions SystemKit/kinfo_proc-bridge.c

This file was deleted.

45 changes: 0 additions & 45 deletions SystemKit/kinfo_proc-bridge.h

This file was deleted.

0 comments on commit 52829fb

Please sign in to comment.