|
@@ -67,12 +67,13 @@ COMMAND_CONSUPTIME, "console_uptime",
|
67
|
67
|
command_t
|
68
|
68
|
command_parse(char *request)
|
69
|
69
|
{
|
|
70
|
+ int i;
|
70
|
71
|
if (strlen(request) > CONSOLE_BUFFER_LENGTH) {
|
71
|
72
|
printf("Error: Command longer than 250 bytes.\n");
|
72
|
73
|
return -1;
|
73
|
74
|
}
|
74
|
75
|
|
75
|
|
- for (int i = 0; i < sizeof(kSupportedCommands)
|
|
76
|
+ for (i = 0; i < sizeof(kSupportedCommands)
|
76
|
77
|
/ sizeof(kSupportedCommands[0]); i++) {
|
77
|
78
|
if (strncmp(request, kSupportedCommands[i].command,
|
78
|
79
|
(int) strlen(request) - 1) == 0) {
|
|
@@ -177,72 +178,94 @@ ntkd_request(command_t command)
|
177
|
178
|
}
|
178
|
179
|
|
179
|
180
|
|
180
|
|
-void console_uptime(void) {
|
181
|
|
-
|
182
|
|
- unsigned int uptime_sec1;
|
183
|
|
- unsigned int uptime_min1;
|
184
|
|
- unsigned int uptime_hour1;
|
185
|
|
-
|
186
|
|
- unsigned int uptime_day1;
|
187
|
|
- unsigned int uptime_month1;
|
188
|
|
- unsigned int uptime_year1;
|
189
|
|
-
|
190
|
|
- time(&rawtime);
|
191
|
|
-
|
192
|
|
- timeinfo = localtime(&rawtime);
|
193
|
|
-
|
194
|
|
- uptime_sec1 = timeinfo->tm_sec;
|
195
|
|
- uptime_min1 = timeinfo->tm_min;
|
196
|
|
- uptime_hour1 = timeinfo->tm_hour;
|
197
|
|
-
|
198
|
|
- uptime_day1 = timeinfo->tm_mday;
|
199
|
|
- uptime_month1 = timeinfo->tm_mon;
|
200
|
|
- uptime_year1 = timeinfo->tm_year;
|
201
|
|
-
|
202
|
|
- uptime_sec1 -= uptime_sec;
|
203
|
|
- uptime_min1 -= uptime_min;
|
204
|
|
- uptime_hour1 -= uptime_hour;
|
205
|
|
-
|
206
|
|
- uptime_day1 -= uptime_day;
|
207
|
|
- uptime_month1 -= uptime_month;
|
208
|
|
- uptime_year1 -= uptime_year;
|
209
|
|
- /* Checks if the date/time is negative,
|
210
|
|
- * And makes it positive.
|
211
|
|
- * e.g -11 is 1 because this is a signed variable
|
212
|
|
- * at a modulus of 12. Thus after 12, It is -12
|
213
|
|
- * which is zero, Every number after this is counting up
|
214
|
|
- * to 12 again, Which is going to be 0 in this instance.
|
215
|
|
- * -12 to 12 is 24 actual months.
|
216
|
|
- * So -11 + 12 is 1, As it should be, And -12 + 12 is zero
|
217
|
|
- * as it should be. The only difference is the modulus number,
|
218
|
|
- * i.e: 12, 24, etc. */
|
219
|
|
- if(uptime_month1 < 0)
|
220
|
|
- uptime_month1 + 12;
|
221
|
|
- if(uptime_day1 < 0)
|
222
|
|
- uptime_day1 + 365;
|
223
|
|
- if(uptime_hour1 < 0)
|
224
|
|
- uptime_hour1 + 24;
|
225
|
|
- if(uptime_min1 < 0)
|
226
|
|
- uptime_min1 + 60;
|
227
|
|
- if(uptime_sec1 < 0)
|
228
|
|
- uptime_sec1 + 60;
|
229
|
|
- /* Checks if the date/time is the modulus, And resets it to zero.
|
230
|
|
- * e.g: 12 months is a year, Listing 12 months and one year
|
231
|
|
- * is confusing,
|
232
|
|
- * And implies that it has been two years. */
|
233
|
|
- if(uptime_month1 == 12)
|
234
|
|
- uptime_month1 = 0;
|
235
|
|
- if(uptime_day1 == 365)
|
236
|
|
- uptime_day1 = 0;
|
237
|
|
- if(uptime_hour1 == 24)
|
238
|
|
- uptime_hour1 = 0;
|
239
|
|
- if(uptime_min1 == 60)
|
240
|
|
- uptime_min1 = 0;
|
241
|
|
- if(uptime_sec1 == 60)
|
242
|
|
- uptime_sec1 = 0;
|
243
|
|
-
|
244
|
|
- printf("Total Uptime is: %i Year(s), %i Month(s), %i Day(s), %i Hour(s), %i Minute(s), %i Second(s)\n",uptime_year1, uptime_month1, uptime_day1, uptime_hour1, uptime_min1, uptime_sec1);
|
245
|
|
-
|
|
181
|
+void
|
|
182
|
+console_uptime(void)
|
|
183
|
+{
|
|
184
|
+
|
|
185
|
+ unsigned int uptime_sec1;
|
|
186
|
+ unsigned int uptime_min1;
|
|
187
|
+ unsigned int uptime_hour1;
|
|
188
|
+
|
|
189
|
+ unsigned int uptime_day1;
|
|
190
|
+ unsigned int uptime_month1;
|
|
191
|
+ unsigned int uptime_year1;
|
|
192
|
+
|
|
193
|
+ time(&rawtime);
|
|
194
|
+
|
|
195
|
+ timeinfo = localtime(&rawtime);
|
|
196
|
+
|
|
197
|
+ uptime_sec1 = timeinfo->tm_sec;
|
|
198
|
+ uptime_min1 = timeinfo->tm_min;
|
|
199
|
+ uptime_hour1 = timeinfo->tm_hour;
|
|
200
|
+
|
|
201
|
+ uptime_day1 = timeinfo->tm_mday;
|
|
202
|
+ uptime_month1 = timeinfo->tm_mon;
|
|
203
|
+ uptime_year1 = timeinfo->tm_year;
|
|
204
|
+
|
|
205
|
+ uptime_sec1 -= uptime_sec;
|
|
206
|
+ uptime_min1 -= uptime_min;
|
|
207
|
+ uptime_hour1 -= uptime_hour;
|
|
208
|
+
|
|
209
|
+ uptime_day1 -= uptime_day;
|
|
210
|
+ uptime_month1 -= uptime_month;
|
|
211
|
+ uptime_year1 -= uptime_year;
|
|
212
|
+ /* Checks if the date/time is negative,
|
|
213
|
+ * And makes it positive.
|
|
214
|
+ * e.g -11 is 1 because this is a signed variable
|
|
215
|
+ * at a modulus of 12. Thus after 12, It is -12
|
|
216
|
+ * which is zero, Every number after this is counting up
|
|
217
|
+ * to 12 again, Which is going to be 0 in this instance.
|
|
218
|
+ * -12 to 12 is 24 actual months.
|
|
219
|
+ * So -11 + 12 is 1, As it should be, And -12 + 12 is zero
|
|
220
|
+ * as it should be. The only difference is the modulus number,
|
|
221
|
+ * i.e: 12, 24, etc. */
|
|
222
|
+ if(uptime_month1 < 0)
|
|
223
|
+ {
|
|
224
|
+ uptime_month1 += 12;
|
|
225
|
+ }
|
|
226
|
+ if(uptime_day1 < 0)
|
|
227
|
+ {
|
|
228
|
+ uptime_day1 += 365;
|
|
229
|
+ }
|
|
230
|
+ if(uptime_hour1 < 0)
|
|
231
|
+ {
|
|
232
|
+ uptime_hour1 += 24;
|
|
233
|
+ }
|
|
234
|
+ if(uptime_min1 < 0)
|
|
235
|
+ {
|
|
236
|
+ uptime_min1 += 60;
|
|
237
|
+ }
|
|
238
|
+ if(uptime_sec1 < 0)
|
|
239
|
+ {
|
|
240
|
+ uptime_sec1 += 60;
|
|
241
|
+ }
|
|
242
|
+ /* Checks if the date/time is the modulus, And resets it to zero.
|
|
243
|
+ * e.g: 12 months is a year, Listing 12 months and one year
|
|
244
|
+ * is confusing,
|
|
245
|
+ * And implies that it has been two years. */
|
|
246
|
+ if(uptime_month1 == 12)
|
|
247
|
+ {
|
|
248
|
+ uptime_month1 = 0;
|
|
249
|
+ }
|
|
250
|
+ if(uptime_day1 == 365)
|
|
251
|
+ {
|
|
252
|
+ uptime_day1 = 0;
|
|
253
|
+ }
|
|
254
|
+ if(uptime_hour1 == 24)
|
|
255
|
+ {
|
|
256
|
+ uptime_hour1 = 0;
|
|
257
|
+ }
|
|
258
|
+ if(uptime_min1 == 60)
|
|
259
|
+ {
|
|
260
|
+ uptime_min1 = 0;
|
|
261
|
+ }
|
|
262
|
+ if(uptime_sec1 == 60)
|
|
263
|
+ {
|
|
264
|
+ uptime_sec1 = 0;
|
|
265
|
+ }
|
|
266
|
+
|
|
267
|
+ printf("Total Uptime is: %i Year(s), %i Month(s), %i Day(s), %i Hour(s), %i Minute(s), %i Second(s)\n",uptime_year1, uptime_month1, uptime_day1, uptime_hour1, uptime_min1, uptime_sec1);
|
|
268
|
+
|
246
|
269
|
}
|
247
|
270
|
|
248
|
271
|
|
|
@@ -326,8 +349,9 @@ main(void)
|
326
|
349
|
void
|
327
|
350
|
usage(void)
|
328
|
351
|
{
|
|
352
|
+ int i;
|
329
|
353
|
printf("Usage:\n");
|
330
|
|
- for (int i = 0; i < sizeof(kSupportedCommands)
|
|
354
|
+ for (i = 0; i < sizeof(kSupportedCommands)
|
331
|
355
|
/ sizeof(kSupportedCommands[0]); i++) {
|
332
|
356
|
printf(" %16s - %s\n", kSupportedCommands[i].command,
|
333
|
357
|
kSupportedCommands[i].help);
|