get_linux_version() returns a version of the currently running kernel,
encoded as in int, and is contained in common/linux_version.[ch].
Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
AC_CHECK_HEADERS([ \
arpa/inet.h \
+ linux/version.h \
netdb.h \
netinet/in.h \
sys/file.h \
common/bloom_filter.cc
if LINUX
-libcommon_la_SOURCES += common/secret.c
+libcommon_la_SOURCES += \
+ common/secret.c \
+ common/linux_version.c
endif
# these should go out of libcommon
common/AsyncReserver.h \
common/sync_filesystem.h \
common/cmdparse.h \
- common/hobject.h
+ common/hobject.h \
+ common/linux_version.h
noinst_LTLIBRARIES += libcommon.la
--- /dev/null
+#include "common/linux_version.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+int get_linux_version(void)
+{
+ struct utsname ubuf;
+ int a, b, c;
+ int n;
+
+ if (uname(&ubuf) || strcmp(ubuf.sysname, "Linux"))
+ return 0;
+
+ n = sscanf(ubuf.release, "%d.%d.%d", &a, &b, &c);
+ switch (n) {
+ case 3:
+ return KERNEL_VERSION(a, b, c);
+ case 2:
+ return KERNEL_VERSION(a, b, 0);
+ default:
+ return 0;
+ }
+}
--- /dev/null
+#ifndef CEPH_LINUX_VERSION_H
+#define CEPH_LINUX_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_LINUX_VERSION_H
+# include <linux/version.h>
+#endif
+
+#ifndef KERNEL_VERSION
+# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+#endif
+
+int get_linux_version(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CEPH_LINUX_VERSION_H */