mirror of
https://bitbucket.org/anguist/ntpa
synced 2025-10-05 10:30:56 +00:00
Reference clean up
This commit is contained in:
@ -24,7 +24,6 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Ntp.Analyzer.Log;
|
||||
using Ntp.Analyzer.Process;
|
||||
@ -38,38 +37,6 @@ namespace Ntp.Analyzer.Cli
|
||||
/// </summary>
|
||||
public static class MainClass
|
||||
{
|
||||
#if __MonoCS__
|
||||
[DllImport ("libc")]
|
||||
private static extern int getpid ();
|
||||
|
||||
[DllImport ("libc")] // Linux
|
||||
private static extern int prctl (int option, byte[] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
|
||||
|
||||
[DllImport ("libc")] // BSD
|
||||
private static extern void setproctitle (byte[] fmt, byte[] str_arg);
|
||||
|
||||
/// <summary>
|
||||
/// This is from http://abock.org/2006/02/09/changing-process-name-in-mono/
|
||||
/// </summary>
|
||||
/// <param name="name">Name.</param>
|
||||
private static void SetPosixProcessName (string name)
|
||||
{
|
||||
try {
|
||||
if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
|
||||
throw new ApplicationException ("Error setting process name: " + Mono.Unix.Native.Stdlib.GetLastError ());
|
||||
}
|
||||
} catch (EntryPointNotFoundException) {
|
||||
// Not every BSD has setproctitle
|
||||
try {
|
||||
setproctitle (Encoding.ASCII.GetBytes ("%s\0"), Encoding.ASCII.GetBytes (name + "\0"));
|
||||
} catch (EntryPointNotFoundException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
private static int getpid () { return 0; }
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The entry point of the program, where the program control starts and ends.
|
||||
/// </summary>
|
||||
@ -97,7 +64,7 @@ namespace Ntp.Analyzer.Cli
|
||||
}
|
||||
|
||||
string configFile = (args.Length > 0) ? args [0] : "/etc/ntpa.conf";
|
||||
int pid = getpid ();
|
||||
int pid = ProcessInfo.ProcessId;
|
||||
|
||||
Main main = new Main (configFile, pid, name);
|
||||
main.Start ();
|
||||
@ -109,4 +76,4 @@ namespace Ntp.Analyzer.Cli
|
||||
Console.WriteLine("Usage: ntpa [configuration file | stop] [instance name]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,6 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Mono.Posix" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
|
Reference in New Issue
Block a user