diff options
Diffstat (limited to 'procps')
-rw-r--r-- | procps/smemcap.c | 6 | ||||
-rw-r--r-- | procps/top.c | 14 | ||||
-rw-r--r-- | procps/uptime.c | 30 |
3 files changed, 37 insertions, 13 deletions
diff --git a/procps/smemcap.c b/procps/smemcap.c index f2e2de29d..01acbf74e 100644 --- a/procps/smemcap.c +++ b/procps/smemcap.c | |||
@@ -66,7 +66,11 @@ static void archivefile(const char *path) | |||
66 | struct stat s; | 66 | struct stat s; |
67 | 67 | ||
68 | /* buffer the file */ | 68 | /* buffer the file */ |
69 | fd = xopen(path, O_RDONLY); | 69 | fd = open(path, O_RDONLY); |
70 | if (fd == -1) { | ||
71 | /* skip vanished processes between dir listing and traversal */ | ||
72 | return; | ||
73 | } | ||
70 | do { | 74 | do { |
71 | cur = xzalloc(sizeof(*cur)); | 75 | cur = xzalloc(sizeof(*cur)); |
72 | *prev = cur; | 76 | *prev = cur; |
diff --git a/procps/top.c b/procps/top.c index 1b49a5e6b..f016f5501 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -901,11 +901,11 @@ enum { | |||
901 | }; | 901 | }; |
902 | 902 | ||
903 | #if ENABLE_FEATURE_TOP_INTERACTIVE | 903 | #if ENABLE_FEATURE_TOP_INTERACTIVE |
904 | static unsigned handle_input(unsigned scan_mask, unsigned interval) | 904 | static unsigned handle_input(unsigned scan_mask, duration_t interval) |
905 | { | 905 | { |
906 | if (option_mask32 & OPT_EOF) { | 906 | if (option_mask32 & OPT_EOF) { |
907 | /* EOF on stdin ("top </dev/null") */ | 907 | /* EOF on stdin ("top </dev/null") */ |
908 | sleep(interval); | 908 | sleep_for_duration(interval); |
909 | return scan_mask; | 909 | return scan_mask; |
910 | } | 910 | } |
911 | 911 | ||
@@ -1092,9 +1092,9 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval) | |||
1092 | int top_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1092 | int top_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1093 | int top_main(int argc UNUSED_PARAM, char **argv) | 1093 | int top_main(int argc UNUSED_PARAM, char **argv) |
1094 | { | 1094 | { |
1095 | duration_t interval; | ||
1095 | int iterations; | 1096 | int iterations; |
1096 | unsigned col; | 1097 | unsigned col; |
1097 | unsigned interval; | ||
1098 | char *str_interval, *str_iterations; | 1098 | char *str_interval, *str_iterations; |
1099 | unsigned scan_mask = TOP_MASK; | 1099 | unsigned scan_mask = TOP_MASK; |
1100 | 1100 | ||
@@ -1120,8 +1120,10 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1120 | /* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */ | 1120 | /* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */ |
1121 | if (str_interval[0] == '-') | 1121 | if (str_interval[0] == '-') |
1122 | str_interval++; | 1122 | str_interval++; |
1123 | interval = parse_duration_str(str_interval); | ||
1123 | /* Need to limit it to not overflow poll timeout */ | 1124 | /* Need to limit it to not overflow poll timeout */ |
1124 | interval = xatou16(str_interval); | 1125 | if (interval > INT_MAX / 1000) |
1126 | interval = INT_MAX / 1000; | ||
1125 | } | 1127 | } |
1126 | if (col & OPT_n) { | 1128 | if (col & OPT_n) { |
1127 | if (str_iterations[0] == '-') | 1129 | if (str_iterations[0] == '-') |
@@ -1169,7 +1171,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1169 | /* We output to stdout, we need size of stdout (not stdin)! */ | 1171 | /* We output to stdout, we need size of stdout (not stdin)! */ |
1170 | get_terminal_width_height(STDOUT_FILENO, &col, &G.lines); | 1172 | get_terminal_width_height(STDOUT_FILENO, &col, &G.lines); |
1171 | if (G.lines < 5 || col < 10) { | 1173 | if (G.lines < 5 || col < 10) { |
1172 | sleep(interval); | 1174 | sleep_for_duration(interval); |
1173 | continue; | 1175 | continue; |
1174 | } | 1176 | } |
1175 | if (col > LINE_BUF_SIZE - 2) | 1177 | if (col > LINE_BUF_SIZE - 2) |
@@ -1254,7 +1256,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1254 | break; | 1256 | break; |
1255 | #if !ENABLE_FEATURE_TOP_INTERACTIVE | 1257 | #if !ENABLE_FEATURE_TOP_INTERACTIVE |
1256 | clearmems(); | 1258 | clearmems(); |
1257 | sleep(interval); | 1259 | sleep_for_duration(interval); |
1258 | #else | 1260 | #else |
1259 | new_mask = handle_input(scan_mask, interval); | 1261 | new_mask = handle_input(scan_mask, interval); |
1260 | if (new_mask == NO_RESCAN_MASK) | 1262 | if (new_mask == NO_RESCAN_MASK) |
diff --git a/procps/uptime.c b/procps/uptime.c index b0ee8391b..3262f41b4 100644 --- a/procps/uptime.c +++ b/procps/uptime.c | |||
@@ -45,7 +45,6 @@ | |||
45 | # include <sys/sysinfo.h> | 45 | # include <sys/sysinfo.h> |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | |||
49 | #ifndef FSHIFT | 48 | #ifndef FSHIFT |
50 | # define FSHIFT 16 /* nr of bits of precision */ | 49 | # define FSHIFT 16 /* nr of bits of precision */ |
51 | #endif | 50 | #endif |
@@ -53,29 +52,48 @@ | |||
53 | #define LOAD_INT(x) (unsigned)((x) >> FSHIFT) | 52 | #define LOAD_INT(x) (unsigned)((x) >> FSHIFT) |
54 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100) | 53 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100) |
55 | 54 | ||
56 | |||
57 | int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 55 | int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
58 | int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 56 | int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
59 | { | 57 | { |
60 | unsigned updays, uphours, upminutes; | 58 | unsigned updays, uphours, upminutes; |
59 | unsigned opts; | ||
61 | struct sysinfo info; | 60 | struct sysinfo info; |
62 | struct tm *current_time; | 61 | struct tm *current_time; |
63 | time_t current_secs; | 62 | time_t current_secs; |
64 | 63 | ||
64 | opts = getopt32(argv, "s"); | ||
65 | |||
65 | time(¤t_secs); | 66 | time(¤t_secs); |
67 | sysinfo(&info); | ||
68 | |||
69 | if (opts) // -s | ||
70 | current_secs -= info.uptime; | ||
71 | |||
66 | current_time = localtime(¤t_secs); | 72 | current_time = localtime(¤t_secs); |
67 | 73 | ||
68 | sysinfo(&info); | 74 | if (opts) { // -s |
75 | printf("%04u-%02u-%02u %02u:%02u:%02u\n", | ||
76 | current_time->tm_year + 1900, current_time->tm_mon + 1, current_time->tm_mday, | ||
77 | current_time->tm_hour, current_time->tm_min, current_time->tm_sec | ||
78 | ); | ||
79 | /* The above way of calculating boot time is wobbly, | ||
80 | * info.uptime has only 1 second precision, which makes | ||
81 | * "uptime -s" wander +- one second. | ||
82 | * /proc/uptime may be better, it has 0.01s precision. | ||
83 | */ | ||
84 | return EXIT_SUCCESS; | ||
85 | } | ||
69 | 86 | ||
70 | printf(" %02u:%02u:%02u up ", | 87 | printf(" %02u:%02u:%02u up ", |
71 | current_time->tm_hour, current_time->tm_min, current_time->tm_sec); | 88 | current_time->tm_hour, current_time->tm_min, current_time->tm_sec |
89 | ); | ||
72 | updays = (unsigned) info.uptime / (unsigned)(60*60*24); | 90 | updays = (unsigned) info.uptime / (unsigned)(60*60*24); |
73 | if (updays) | 91 | if (updays != 0) |
74 | printf("%u day%s, ", updays, (updays != 1) ? "s" : ""); | 92 | printf("%u day%s, ", updays, (updays != 1) ? "s" : ""); |
75 | upminutes = (unsigned) info.uptime / (unsigned)60; | 93 | upminutes = (unsigned) info.uptime / (unsigned)60; |
76 | uphours = (upminutes / (unsigned)60) % (unsigned)24; | 94 | uphours = (upminutes / (unsigned)60) % (unsigned)24; |
77 | upminutes %= 60; | 95 | upminutes %= 60; |
78 | if (uphours) | 96 | if (uphours != 0) |
79 | printf("%2u:%02u", uphours, upminutes); | 97 | printf("%2u:%02u", uphours, upminutes); |
80 | else | 98 | else |
81 | printf("%u min", upminutes); | 99 | printf("%u min", upminutes); |