chiark / gitweb /
use #pragma once instead of foo*foo #define guards
[elogind.git] / src / shared / missing.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 /* Missing glibc definitions to access certain kernel APIs */
25
26 #include <sys/resource.h>
27 #include <sys/syscall.h>
28 #include <fcntl.h>
29 #include <unistd.h>
30 #include <linux/oom.h>
31
32 #ifdef HAVE_AUDIT
33 #include <libaudit.h>
34 #endif
35
36 #include "macro.h"
37
38 #ifdef ARCH_MIPS
39 #include <asm/sgidefs.h>
40 #endif
41
42 #ifndef RLIMIT_RTTIME
43 #define RLIMIT_RTTIME 15
44 #endif
45
46 #ifndef F_LINUX_SPECIFIC_BASE
47 #define F_LINUX_SPECIFIC_BASE 1024
48 #endif
49
50 #ifndef F_SETPIPE_SZ
51 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
52 #endif
53
54 #ifndef F_GETPIPE_SZ
55 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
56 #endif
57
58 #ifndef IP_FREEBIND
59 #define IP_FREEBIND 15
60 #endif
61
62 #ifndef OOM_SCORE_ADJ_MIN
63 #define OOM_SCORE_ADJ_MIN (-1000)
64 #endif
65
66 #ifndef OOM_SCORE_ADJ_MAX
67 #define OOM_SCORE_ADJ_MAX 1000
68 #endif
69
70 #ifndef AUDIT_SERVICE_START
71 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
72 #endif
73
74 #ifndef AUDIT_SERVICE_STOP
75 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
76 #endif
77
78 #ifndef TIOCVHANGUP
79 #define TIOCVHANGUP 0x5437
80 #endif
81
82 #ifndef IP_TRANSPARENT
83 #define IP_TRANSPARENT 19
84 #endif
85
86 static inline int pivot_root(const char *new_root, const char *put_old) {
87         return syscall(SYS_pivot_root, new_root, put_old);
88 }
89
90 #ifdef __x86_64__
91 #  ifndef __NR_fanotify_init
92 #    define __NR_fanotify_init 300
93 #  endif
94 #  ifndef __NR_fanotify_mark
95 #    define __NR_fanotify_mark 301
96 #  endif
97 #elif defined _MIPS_SIM
98 #  if _MIPS_SIM == _MIPS_SIM_ABI32
99 #    ifndef __NR_fanotify_init
100 #      define __NR_fanotify_init 4336
101 #    endif
102 #    ifndef __NR_fanotify_mark
103 #      define __NR_fanotify_mark 4337
104 #    endif
105 #  elif _MIPS_SIM == _MIPS_SIM_NABI32
106 #    ifndef __NR_fanotify_init
107 #      define __NR_fanotify_init 6300
108 #    endif
109 #    ifndef __NR_fanotify_mark
110 #      define __NR_fanotify_mark 6301
111 #    endif
112 #  elif _MIPS_SIM == _MIPS_SIM_ABI64
113 #    ifndef __NR_fanotify_init
114 #      define __NR_fanotify_init 5295
115 #    endif
116 #    ifndef __NR_fanotify_mark
117 #      define __NR_fanotify_mark 5296
118 #    endif
119 #  endif
120 #else
121 #  ifndef __NR_fanotify_init
122 #    define __NR_fanotify_init 338
123 #  endif
124 #  ifndef __NR_fanotify_mark
125 #    define __NR_fanotify_mark 339
126 #  endif
127 #endif
128
129 static inline int fanotify_init(unsigned int flags, unsigned int event_f_flags) {
130         return syscall(__NR_fanotify_init, flags, event_f_flags);
131 }
132
133 static inline int fanotify_mark(int fanotify_fd, unsigned int flags, uint64_t mask,
134                                 int dfd, const char *pathname) {
135 #if defined _MIPS_SIM && _MIPS_SIM == _MIPS_SIM_ABI32 || defined __powerpc__ && !defined __powerpc64__
136         union {
137                 uint64_t _64;
138                 uint32_t _32[2];
139         } _mask;
140         _mask._64 = mask;
141
142         return syscall(__NR_fanotify_mark, fanotify_fd, flags,
143                        _mask._32[0], _mask._32[1], dfd, pathname);
144 #else
145         return syscall(__NR_fanotify_mark, fanotify_fd, flags, mask, dfd, pathname);
146 #endif
147 }
148
149 #ifndef BTRFS_IOCTL_MAGIC
150 #define BTRFS_IOCTL_MAGIC 0x94
151 #endif
152
153 #ifndef BTRFS_PATH_NAME_MAX
154 #define BTRFS_PATH_NAME_MAX 4087
155 #endif
156
157 struct btrfs_ioctl_vol_args {
158         int64_t fd;
159         char name[BTRFS_PATH_NAME_MAX + 1];
160 };
161
162 #ifndef BTRFS_IOC_DEFRAG
163 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, struct btrfs_ioctl_vol_args)
164 #endif
165
166 #ifndef BTRFS_SUPER_MAGIC
167 #define BTRFS_SUPER_MAGIC 0x9123683E
168 #endif
169
170 #ifndef MS_MOVE
171 #define MS_MOVE 8192
172 #endif
173
174 #ifndef MS_PRIVATE
175 #define MS_PRIVATE  (1 << 18)
176 #endif
177
178 static inline pid_t gettid(void) {
179         return (pid_t) syscall(SYS_gettid);
180 }
181
182 #ifndef SCM_SECURITY
183 #define SCM_SECURITY 0x03
184 #endif
185
186 #ifndef MS_STRICTATIME
187 #define MS_STRICTATIME (1<<24)
188 #endif
189
190 #ifndef PR_SET_NO_NEW_PRIVS
191 #define PR_SET_NO_NEW_PRIVS 38
192 #endif