main.c 1.32 KB
Newer Older
1
/* Copyright 2015 by the NTPsec project contributors
2
 * SPDX-License-Identifier: BSD-2-Clause
3 4 5 6 7
 */

#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
8
#include <stdbool.h>
9 10 11 12 13 14 15

#include "config.h"

/*
 * Our methods, one per linked module
 */
extern void ppscheck(char *device);
16 17
extern void tickadj(const bool json, const int tick);
extern void jitter(const bool json);
18
extern void stepback(void);
19
extern void precision(const bool json);
20 21 22 23 24

int
main(int argc, char **argv)
{
	int ch;
25 26
	bool json = false;
	while ((ch = getopt(argc, argv, "a:Acejp:")) != EOF) {
27 28 29
		switch (ch) {
		case 'A':
#ifdef HAVE_ADJTIMEX
30
		    tickadj(json, 0);
31 32 33 34 35 36 37
#else
		    fputs("ntpfrob: no adjtimex(2) call.\n", stderr);
		    exit(0);
#endif
		    break;
		case 'a':
#ifdef HAVE_ADJTIMEX
38
		    tickadj(json, atoi(optarg));
39 40 41 42 43 44
#else
		    fputs("ntpfrob: no adjtimex(2) call.\n", stderr);
		    exit(0);
#endif
		    break;
		case 'c':
45
		    jitter(json);
46 47
		    exit(0);
		    break;
48 49 50 51 52 53 54
		case 'e':
		    precision(json);
		    exit(0);
		    break;
		case 'j':
		    json = true;
		    break;
55 56 57 58 59 60 61 62
		case 'p':
#ifdef HAVE_SYS_TIMEPPS_H
		    ppscheck(optarg);
#else
		    fputs("ntpfrob: no PPS kernel interface.\n", stderr);
		    exit(0);
#endif
		    break;
63 64 65 66
		default:
		    fputs("ntpfrob: no mode option specified.\n", stderr);
		    exit(1);
		    break;
67 68 69 70 71
		}
	}

    exit(0);
}