library: Update uptime calls to standard format
Changed all the uptime related functions to use the standard naming procps_uptime_*
This commit is contained in:
parent
56399212c8
commit
639daf5468
@ -101,7 +101,7 @@ top_top_SOURCES = \
|
|||||||
top/top.c \
|
top/top.c \
|
||||||
top/top_nls.h \
|
top/top_nls.h \
|
||||||
top/top_nls.c \
|
top/top_nls.c \
|
||||||
lib/fileutils.c
|
lib/fileutils.c \
|
||||||
lib/signals.c
|
lib/signals.c
|
||||||
top_top_LDADD = $(LDADD) @NCURSES_LIBS@ $(DL_LIB)
|
top_top_LDADD = $(LDADD) @NCURSES_LIBS@ $(DL_LIB)
|
||||||
endif
|
endif
|
||||||
|
@ -40,7 +40,6 @@ global:
|
|||||||
meminfo;
|
meminfo;
|
||||||
openproc;
|
openproc;
|
||||||
page_bytes;
|
page_bytes;
|
||||||
print_uptime;
|
|
||||||
put_slabinfo;
|
put_slabinfo;
|
||||||
readeither;
|
readeither;
|
||||||
readproc;
|
readproc;
|
||||||
@ -49,12 +48,8 @@ global:
|
|||||||
readproctab;
|
readproctab;
|
||||||
readtask;
|
readtask;
|
||||||
smp_num_cpus;
|
smp_num_cpus;
|
||||||
sprint_uptime;
|
|
||||||
tty_to_dev;
|
tty_to_dev;
|
||||||
user_from_uid;
|
user_from_uid;
|
||||||
uptime;
|
|
||||||
sprint_uptime;
|
|
||||||
sprint_uptime_short;
|
|
||||||
procps_hertz_get;
|
procps_hertz_get;
|
||||||
procps_linux_version;
|
procps_linux_version;
|
||||||
procps_meminfo_new;
|
procps_meminfo_new;
|
||||||
@ -76,6 +71,9 @@ global:
|
|||||||
procps_stat_get_jiffs_hist_all;
|
procps_stat_get_jiffs_hist_all;
|
||||||
procps_stat_get_sys;
|
procps_stat_get_sys;
|
||||||
procps_stat_get_sys_chain;
|
procps_stat_get_sys_chain;
|
||||||
|
procps_uptime;
|
||||||
|
procps_uptime_sprint;
|
||||||
|
procps_uptime_sprint_short;
|
||||||
procps_vmstat_new;
|
procps_vmstat_new;
|
||||||
procps_vmstat_read;
|
procps_vmstat_read;
|
||||||
procps_vmstat_ref;
|
procps_vmstat_ref;
|
||||||
|
@ -54,6 +54,7 @@ static int count_users(void)
|
|||||||
|
|
||||||
return numuser;
|
return numuser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* uptime:
|
* uptime:
|
||||||
*
|
*
|
||||||
@ -64,7 +65,9 @@ static int count_users(void)
|
|||||||
*
|
*
|
||||||
* Returns: uptime_secs on success and <0 on failure
|
* Returns: uptime_secs on success and <0 on failure
|
||||||
*/
|
*/
|
||||||
PROCPS_EXPORT int uptime(double *restrict uptime_secs, double *restrict idle_secs)
|
PROCPS_EXPORT int procps_uptime(
|
||||||
|
double *restrict uptime_secs,
|
||||||
|
double *restrict idle_secs)
|
||||||
{
|
{
|
||||||
double up=0, idle=0;
|
double up=0, idle=0;
|
||||||
char *savelocale;
|
char *savelocale;
|
||||||
@ -73,6 +76,7 @@ PROCPS_EXPORT int uptime(double *restrict uptime_secs, double *restrict idle_sec
|
|||||||
|
|
||||||
if ((fp = fopen(UPTIME_FILE, "r")) == NULL)
|
if ((fp = fopen(UPTIME_FILE, "r")) == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
savelocale = strdup(setlocale(LC_NUMERIC, NULL));
|
savelocale = strdup(setlocale(LC_NUMERIC, NULL));
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
if (fscanf(fp, "%lf %lf", &up, &idle) < 2) {
|
if (fscanf(fp, "%lf %lf", &up, &idle) < 2) {
|
||||||
@ -92,13 +96,13 @@ PROCPS_EXPORT int uptime(double *restrict uptime_secs, double *restrict idle_sec
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sprint_uptime:
|
* procps_uptime_sprint:
|
||||||
*
|
*
|
||||||
* Print current time in nice format
|
* Print current time in nice format
|
||||||
*
|
*
|
||||||
* Returns a statically allocated upbuf or NULL on error
|
* Returns a statically allocated upbuf or NULL on error
|
||||||
*/
|
*/
|
||||||
PROCPS_EXPORT char *sprint_uptime(void)
|
PROCPS_EXPORT char *procps_uptime_sprint(void)
|
||||||
{
|
{
|
||||||
int upminutes, uphours, updays, users;
|
int upminutes, uphours, updays, users;
|
||||||
int pos;
|
int pos;
|
||||||
@ -111,7 +115,7 @@ PROCPS_EXPORT char *sprint_uptime(void)
|
|||||||
if (time(&realseconds) < 0)
|
if (time(&realseconds) < 0)
|
||||||
return upbuf;
|
return upbuf;
|
||||||
realtime = localtime(&realseconds);
|
realtime = localtime(&realseconds);
|
||||||
if (uptime(&uptime_secs, &idle_secs) < 0)
|
if (procps_uptime(&uptime_secs, &idle_secs) < 0)
|
||||||
return upbuf;
|
return upbuf;
|
||||||
|
|
||||||
updays = ((int) uptime_secs / (60*60*24));
|
updays = ((int) uptime_secs / (60*60*24));
|
||||||
@ -136,7 +140,14 @@ PROCPS_EXPORT char *sprint_uptime(void)
|
|||||||
return upbuf;
|
return upbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCPS_EXPORT char *sprint_uptime_short(void)
|
/*
|
||||||
|
* procps_uptime_sprint_short:
|
||||||
|
*
|
||||||
|
* Print current time in nice format
|
||||||
|
*
|
||||||
|
* Returns a statically allocated buffer or NULL on error
|
||||||
|
*/
|
||||||
|
PROCPS_EXPORT char *procps_uptime_sprint_short(void)
|
||||||
{
|
{
|
||||||
int updecades, upyears, upweeks, updays, uphours, upminutes;
|
int updecades, upyears, upweeks, updays, uphours, upminutes;
|
||||||
int pos = 3;
|
int pos = 3;
|
||||||
@ -146,7 +157,7 @@ PROCPS_EXPORT char *sprint_uptime_short(void)
|
|||||||
double uptime_secs, idle_secs;
|
double uptime_secs, idle_secs;
|
||||||
|
|
||||||
shortbuf[0] = '\0';
|
shortbuf[0] = '\0';
|
||||||
if (uptime(&uptime_secs, &idle_secs) < 0)
|
if (procps_uptime(&uptime_secs, &idle_secs) < 0)
|
||||||
return shortbuf;
|
return shortbuf;
|
||||||
|
|
||||||
updecades = (int) uptime_secs / (60*60*24*365*10);
|
updecades = (int) uptime_secs / (60*60*24*365*10);
|
||||||
|
@ -29,9 +29,9 @@
|
|||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
int uptime(double *uptime_secs, double *idle_secs);
|
int procps_uptime(double *uptime_secs, double *idle_secs);
|
||||||
char *sprint_uptime(void);
|
char *procps_uptime_sprint(void);
|
||||||
char *sprint_uptime_short(void);
|
char *procps_uptime_sprint_short(void);
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "../proc/wchan.h"
|
#include "../proc/wchan.h"
|
||||||
#include "../proc/version.h"
|
#include "../proc/version.h"
|
||||||
#include "../proc/sysinfo.h"
|
#include "../proc/sysinfo.h"
|
||||||
|
#include <proc/uptime.h>
|
||||||
|
|
||||||
#include "../include/c.h"
|
#include "../include/c.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -390,7 +391,7 @@ void reset_global(void){
|
|||||||
negate_selection = 0;
|
negate_selection = 0;
|
||||||
page_size = getpagesize();
|
page_size = getpagesize();
|
||||||
running_only = 0;
|
running_only = 0;
|
||||||
seconds_since_boot = uptime(0,0);
|
seconds_since_boot = procps_uptime(0,0);
|
||||||
selection_list = NULL;
|
selection_list = NULL;
|
||||||
simple_select = 0;
|
simple_select = 0;
|
||||||
sort_list = NULL;
|
sort_list = NULL;
|
||||||
|
@ -2516,7 +2516,7 @@ static void procs_hlp (proc_t *this) {
|
|||||||
float et;
|
float et;
|
||||||
void *v;
|
void *v;
|
||||||
|
|
||||||
uptime(&uptime_cur, NULL);
|
procps_uptime(&uptime_cur, NULL);
|
||||||
et = uptime_cur - uptime_sav;
|
et = uptime_cur - uptime_sav;
|
||||||
if (et < 0.01) et = 0.005;
|
if (et < 0.01) et = 0.005;
|
||||||
uptime_sav = uptime_cur;
|
uptime_sav = uptime_cur;
|
||||||
@ -5102,10 +5102,10 @@ static void summary_show (void) {
|
|||||||
// Display Uptime and Loadavg
|
// Display Uptime and Loadavg
|
||||||
if (isROOM(View_LOADAV, 1)) {
|
if (isROOM(View_LOADAV, 1)) {
|
||||||
if (!Rc.mode_altscr)
|
if (!Rc.mode_altscr)
|
||||||
show_special(0, fmtmk(LOADAV_line, Myname, sprint_uptime()));
|
show_special(0, fmtmk(LOADAV_line, Myname, procps_uptime_sprint()));
|
||||||
else
|
else
|
||||||
show_special(0, fmtmk(CHKw(w, Show_TASKON)? LOADAV_line_alt : LOADAV_line
|
show_special(0, fmtmk(CHKw(w, Show_TASKON)? LOADAV_line_alt : LOADAV_line
|
||||||
, w->grpname, sprint_uptime()));
|
, w->grpname, procps_uptime_sprint()));
|
||||||
Msg_row += 1;
|
Msg_row += 1;
|
||||||
} // end: View_LOADAV
|
} // end: View_LOADAV
|
||||||
|
|
||||||
|
8
uptime.c
8
uptime.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* uptime.c - display system uptime
|
* uptime.c - display system uptime
|
||||||
* Copyright (C) 2012 Craig Small <csmall-procps@enc.com.au>
|
* Copyright (C) 2012-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
|
||||||
@ -43,7 +43,7 @@ static void print_uptime_since()
|
|||||||
now = tim.tv_sec + (tim.tv_usec / 1000000.0);
|
now = tim.tv_sec + (tim.tv_usec / 1000000.0);
|
||||||
|
|
||||||
/* Get the uptime and calculate when that was */
|
/* Get the uptime and calculate when that was */
|
||||||
uptime(&uptime_secs, &idle_secs);
|
procps_uptime(&uptime_secs, &idle_secs);
|
||||||
up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
|
up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
|
||||||
|
|
||||||
/* Show this */
|
/* Show this */
|
||||||
@ -105,8 +105,8 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
printf("%s\n", sprint_uptime_short());
|
printf("%s\n", procps_uptime_sprint_short());
|
||||||
else
|
else
|
||||||
printf("%s\n", sprint_uptime());
|
printf("%s\n", procps_uptime_sprint());
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
2
w.c
2
w.c
@ -586,7 +586,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (header) {
|
if (header) {
|
||||||
/* print uptime and headers */
|
/* print uptime and headers */
|
||||||
printf("%s\n", sprint_uptime());
|
printf("%s\n", procps_uptime_sprint());
|
||||||
/* Translation Hint: Following five uppercase messages are
|
/* Translation Hint: Following five uppercase messages are
|
||||||
* headers. Try to keep alignment intact. */
|
* headers. Try to keep alignment intact. */
|
||||||
printf(_("%-*s TTY "), userlen, _("USER"));
|
printf(_("%-*s TTY "), userlen, _("USER"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user