Add rcsid. Add usage() with up to date flag list. Use err(3).
This commit is contained in:
parent
ea9e39333c
commit
2cc11a3c27
@ -5,6 +5,12 @@
|
|||||||
* able to read and write the binary as well, but haven't
|
* able to read and write the binary as well, but haven't
|
||||||
* mastered this yet.
|
* mastered this yet.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#if !defined(SYS_VAX) && !defined(SYS_BSD)
|
#if !defined(SYS_VAX) && !defined(SYS_BSD)
|
||||||
@ -45,6 +51,7 @@ main(int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
#else /* not Linux... kmem tweaking: */
|
#else /* not Linux... kmem tweaking: */
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#ifndef SYS_BSD
|
#ifndef SYS_BSD
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
@ -86,7 +93,6 @@ main(int argc, char ** argv)
|
|||||||
#define KMEM "/dev/kmem"
|
#define KMEM "/dev/kmem"
|
||||||
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
|
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
|
||||||
|
|
||||||
char *progname;
|
|
||||||
int debug;
|
int debug;
|
||||||
|
|
||||||
int dokmem = 1;
|
int dokmem = 1;
|
||||||
@ -107,10 +113,17 @@ static int openfile P((char *, int));
|
|||||||
static void writevar P((int, unsigned long, int));
|
static void writevar P((int, unsigned long, int));
|
||||||
static void readvar P((int, unsigned long, int *));
|
static void readvar P((int, unsigned long, int *));
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage: tickadj [-Adkpqs] [-a newadj] [-t newtick]\n");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main - parse arguments and handle options
|
* main - parse arguments and handle options
|
||||||
*/
|
*/
|
||||||
void
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
@ -135,7 +148,6 @@ char *argv[];
|
|||||||
void readvar();
|
void readvar();
|
||||||
void writevar();
|
void writevar();
|
||||||
|
|
||||||
progname = argv[0];
|
|
||||||
while ((c = ntp_getopt(argc, argv, "a:Adkqpst:")) != EOF)
|
while ((c = ntp_getopt(argc, argv, "a:Adkqpst:")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -153,9 +165,8 @@ char *argv[];
|
|||||||
case 'a':
|
case 'a':
|
||||||
writetickadj = atoi(ntp_optarg);
|
writetickadj = atoi(ntp_optarg);
|
||||||
if (writetickadj <= 0) {
|
if (writetickadj <= 0) {
|
||||||
(void) fprintf(stderr,
|
warnx("unlikely value for tickadj: %s",
|
||||||
"%s: unlikely value for tickadj: %s\n",
|
ntp_optarg);
|
||||||
progname, ntp_optarg);
|
|
||||||
errflg++;
|
errflg++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -168,9 +179,8 @@ char *argv[];
|
|||||||
case 't':
|
case 't':
|
||||||
writetick = atoi(ntp_optarg);
|
writetick = atoi(ntp_optarg);
|
||||||
if (writetick <= 0) {
|
if (writetick <= 0) {
|
||||||
(void) fprintf(stderr,
|
warnx("unlikely value for tick: %s",
|
||||||
"%s: unlikely value for tick: %s\n",
|
ntp_optarg);
|
||||||
progname, ntp_optarg);
|
|
||||||
errflg++;
|
errflg++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -178,11 +188,8 @@ char *argv[];
|
|||||||
errflg++;
|
errflg++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (errflg || ntp_optind != argc) {
|
if (errflg || ntp_optind != argc)
|
||||||
(void) fprintf(stderr,
|
usage();
|
||||||
"usage: %s [-Aqsp] [-a newadj] [-t newtick]\n", progname);
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
kernel = getoffsets(kernel, &tick_offset,
|
kernel = getoffsets(kernel, &tick_offset,
|
||||||
&tickadj_offset, &dosync_offset, &noprintf_offset);
|
&tickadj_offset, &dosync_offset, &noprintf_offset);
|
||||||
|
|
||||||
@ -194,26 +201,22 @@ char *argv[];
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (setnoprintf && (noprintf_offset == 0)) {
|
if (setnoprintf && (noprintf_offset == 0)) {
|
||||||
(void) fprintf(stderr,
|
warnx("no noprintf kernel variable");
|
||||||
"No noprintf kernal variable\n");
|
|
||||||
errflg++;
|
errflg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unsetdosync && (dosync_offset == 0)) {
|
if (unsetdosync && (dosync_offset == 0)) {
|
||||||
(void) fprintf(stderr,
|
warnx("no dosynctodr kernel variable");
|
||||||
"No dosynctodr kernal variable\n");
|
|
||||||
errflg++;
|
errflg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeopttickadj && (tickadj_offset == 0)) {
|
if (writeopttickadj && (tickadj_offset == 0)) {
|
||||||
(void) fprintf(stderr,
|
warnx("no tickadj kernel variable");
|
||||||
"No tickadj kernal variable\n");
|
|
||||||
errflg++;
|
errflg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writetick && (tick_offset == 0)) {
|
if (writetick && (tick_offset == 0)) {
|
||||||
(void) fprintf(stderr,
|
warnx("no tick kernel variable");
|
||||||
"No tick kernal variable\n");
|
|
||||||
errflg++;
|
errflg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,11 +236,8 @@ char *argv[];
|
|||||||
readvar(fd, noprintf_offset, &noprintf);
|
readvar(fd, noprintf_offset, &noprintf);
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
|
|
||||||
if (unsetdosync && dosync_offset == 0) {
|
if (unsetdosync && dosync_offset == 0)
|
||||||
(void) fprintf(stderr,
|
errx(1, "can't find dosynctodr in namelist");
|
||||||
"%s: can't find dosynctodr in namelist\n", progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
(void) printf("tick = %d us",tick);
|
(void) printf("tick = %d us",tick);
|
||||||
@ -250,11 +250,8 @@ char *argv[];
|
|||||||
(void) printf("kernel level printf's: %s\n", noprintf ? "off" : "on");
|
(void) printf("kernel level printf's: %s\n", noprintf ? "off" : "on");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tick <= 0) {
|
if (tick <= 0)
|
||||||
(void) fprintf(stderr, "%s: the value of tick is silly!\n",
|
errx(1, "the value of tick is silly!");
|
||||||
progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
hz = (int)(1000000L / (long)tick);
|
hz = (int)(1000000L / (long)tick);
|
||||||
hz_hundredths = (int)((100000000L / (long)tick) - ((long)hz * 100L));
|
hz_hundredths = (int)((100000000L / (long)tick) - ((long)hz * 100L));
|
||||||
@ -458,12 +455,8 @@ getoffsets(filex, tick_off, tickadj_off, dosync_off, noprintf_off)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (*kname == NULL) {
|
if (*kname == NULL)
|
||||||
(void) fprintf(stderr,
|
errx(1, "nlist fails: can't find/read kernel boot file name");
|
||||||
"%s: nlist fails: can't find/read /vmunix or /unix\n",
|
|
||||||
progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dokmem)
|
if (dokmem)
|
||||||
file = kmem;
|
file = kmem;
|
||||||
@ -521,11 +514,8 @@ openfile(name, mode)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(name, mode);
|
fd = open(name, mode);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
(void) fprintf(stderr, "%s: open %s: ", progname, name);
|
err(1, "open %s", name);
|
||||||
perror("");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,16 +530,10 @@ writevar(fd, off, var)
|
|||||||
int var;
|
int var;
|
||||||
{
|
{
|
||||||
|
|
||||||
if (lseek(fd, off, L_SET) == -1) {
|
if (lseek(fd, off, L_SET) == -1)
|
||||||
(void) fprintf(stderr, "%s: lseek fails: ", progname);
|
err(1, "lseek fails");
|
||||||
perror("");
|
if (write(fd, (char *)&var, sizeof(int)) != sizeof(int))
|
||||||
exit(1);
|
err(1, "write fails");
|
||||||
}
|
|
||||||
if (write(fd, (char *)&var, sizeof(int)) != sizeof(int)) {
|
|
||||||
(void) fprintf(stderr, "%s: write fails: ", progname);
|
|
||||||
perror("");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -564,21 +548,12 @@ readvar(fd, off, var)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (lseek(fd, off, L_SET) == -1) {
|
if (lseek(fd, off, L_SET) == -1)
|
||||||
(void) fprintf(stderr, "%s: lseek fails: ", progname);
|
err(1, "lseek fails");
|
||||||
perror("");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
i = read(fd, (char *)var, sizeof(int));
|
i = read(fd, (char *)var, sizeof(int));
|
||||||
if (i < 0) {
|
if (i < 0)
|
||||||
(void) fprintf(stderr, "%s: read fails: ", progname);
|
err(1, "read fails");
|
||||||
perror("");
|
if (i != sizeof(int))
|
||||||
exit(1);
|
errx(1, "read expected %d, got %d", (int)sizeof(int), i);
|
||||||
}
|
|
||||||
if (i != sizeof(int)) {
|
|
||||||
(void) fprintf(stderr, "%s: read expected %d, got %d\n",
|
|
||||||
progname, (int)sizeof(int), i);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif /* not Linux */
|
#endif /* not Linux */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user