NTP Analyzer  0.8.2
Analyze the operation of time servers
InterProcess.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System;
23 using Mono.Unix;
24 using Mono.Unix.Native;
25 using Ntp.Common.Log;
26 
27 namespace Ntp.Common.System
28 {
29  public static class InterProcess
30  {
31  public enum Signal
32  {
33  Error = 0,
34  Exit,
35  Reload,
36  Refresh,
37  Notify
38  }
39 
40  private static UnixSignal sigterm, sigquit, sigint, sighup, sigusr1, sigusr2;
41 
42  private static readonly UnixSignal[] Signals =
43  {
44  sigint = new UnixSignal(Signum.SIGINT),
45  sigterm = new UnixSignal(Signum.SIGTERM),
46  sigquit = new UnixSignal(Signum.SIGQUIT),
47  sighup = new UnixSignal(Signum.SIGHUP),
48  sigusr1 = new UnixSignal(Signum.SIGUSR1),
49  sigusr2 = new UnixSignal(Signum.SIGUSR2)
50  };
51 
52  public static Signal Wait(string name, LogBase log)
53  {
54  while (true)
55  {
56  int i;
57  try
58  {
59  i = UnixSignal.WaitAny(Signals, -1);
60  }
61  catch (Exception e)
62  {
63  log.SignalError(e);
64  return Signal.Error;
65  }
66 
67  if (i < 0 || i >= Signals.Length)
68  {
69  log.UnknownSignal(Signals[i].Signum.ToString());
70  continue;
71  }
72 
73  log.ReceivedSignal(Signals[i].Signum.ToString());
74 
75  if (sigint.IsSet || sigterm.IsSet || sigquit.IsSet)
76  {
77  sigint.Reset();
78  sigterm.Reset();
79  sigquit.Reset();
80  return Signal.Exit;
81  }
82 
83  if (sighup.IsSet)
84  {
85  sighup.Reset();
86  return Signal.Refresh;
87  }
88 
89  if (sigusr1.IsSet)
90  {
91  sigusr1.Reset();
92  return Signal.Reload;
93  }
94 
95  if (sigusr2.IsSet)
96  {
97  sigusr2.Reset();
98  return Signal.Notify;
99  }
100  }
101  }
102  }
103 }
static Signal Wait(string name, LogBase log)
Definition: InterProcess.cs:52
var e
Definition: bootstrap.min.js:6