]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/dl-osinfo.h
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / dl-osinfo.h
1 /* Operating system specific code for generic dynamic loader functions.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <sys/sysctl.h>
21 #include "kernel-features.h"
22
23 #ifndef MIN
24 # define MIN(a,b) (((a)<(b))?(a):(b))
25 #endif
26
27 /* There is no prototype for __sysctl in that file. */
28 extern int __sysctl (int *name, int nlen, void *oldval,
29 size_t *oldlenp, void *newval, size_t newlen);
30
31
32 #ifdef SHARED
33 /* This is the function used in the dynamic linker to print the fatal error
34 message. */
35 static inline void
36 __attribute__ ((__noreturn__))
37 dl_fatal (const char *str)
38 {
39 _dl_sysdep_output (2, str, NULL);
40 _exit (1);
41 }
42 #endif
43
44
45 #define DL_SYSDEP_OSCHECK(FATAL) \
46 do { \
47 /* Test whether the kernel is new enough. This test is only \
48 performed if the library is not compiled to run on all \
49 kernels. */ \
50 if (__LINUX_KERNEL_VERSION > 0) \
51 { \
52 static const int sysctl_args[] = { CTL_KERN, KERN_OSRELEASE }; \
53 char buf[64]; \
54 size_t reslen = sizeof (buf); \
55 unsigned int version; \
56 int parts; \
57 char *cp; \
58 \
59 /* Try reading the number using `sysctl' first. */ \
60 if (__sysctl ((int *) sysctl_args, \
61 sizeof (sysctl_args) / sizeof (sysctl_args[0]), \
62 buf, &reslen, NULL, 0) < 0) \
63 { \
64 /* This was not successful. Now try reading the /proc \
65 filesystem. */ \
66 int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY); \
67 if (fd == -1 \
68 || (reslen = __read (fd, buf, sizeof (buf))) <= 0) \
69 /* This also didn't work. We give up since we cannot \
70 make sure the library can actually work. */ \
71 FATAL ("FATAL: cannot determine library version\n"); \
72 \
73 __close (fd); \
74 } \
75 buf[MIN (reslen, sizeof (buf) - 1)] = '\0'; \
76 \
77 /* Now convert it into a number. The string consists of at most \
78 three parts. */ \
79 version = 0; \
80 parts = 0; \
81 cp = buf; \
82 while ((*cp >= '0') && (*cp <= '9')) \
83 { \
84 unsigned int here = *cp++ - '0'; \
85 \
86 while ((*cp >= '0') && (*cp <= '9')) \
87 { \
88 here *= 10; \
89 here += *cp++ - '0'; \
90 } \
91 \
92 ++parts; \
93 version <<= 8; \
94 version |= here; \
95 \
96 if (*cp++ != '.') \
97 /* Another part following? */ \
98 break; \
99 } \
100 \
101 if (parts < 3) \
102 version <<= 8 * (3 - parts); \
103 \
104 /* Now we can test with the required version. */ \
105 if (version < __LINUX_KERNEL_VERSION) \
106 /* Not sufficent. */ \
107 FATAL ("FATAL: kernel too old\n"); \
108 } \
109 } while (0)