uptime: Correctly print pretty/short format
uptime -p would show empty output after 52 weeks of uptime. This commit is largely the work of Ed but reformatted for newlib branch. Signed-off-by: Craig Small <csmall@dropbear.xyz> References: procps-ng/procps!141 procps-ng/procps#217
This commit is contained in:
parent
5f760d5085
commit
0496b39876
1
NEWS
1
NEWS
@ -25,6 +25,7 @@ procps-ng-NEXT
|
|||||||
* top: summary area memory lines can print two abreast
|
* top: summary area memory lines can print two abreast
|
||||||
* top: added two new autogroup fields
|
* top: added two new autogroup fields
|
||||||
* top: added long versions of command line options
|
* top: added long versions of command line options
|
||||||
|
* uptime: print short/pretty format correctly issue #217
|
||||||
* vmstat: add -y option to remove first line merge !72
|
* vmstat: add -y option to remove first line merge !72
|
||||||
|
|
||||||
procps-ng-3.3.17
|
procps-ng-3.3.17
|
||||||
|
@ -160,13 +160,49 @@ PROCPS_EXPORT char *procps_uptime_sprint_short(void)
|
|||||||
if (procps_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);
|
if (uptime_secs>60*60*24*365*10) {
|
||||||
|
updecades = (int) uptime_secs / (60*60*24*365*10);
|
||||||
|
uptime_secs -= updecades*60*60*24*365*10;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updecades = 0;
|
||||||
|
}
|
||||||
|
if (uptime_secs>60*60*24*365) {
|
||||||
|
upyears = (int) uptime_secs / (60*60*24*365);
|
||||||
|
uptime_secs -= upyears*60*60*24*365;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
upyears = 0;
|
||||||
|
}
|
||||||
|
if (uptime_secs>60*60*24*7) {
|
||||||
|
upweeks = (int) uptime_secs / (60*60*24*7);
|
||||||
|
uptime_secs -= upweeks*60*60*24*7;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
upweeks = 0;
|
||||||
|
}
|
||||||
|
if (uptime_secs>60*60*24) {
|
||||||
|
updays = (int) uptime_secs / (60*60*24);
|
||||||
|
uptime_secs -= updays*60*60*24;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updays = 0;
|
||||||
|
}
|
||||||
|
if (uptime_secs>60*60) {
|
||||||
|
uphours = (int) uptime_secs / (60*60);
|
||||||
|
uptime_secs -= uphours*60*60;
|
||||||
|
}
|
||||||
|
if (uptime_secs>60) {
|
||||||
|
upminutes = (int) uptime_secs / 60;
|
||||||
|
uptime_secs -= upminutes*60;
|
||||||
|
}
|
||||||
|
/*updecades = (int) uptime_secs / (60*60*24*365*10);
|
||||||
upyears = ((int) uptime_secs / (60*60*24*365)) % 10;
|
upyears = ((int) uptime_secs / (60*60*24*365)) % 10;
|
||||||
upweeks = ((int) uptime_secs / (60*60*24*7)) % 52;
|
upweeks = ((int) uptime_secs / (60*60*24*7)) % 52;
|
||||||
updays = ((int) uptime_secs / (60*60*24)) % 7;
|
updays = ((int) uptime_secs / (60*60*24)) % 7;
|
||||||
uphours = ((int) uptime_secs / (60*60)) % 24;
|
uphours = ((int) uptime_secs / (60*60)) % 24;
|
||||||
upminutes = ((int) uptime_secs / (60)) % 60;
|
upminutes = ((int) uptime_secs / (60)) % 60;
|
||||||
|
*/
|
||||||
strcat(shortbuf, "up ");
|
strcat(shortbuf, "up ");
|
||||||
|
|
||||||
if (updecades) {
|
if (updecades) {
|
||||||
|
Loading…
Reference in New Issue
Block a user