main.c (70118) | main.c (74671) |
---|---|
1/*- 2 * Copyright (c) 1980, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; 43#endif 44static const char rcsid[] = | 1/*- 2 * Copyright (c) 1980, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; 43#endif 44static const char rcsid[] = |
45 "$FreeBSD: head/usr.bin/systat/main.c 70118 2000-12-17 18:43:28Z rwatson $"; | 45 "$FreeBSD: head/usr.bin/systat/main.c 74671 2001-03-23 03:58:25Z tmm $"; |
46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/time.h> | 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/time.h> |
50#include <sys/sysctl.h> |
|
50 51#include <err.h> 52#include <locale.h> 53#include <nlist.h> 54#include <paths.h> 55#include <signal.h> 56#include <stdio.h> 57#include <stdlib.h> --- 11 unchanged lines hidden (view full) --- 69int verbose = 1; /* to report kvm read errs */ 70struct clockinfo clkinfo; 71double hertz; 72char c; 73char *namp; 74char hostname[MAXHOSTNAMELEN]; 75WINDOW *wnd; 76int CMDLINE; | 51 52#include <err.h> 53#include <locale.h> 54#include <nlist.h> 55#include <paths.h> 56#include <signal.h> 57#include <stdio.h> 58#include <stdlib.h> --- 11 unchanged lines hidden (view full) --- 70int verbose = 1; /* to report kvm read errs */ 71struct clockinfo clkinfo; 72double hertz; 73char c; 74char *namp; 75char hostname[MAXHOSTNAMELEN]; 76WINDOW *wnd; 77int CMDLINE; |
78int use_kvm = 1; |
|
77 78static WINDOW *wload; /* one line window for load average */ 79 80int 81main(argc, argv) 82 int argc; 83 char **argv; 84{ | 79 80static WINDOW *wload; /* one line window for load average */ 81 82int 83main(argc, argv) 84 int argc; 85 char **argv; 86{ |
85 char errbuf[80]; | 87 char errbuf[80], dummy; |
86 size_t size; 87 int err; 88 89 (void) setlocale(LC_TIME, ""); 90 91 argc--, argv++; 92 while (argc > 0) { 93 if (argv[0][0] == '-') { --- 8 unchanged lines hidden (view full) --- 102 } else { 103 naptime = atoi(argv[0]); 104 if (naptime <= 0) 105 naptime = 5; 106 } 107 argc--, argv++; 108 } 109 kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); | 88 size_t size; 89 int err; 90 91 (void) setlocale(LC_TIME, ""); 92 93 argc--, argv++; 94 while (argc > 0) { 95 if (argv[0][0] == '-') { --- 8 unchanged lines hidden (view full) --- 104 } else { 105 naptime = atoi(argv[0]); 106 if (naptime <= 0) 107 naptime = 5; 108 } 109 argc--, argv++; 110 } 111 kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); |
112 if (kd != NULL) { 113 /* 114 * Try to actually read something, we may be in a jail, and 115 * have /dev/null opened as /dev/mem. 116 */ 117 if (kvm_nlist(kd, namelist) != 0 || namelist[0].n_value == 0 || 118 kvm_read(kd, namelist[0].n_value, &dummy, sizeof(dummy)) != 119 sizeof(dummy)) { 120 kvm_close(kd); 121 kd = NULL; 122 } 123 } |
|
110 if (kd == NULL) { | 124 if (kd == NULL) { |
111 error("%s", errbuf); 112 exit(1); | 125 /* 126 * Maybe we are lacking permissions? Retry, this time with bogus 127 * devices. We can now use sysctl only. 128 */ 129 use_kvm = 0; 130 kd = kvm_openfiles("/dev/null", "/dev/null", "/dev/null", O_RDONLY, errbuf); 131 if (kd == NULL) { 132 error("%s", errbuf); 133 exit(1); 134 } |
113 } 114 signal(SIGINT, die); 115 signal(SIGQUIT, die); 116 signal(SIGTERM, die); 117 118 /* 119 * Initialize display. Load average appears in a one line 120 * window of its own. Current command's display appears in --- 171 unchanged lines hidden --- | 135 } 136 signal(SIGINT, die); 137 signal(SIGQUIT, die); 138 signal(SIGTERM, die); 139 140 /* 141 * Initialize display. Load average appears in a one line 142 * window of its own. Current command's display appears in --- 171 unchanged lines hidden --- |