aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/utility.c b/utility.c
index 5bfed81d7..64598fab6 100644
--- a/utility.c
+++ b/utility.c
@@ -48,6 +48,7 @@
48#include <unistd.h> 48#include <unistd.h>
49#include <ctype.h> 49#include <ctype.h>
50#include <sys/param.h> /* for PATH_MAX */ 50#include <sys/param.h> /* for PATH_MAX */
51#include <sys/utsname.h> /* for uname(2) */
51 52
52#if defined BB_FEATURE_MOUNT_LOOP 53#if defined BB_FEATURE_MOUNT_LOOP
53#include <fcntl.h> 54#include <fcntl.h>
@@ -103,26 +104,20 @@ extern void fatalError(char *s, ...)
103} 104}
104 105
105#if defined (BB_INIT) || defined (BB_PS) 106#if defined (BB_INIT) || defined (BB_PS)
106
107#if ! defined BB_FEATURE_USE_PROCFS
108#error Sorry, I depend on the /proc filesystem right now.
109#endif
110/* Returns kernel version encoded as major*65536 + minor*256 + patch, 107/* Returns kernel version encoded as major*65536 + minor*256 + patch,
111 * so, for example, to check if the kernel is greater than 2.2.11: 108 * so, for example, to check if the kernel is greater than 2.2.11:
112 * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> } 109 * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
113 */ 110 */
114int get_kernel_revision() 111int get_kernel_revision()
115{ 112{
116 FILE *file; 113 struct utsname name;
117 int major = 0, minor = 0, patch = 0; 114 int major = 0, minor = 0, patch = 0;
118 115
119 file = fopen("/proc/sys/kernel/osrelease", "r"); 116 if (uname(&name) == -1) {
120 if (file == NULL) { 117 perror("cannot get system information");
121 /* bummer, /proc must not be mounted... */
122 return (0); 118 return (0);
123 } 119 }
124 fscanf(file, "%d.%d.%d", &major, &minor, &patch); 120 sscanf(name.version, "%d.%d.%d", &major, &minor, &patch);
125 fclose(file);
126 return major * 65536 + minor * 256 + patch; 121 return major * 65536 + minor * 256 + patch;
127} 122}
128#endif /* BB_INIT || BB_PS */ 123#endif /* BB_INIT || BB_PS */