2012-03-02 17:59:36 +05:30
|
|
|
/*
|
2015-06-19 16:30:46 +05:30
|
|
|
* libprocps - Library to read proc filesystem
|
2002-12-15 06:00:17 +05:30
|
|
|
*
|
2015-06-19 16:30:46 +05:30
|
|
|
* Copyright (C) 1995 Martin Schulze <joey@infodrom.north.de>
|
|
|
|
* Copyright (C) 1996 Charles Blake <cblake@bbn.com>
|
|
|
|
* Copyright (C) 2003 Albert Cahalan
|
|
|
|
* Copyright (C) 2015 Craig Small <csmall@enc.com.au>
|
2002-12-15 06:00:17 +05:30
|
|
|
*
|
2012-03-02 17:59:36 +05:30
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-02-02 04:17:29 +05:30
|
|
|
*/
|
2015-06-19 16:30:46 +05:30
|
|
|
#include <errno.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <stdio.h>
|
2015-06-19 16:30:46 +05:30
|
|
|
#include "procps-private.h"
|
2002-10-10 05:31:37 +05:30
|
|
|
#include "version.h"
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2015-06-19 16:30:46 +05:30
|
|
|
#define PROCFS_OSRELEASE "/proc/sys/kernel/osrelease"
|
2013-03-31 10:30:00 +05:30
|
|
|
|
2015-06-19 16:30:46 +05:30
|
|
|
/*
|
|
|
|
* procps_linux_version
|
2015-06-19 19:11:51 +05:30
|
|
|
*
|
|
|
|
* Return the current running Linux version release as shown in
|
2015-06-19 16:30:46 +05:30
|
|
|
* the procps filesystem.
|
|
|
|
*
|
|
|
|
* There are three ways you can get OS release:
|
|
|
|
* 1) /proc/sys/kernel/osrelease - returns correct version of procfs
|
|
|
|
* 2) /proc/version - returns version of kernel e.g. BSD this is wrong
|
|
|
|
* 3) uname and uts.release - same as /proc/version field #3
|
|
|
|
*
|
|
|
|
* Returns: version as an integer
|
|
|
|
* Negative value means an error
|
|
|
|
*/
|
|
|
|
PROCPS_EXPORT int procps_linux_version(void)
|
|
|
|
{
|
2012-01-09 16:27:44 +05:30
|
|
|
FILE *fp;
|
|
|
|
char buf[256];
|
2015-06-19 16:30:46 +05:30
|
|
|
unsigned int x = 0, y = 0, z = 0;
|
|
|
|
int version_string_depth;
|
2012-01-09 16:27:44 +05:30
|
|
|
|
2015-06-19 16:30:46 +05:30
|
|
|
if ((fp = fopen(PROCFS_OSRELEASE, "r")) == NULL)
|
|
|
|
return -errno;
|
2012-01-09 16:27:44 +05:30
|
|
|
if (fgets(buf, 256, fp) == NULL) {
|
2015-06-19 16:30:46 +05:30
|
|
|
fclose(fp);
|
|
|
|
return -EIO;
|
2012-01-09 16:27:44 +05:30
|
|
|
}
|
|
|
|
fclose(fp);
|
2015-06-19 16:30:46 +05:30
|
|
|
version_string_depth = sscanf(buf, "%u.%u.%u", &x, &y, &z);
|
2011-06-20 21:24:06 +05:30
|
|
|
if ((version_string_depth < 2) || /* Non-standard for all known kernels */
|
|
|
|
((version_string_depth < 3) && (x < 3))) /* Non-standard for 2.x.x kernels */
|
2015-06-19 16:30:46 +05:30
|
|
|
return -ERANGE;
|
|
|
|
return LINUX_VERSION(x,y,z);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|