Bernhard Reutner-Fischer | c89982d | 2006-06-03 19:49:21 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 2 | /* |
| 3 | * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables. |
| 4 | * |
| 5 | * Originally written: October 1997 |
| 6 | * Last hack: March 2001 |
| 7 | * Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov> |
| 8 | * |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 9 | * busyboxed 20 March 2001, Larry Doolittle <ldoolitt@recycle.lbl.gov> |
Bernhard Reutner-Fischer | c89982d | 2006-06-03 19:49:21 +0000 | [diff] [blame] | 10 | * |
Rob Landley | 8fba99f | 2006-05-27 22:08:01 +0000 | [diff] [blame] | 11 | * Licensed under GPLv2 or later, see file License in this tarball for details. |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
Bernhard Reutner-Fischer | c89982d | 2006-06-03 19:49:21 +0000 | [diff] [blame] | 14 | #include "busybox.h" |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | #include <sys/types.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <sys/timex.h> |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 20 | |
"Vladimir N. Oleynik" | 1f0262b | 2005-10-20 11:17:48 +0000 | [diff] [blame] | 21 | static const struct {int bit; const char *name;} statlist[] = { |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 22 | { STA_PLL, "PLL" }, |
| 23 | { STA_PPSFREQ, "PPSFREQ" }, |
| 24 | { STA_PPSTIME, "PPSTIME" }, |
| 25 | { STA_FLL, "FFL" }, |
| 26 | { STA_INS, "INS" }, |
| 27 | { STA_DEL, "DEL" }, |
| 28 | { STA_UNSYNC, "UNSYNC" }, |
| 29 | { STA_FREQHOLD, "FREQHOLD" }, |
| 30 | { STA_PPSSIGNAL, "PPSSIGNAL" }, |
| 31 | { STA_PPSJITTER, "PPSJITTER" }, |
| 32 | { STA_PPSWANDER, "PPSWANDER" }, |
| 33 | { STA_PPSERROR, "PPSERROR" }, |
| 34 | { STA_CLOCKERR, "CLOCKERR" }, |
| 35 | { 0, NULL } }; |
| 36 | |
"Vladimir N. Oleynik" | 1f0262b | 2005-10-20 11:17:48 +0000 | [diff] [blame] | 37 | static const char * const ret_code_descript[] = { |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 38 | "clock synchronized", |
| 39 | "insert leap second", |
| 40 | "delete leap second", |
| 41 | "leap second in progress", |
| 42 | "leap second has occurred", |
| 43 | "clock not synchronized" }; |
| 44 | |
Rob Landley | 8fba99f | 2006-05-27 22:08:01 +0000 | [diff] [blame] | 45 | int adjtimex_main(int argc, char **argv) |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 46 | { |
| 47 | struct timex txc; |
| 48 | int quiet=0; |
| 49 | int c, i, ret, sep; |
"Vladimir N. Oleynik" | 1f0262b | 2005-10-20 11:17:48 +0000 | [diff] [blame] | 50 | const char *descript; |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 51 | txc.modes=0; |
| 52 | for (;;) { |
| 53 | c = getopt( argc, argv, "qo:f:p:t:"); |
| 54 | if (c == EOF) break; |
| 55 | switch (c) { |
| 56 | case 'q': |
| 57 | quiet=1; |
| 58 | break; |
| 59 | case 'o': |
| 60 | txc.offset = atoi(optarg); |
| 61 | txc.modes |= ADJ_OFFSET_SINGLESHOT; |
| 62 | break; |
| 63 | case 'f': |
| 64 | txc.freq = atoi(optarg); |
| 65 | txc.modes |= ADJ_FREQUENCY; |
| 66 | break; |
| 67 | case 'p': |
| 68 | txc.constant = atoi(optarg); |
| 69 | txc.modes |= ADJ_TIMECONST; |
| 70 | break; |
| 71 | case 't': |
| 72 | txc.tick = atoi(optarg); |
| 73 | txc.modes |= ADJ_TICK; |
| 74 | break; |
| 75 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 76 | bb_show_usage(); |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 77 | exit(1); |
| 78 | } |
| 79 | } |
| 80 | if (argc != optind) { /* no valid non-option parameters */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 81 | bb_show_usage(); |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 82 | exit(1); |
| 83 | } |
| 84 | |
| 85 | ret = adjtimex(&txc); |
| 86 | |
| 87 | if (ret < 0) perror("adjtimex"); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 88 | |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 89 | if (!quiet && ret>=0) { |
| 90 | printf( |
| 91 | " mode: %d\n" |
| 92 | "-o offset: %ld\n" |
| 93 | "-f frequency: %ld\n" |
| 94 | " maxerror: %ld\n" |
| 95 | " esterror: %ld\n" |
| 96 | " status: %d ( ", |
| 97 | txc.modes, txc.offset, txc.freq, txc.maxerror, |
| 98 | txc.esterror, txc.status); |
| 99 | |
| 100 | /* representative output of next code fragment: |
| 101 | "PLL | PPSTIME" */ |
| 102 | sep=0; |
| 103 | for (i=0; statlist[i].name; i++) { |
| 104 | if (txc.status & statlist[i].bit) { |
| 105 | if (sep) fputs(" | ",stdout); |
| 106 | fputs(statlist[i].name,stdout); |
| 107 | sep=1; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | descript = "error"; |
| 112 | if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret]; |
| 113 | printf(" )\n" |
| 114 | "-p timeconstant: %ld\n" |
| 115 | " precision: %ld\n" |
| 116 | " tolerance: %ld\n" |
| 117 | "-t tick: %ld\n" |
| 118 | " time.tv_sec: %ld\n" |
| 119 | " time.tv_usec: %ld\n" |
| 120 | " return value: %d (%s)\n", |
| 121 | txc.constant, |
| 122 | txc.precision, txc.tolerance, txc.tick, |
Eric Andersen | e76c3b0 | 2001-04-05 03:14:39 +0000 | [diff] [blame] | 123 | (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript); |
Mark Whitley | 6f93277 | 2001-03-20 19:18:10 +0000 | [diff] [blame] | 124 | } |
| 125 | return (ret<0); |
| 126 | } |