library: Change linux version
Added function procps_linux_version() which used to be an exported integer instead. Also changed the method of obtaining the linux version (more correctly the os release) to use a specific procfs entry. This works for both Linux and FreeBSD.
This commit is contained in:
parent
94e5ef15fc
commit
56d9d5e7e7
@ -35,7 +35,6 @@ global:
|
|||||||
kb_swap_free;
|
kb_swap_free;
|
||||||
kb_swap_total;
|
kb_swap_total;
|
||||||
kb_swap_used;
|
kb_swap_used;
|
||||||
linux_version_code;
|
|
||||||
loadavg;
|
loadavg;
|
||||||
look_up_our_self;
|
look_up_our_self;
|
||||||
lookup_wchan;
|
lookup_wchan;
|
||||||
@ -60,6 +59,7 @@ global:
|
|||||||
unix_print_signals;
|
unix_print_signals;
|
||||||
uptime;
|
uptime;
|
||||||
user_from_uid;
|
user_from_uid;
|
||||||
|
procps_linux_version;
|
||||||
local:
|
local:
|
||||||
*;
|
*;
|
||||||
};
|
};
|
||||||
|
25
proc/procps-private.h
Normal file
25
proc/procps-private.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* libprocps - Library to read proc filesystem
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
#ifndef PROCPS_PRIVATE_H
|
||||||
|
#define PROCPS_PRIVATE_H
|
||||||
|
|
||||||
|
#include <proc/procps.h>
|
||||||
|
|
||||||
|
#define PROCPS_EXPORT __attribute__ ((visibility("default")))
|
||||||
|
|
||||||
|
#endif
|
@ -78,21 +78,6 @@
|
|||||||
#define OBSOLETE
|
#define OBSOLETE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 1 ) || __GNUC__ > 3
|
|
||||||
// Tells gcc that function is library-internal;
|
|
||||||
// so no need to do dynamic linking at run-time.
|
|
||||||
// This might work with slightly older compilers too.
|
|
||||||
#define HIDDEN __attribute__((visibility("hidden")))
|
|
||||||
// The opposite, in case -fvisibility=hidden used
|
|
||||||
#define EXPORT __attribute__((visibility("default")))
|
|
||||||
// Tell g++ that a function won't throw exceptions.
|
|
||||||
#define NOTHROW __attribute__((__nothrow__))
|
|
||||||
#else
|
|
||||||
#define HIDDEN
|
|
||||||
#define EXPORT
|
|
||||||
#define NOTHROW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Like HIDDEN, but for an alias that gets created.
|
// Like HIDDEN, but for an alias that gets created.
|
||||||
// In gcc-3.2 there is an alias+hidden conflict.
|
// In gcc-3.2 there is an alias+hidden conflict.
|
||||||
// Many will have patched this bug, but oh well.
|
// Many will have patched this bug, but oh well.
|
||||||
|
@ -275,7 +275,7 @@ static int check_for_privs(void){
|
|||||||
static void init_libproc(void) __attribute__((constructor));
|
static void init_libproc(void) __attribute__((constructor));
|
||||||
static void init_libproc(void){
|
static void init_libproc(void){
|
||||||
have_privs = check_for_privs();
|
have_privs = check_for_privs();
|
||||||
init_Linux_version(); /* Must be called before we check code */
|
int linux_version_code = procps_linux_version();
|
||||||
|
|
||||||
cpuinfo();
|
cpuinfo();
|
||||||
page_bytes = sysconf(_SC_PAGESIZE);
|
page_bytes = sysconf(_SC_PAGESIZE);
|
||||||
@ -623,6 +623,7 @@ static unsigned long kb_inactive_file;
|
|||||||
|
|
||||||
void meminfo(void){
|
void meminfo(void){
|
||||||
char namebuf[32]; /* big enough to hold any row name */
|
char namebuf[32]; /* big enough to hold any row name */
|
||||||
|
int linux_version_code = procps_linux_version();
|
||||||
mem_table_struct findme = { namebuf, NULL};
|
mem_table_struct findme = { namebuf, NULL};
|
||||||
mem_table_struct *found;
|
mem_table_struct *found;
|
||||||
char *head;
|
char *head;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Suite version information for procps-ng utilities
|
* libprocps - Library to read proc filesystem
|
||||||
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
|
|
||||||
* Amended by cblake to only export the function symbol.
|
|
||||||
*
|
*
|
||||||
* Modified by Albert Cahalan, ????-2003
|
* 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>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -19,59 +20,44 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include "procps-private.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
/* Linux kernel version information for procps-ng utilities
|
#define PROCFS_OSRELEASE "/proc/sys/kernel/osrelease"
|
||||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
|
||||||
|
/*
|
||||||
|
* procps_linux_version
|
||||||
|
*
|
||||||
|
* Return the current running Linux version release as shown in
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
#include <sys/utsname.h>
|
PROCPS_EXPORT int procps_linux_version(void)
|
||||||
|
{
|
||||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
|
||||||
|
|
||||||
int linux_version_code;
|
|
||||||
|
|
||||||
void init_Linux_version(void) {
|
|
||||||
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
|
||||||
int version_string_depth;
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
static struct utsname uts;
|
|
||||||
|
|
||||||
if (uname(&uts) == -1) /* failure implies impending death */
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
version_string_depth = sscanf(uts.release, "%d.%d.%d", &x, &y, &z);
|
|
||||||
#else
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
unsigned int x = 0, y = 0, z = 0;
|
||||||
|
int version_string_depth;
|
||||||
|
|
||||||
if ( (fp=fopen("/proc/version","r")) == NULL) {
|
if ((fp = fopen(PROCFS_OSRELEASE, "r")) == NULL)
|
||||||
fprintf(stderr, "Cannot find /proc/version - is /proc mounted?\n");
|
return -errno;
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (fgets(buf, 256, fp) == NULL) {
|
if (fgets(buf, 256, fp) == NULL) {
|
||||||
fprintf(stderr, "Cannot read kernel version from /proc/version\n");
|
fclose(fp);
|
||||||
fclose(fp);
|
return -EIO;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
version_string_depth = sscanf(buf, "Linux version %d.%d.%d", &x, &y, &z);
|
version_string_depth = sscanf(buf, "%u.%u.%u", &x, &y, &z);
|
||||||
#endif /* __linux__ */
|
|
||||||
|
|
||||||
if ((version_string_depth < 2) || /* Non-standard for all known kernels */
|
if ((version_string_depth < 2) || /* Non-standard for all known kernels */
|
||||||
((version_string_depth < 3) && (x < 3))) /* Non-standard for 2.x.x kernels */
|
((version_string_depth < 3) && (x < 3))) /* Non-standard for 2.x.x kernels */
|
||||||
#ifdef __linux__
|
return -ERANGE;
|
||||||
fprintf(stderr, /* *very* unlikely to happen by accident */
|
return LINUX_VERSION(x,y,z);
|
||||||
"Non-standard uts for running kernel:\n"
|
|
||||||
"release %s=%d.%d.%d gives version code %d\n",
|
|
||||||
uts.release, x, y, z, LINUX_VERSION(x,y,z));
|
|
||||||
#else
|
|
||||||
fprintf(stderr, /* *very* unlikely to happen by accident */
|
|
||||||
"%s=%d.%d.%d gives version code %d\n",
|
|
||||||
buf, x, y, z, LINUX_VERSION(x,y,z));
|
|
||||||
#endif /* __linux__ */
|
|
||||||
linux_version_code = LINUX_VERSION(x, y, z);
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* libprocps - Library to read proc filesystem
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
#ifndef PROC_VERSION_H
|
#ifndef PROC_VERSION_H
|
||||||
#define PROC_VERSION_H
|
#define PROC_VERSION_H
|
||||||
|
|
||||||
#include "procps.h"
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Suite version information for procps-ng utilities
|
int procps_linux_version(void);
|
||||||
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
|
|
||||||
* Linux kernel version information for procps-ng utilities
|
|
||||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
|
||||||
* Distributable under the terms of the GNU Library General Public License
|
|
||||||
*
|
|
||||||
* Copyright 2002 Albert Cahalan
|
|
||||||
*/
|
|
||||||
|
|
||||||
EXTERN_C_BEGIN
|
|
||||||
|
|
||||||
void init_Linux_version(void); /* Get Linux version */
|
|
||||||
|
|
||||||
extern int linux_version_code; /* runtime version of LINUX_VERSION_CODE
|
|
||||||
in /usr/include/linux/version.h */
|
|
||||||
|
|
||||||
/* Convenience macros for composing/decomposing version codes */
|
/* Convenience macros for composing/decomposing version codes */
|
||||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||||
@ -25,6 +35,8 @@ extern int linux_version_code; /* runtime version of LINUX_VERSION_CODE
|
|||||||
#define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
|
#define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
|
||||||
#define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
|
#define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
|
||||||
|
|
||||||
EXTERN_C_END
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* PROC_VERSION_H */
|
#endif /* PROC_VERSION_H */
|
||||||
|
@ -455,6 +455,7 @@ static const char archdefs[] =
|
|||||||
|
|
||||||
/*********** spew variables ***********/
|
/*********** spew variables ***********/
|
||||||
void self_info(void){
|
void self_info(void){
|
||||||
|
int linux_version_code = procps_linux_version();
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"BSD j %s\n"
|
"BSD j %s\n"
|
||||||
"BSD l %s\n"
|
"BSD l %s\n"
|
||||||
|
@ -407,6 +407,7 @@ static void bye_bye (const char *str) {
|
|||||||
at_eoj(); // restore tty in preparation for exit
|
at_eoj(); // restore tty in preparation for exit
|
||||||
#ifdef ATEOJ_RPTSTD
|
#ifdef ATEOJ_RPTSTD
|
||||||
{ proc_t *p;
|
{ proc_t *p;
|
||||||
|
int linux_version_code = procps_linux_version();
|
||||||
if (!str && !Frames_signal && Ttychanged) { fprintf(stderr,
|
if (!str && !Frames_signal && Ttychanged) { fprintf(stderr,
|
||||||
"\n%s's Summary report:"
|
"\n%s's Summary report:"
|
||||||
"\n\tProgram"
|
"\n\tProgram"
|
||||||
@ -3263,6 +3264,7 @@ static void before (char *me) {
|
|||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
proc_t p;
|
proc_t p;
|
||||||
int i;
|
int i;
|
||||||
|
int linux_version_code = procps_linux_version();
|
||||||
|
|
||||||
atexit(close_stdout);
|
atexit(close_stdout);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user