]> 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 <string.h>
21 #include <sys/sysctl.h>
22 #include <sys/utsname.h>
23 #include "kernel-features.h"
24
25 #ifndef MIN
26 # define MIN(a,b) (((a)<(b))?(a):(b))
27 #endif
28
29 /* There is no prototype for __sysctl in that file. */
30 extern int __sysctl (int *name, int nlen, void *oldval,
31 size_t *oldlenp, void *newval, size_t newlen);
32
33
34 #ifdef SHARED
35 /* This is the function used in the dynamic linker to print the fatal error
36 message. */
37 static inline void
38 __attribute__ ((__noreturn__))
39 dl_fatal (const char *str)
40 {
41 _dl_sysdep_output (2, str, NULL);
42 _exit (1);
43 }
44 #endif
45
46
47 #define DL_SYSDEP_OSCHECK(FATAL) \
48 do { \
49 /* Test whether the kernel is new enough. This test is only \
50 performed if the library is not compiled to run on all \
51 kernels. */ \
52 if (__LINUX_KERNEL_VERSION > 0) \
53 { \
54 char bufmem[64]; \
55 char *buf = bufmem; \
56 unsigned int version; \
57 int parts; \
58 char *cp; \
59 struct utsname uts; \
60 \
61 /* Try the uname syscall */ \
62 if (__uname (&uts)) \
63 { \
64 /* This was not successful. Now try reading the /proc \
65 filesystem. */ \
66 ssize_t reslen; \
67 int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY); \
68 if (fd == -1 \
69 || (reslen = __read (fd, bufmem, sizeof (bufmem))) <= 0) \
70 /* This also didn't work. We give up since we cannot \
71 make sure the library can actually work. */ \
72 FATAL ("FATAL: cannot determine library version\n"); \
73 __close (fd); \
74 buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0'; \
75 } \
76 else \
77 buf = uts.release; \
78 \
79 /* Now convert it into a number. The string consists of at most \
80 three parts. */ \
81 version = 0; \
82 parts = 0; \
83 cp = buf; \
84 while ((*cp >= '0') && (*cp <= '9')) \
85 { \
86 unsigned int here = *cp++ - '0'; \
87 \
88 while ((*cp >= '0') && (*cp <= '9')) \
89 { \
90 here *= 10; \
91 here += *cp++ - '0'; \
92 } \
93 \
94 ++parts; \
95 version <<= 8; \
96 version |= here; \
97 \
98 if (*cp++ != '.') \
99 /* Another part following? */ \
100 break; \
101 } \
102 \
103 if (parts < 3) \
104 version <<= 8 * (3 - parts); \
105 \
106 /* Now we can test with the required version. */ \
107 if (version < __LINUX_KERNEL_VERSION) \
108 /* Not sufficent. */ \
109 FATAL ("FATAL: kernel too old\n"); \
110 } \
111 } while (0)