]> git.ipfire.org Git - thirdparty/chrony.git/blob - sys.c
ntp: fix log message for replaced source
[thirdparty/chrony.git] / sys.c
1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Richard P. Curnow 1997-2002
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 This file contains all the conditionally compiled bits that pull
25 in the various operating-system specific modules
26 */
27
28 #include "config.h"
29
30 #include "sysincl.h"
31
32 #include "sys.h"
33 #include "sys_null.h"
34 #include "logging.h"
35
36 #if defined(LINUX)
37 #include "sys_linux.h"
38 #include "sys_posix.h"
39 #elif defined(SOLARIS)
40 #include "sys_solaris.h"
41 #include "sys_posix.h"
42 #elif defined(NETBSD) || defined(FREEBSD)
43 #include "sys_netbsd.h"
44 #include "sys_posix.h"
45 #elif defined(MACOSX)
46 #include "sys_macosx.h"
47 #endif
48
49 /* ================================================== */
50
51 static int null_driver;
52
53 /* ================================================== */
54
55 void
56 SYS_Initialise(int clock_control)
57 {
58 null_driver = !clock_control;
59 if (null_driver) {
60 SYS_Null_Initialise();
61 return;
62 }
63 #if defined(LINUX)
64 SYS_Linux_Initialise();
65 #elif defined(SOLARIS)
66 SYS_Solaris_Initialise();
67 #elif defined(NETBSD) || defined(FREEBSD)
68 SYS_NetBSD_Initialise();
69 #elif defined(MACOSX)
70 SYS_MacOSX_Initialise();
71 #else
72 #error Unknown system
73 #endif
74 }
75
76 /* ================================================== */
77
78 void
79 SYS_Finalise(void)
80 {
81 if (null_driver) {
82 SYS_Null_Finalise();
83 return;
84 }
85 #if defined(LINUX)
86 SYS_Linux_Finalise();
87 #elif defined(SOLARIS)
88 SYS_Solaris_Finalise();
89 #elif defined(NETBSD) || defined(FREEBSD)
90 SYS_NetBSD_Finalise();
91 #elif defined(MACOSX)
92 SYS_MacOSX_Finalise();
93 #else
94 #error Unknown system
95 #endif
96 }
97
98 /* ================================================== */
99
100 void SYS_DropRoot(uid_t uid, gid_t gid)
101 {
102 #if defined(LINUX) && defined (FEAT_PRIVDROP)
103 SYS_Linux_DropRoot(uid, gid, !null_driver);
104 #elif defined(SOLARIS) && defined(FEAT_PRIVDROP)
105 SYS_Solaris_DropRoot(uid, gid);
106 #elif (defined(NETBSD) || defined(FREEBSD)) && defined(FEAT_PRIVDROP)
107 SYS_NetBSD_DropRoot(uid, gid);
108 #elif defined(MACOSX) && defined(FEAT_PRIVDROP)
109 SYS_MacOSX_DropRoot(uid, gid);
110 #else
111 LOG_FATAL("dropping root privileges not supported");
112 #endif
113 }
114
115 /* ================================================== */
116
117 void SYS_EnableSystemCallFilter(int level, SYS_SystemCallContext context)
118 {
119 #if defined(LINUX) && defined(FEAT_SCFILTER)
120 SYS_Linux_EnableSystemCallFilter(level, context);
121 #else
122 LOG_FATAL("system call filter not supported");
123 #endif
124 }
125
126 /* ================================================== */
127
128 void SYS_SetScheduler(int SchedPriority)
129 {
130 #if defined(MACOSX)
131 SYS_MacOSX_SetScheduler(SchedPriority);
132 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
133 SYS_Posix_SetScheduler(SchedPriority);
134 #else
135 LOG_FATAL("scheduler priority setting not supported");
136 #endif
137 }
138
139 /* ================================================== */
140
141 void SYS_LockMemory(void)
142 {
143 #if defined(HAVE_MLOCKALL)
144 SYS_Posix_MemLockAll();
145 #else
146 LOG_FATAL("memory locking not supported");
147 #endif
148 }
149
150 /* ================================================== */