mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 09:44:04 +00:00
kvm_proc needs synchronized access
Signed-off-by: Nikos Ntarmos <ntarmos@cs.uoi.gr> Signed-off-by: Pavel Labath <pavelo@centrum.sk>
This commit is contained in:
parent
792da5a7db
commit
f607145f13
@ -5718,6 +5718,7 @@ void initialisation(int argc, char **argv) {
|
|||||||
"kvm_open")) == NULL) {
|
"kvm_open")) == NULL) {
|
||||||
CRIT_ERR(NULL, NULL, "cannot read kvm");
|
CRIT_ERR(NULL, NULL, "cannot read kvm");
|
||||||
}
|
}
|
||||||
|
pthread_mutex_init(&kvm_proc_mutex, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -6001,6 +6002,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
kvm_close(kd);
|
kvm_close(kd);
|
||||||
|
pthread_mutex_destroy(&kvm_proc_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -266,7 +266,9 @@ int update_total_processes(void)
|
|||||||
{
|
{
|
||||||
int n_processes;
|
int n_processes;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&kvm_proc_mutex);
|
||||||
kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
||||||
|
pthread_mutex_unlock(&kvm_proc_mutex);
|
||||||
|
|
||||||
info.procs = n_processes;
|
info.procs = n_processes;
|
||||||
return 0;
|
return 0;
|
||||||
@ -278,6 +280,7 @@ int update_running_processes(void)
|
|||||||
int n_processes;
|
int n_processes;
|
||||||
int i, cnt = 0;
|
int i, cnt = 0;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&kvm_proc_mutex);
|
||||||
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
||||||
for (i = 0; i < n_processes; i++) {
|
for (i = 0; i < n_processes; i++) {
|
||||||
#if (__FreeBSD__ < 5) && (__FreeBSD_kernel__ < 5)
|
#if (__FreeBSD__ < 5) && (__FreeBSD_kernel__ < 5)
|
||||||
@ -288,6 +291,7 @@ int update_running_processes(void)
|
|||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&kvm_proc_mutex);
|
||||||
|
|
||||||
info.run_procs = cnt;
|
info.run_procs = cnt;
|
||||||
return 0;
|
return 0;
|
||||||
@ -748,6 +752,7 @@ proc_find_top(struct process **cpu, struct process **mem, struct process **time)
|
|||||||
CRIT_ERR(NULL, NULL, "Cannot read sysctl \"vm.stats.vm.v_page_count\"");
|
CRIT_ERR(NULL, NULL, "Cannot read sysctl \"vm.stats.vm.v_page_count\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&kvm_proc_mutex);
|
||||||
p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);
|
p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);
|
||||||
processes = malloc(n_processes * sizeof(struct process));
|
processes = malloc(n_processes * sizeof(struct process));
|
||||||
|
|
||||||
@ -764,6 +769,7 @@ proc_find_top(struct process **cpu, struct process **mem, struct process **time)
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&kvm_proc_mutex);
|
||||||
|
|
||||||
qsort(processes, j - 1, sizeof(struct process), comparemem);
|
qsort(processes, j - 1, sizeof(struct process), comparemem);
|
||||||
for (i = 0; i < 10 && i < n_processes; i++) {
|
for (i = 0; i < 10 && i < n_processes; i++) {
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
#include <sys/ucred.h>
|
#include <sys/ucred.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
|
#include <pthread.h>
|
||||||
#if (defined(i386) || defined(__i386__))
|
#if (defined(i386) || defined(__i386__))
|
||||||
#include <machine/apm_bios.h>
|
#include <machine/apm_bios.h>
|
||||||
#endif /* i386 || __i386__ */
|
#endif /* i386 || __i386__ */
|
||||||
|
|
||||||
kvm_t *kd;
|
kvm_t *kd;
|
||||||
|
pthread_mutex_t kvm_proc_mutex;
|
||||||
|
|
||||||
int get_entropy_avail(unsigned int *);
|
int get_entropy_avail(unsigned int *);
|
||||||
int get_entropy_poolsize(unsigned int *);
|
int get_entropy_poolsize(unsigned int *);
|
||||||
|
Loading…
Reference in New Issue
Block a user