1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 04:06:03 +00:00

Add new variable sysctlbyname for FreeBSD

This commit is contained in:
su8 2018-09-01 22:40:21 +02:00 committed by lasers
parent a644600bc5
commit 07681e184b
3 changed files with 61 additions and 3 deletions

View File

@ -837,6 +837,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(mouse_speed, 0) obj->callbacks.print = &print_mouse_speed;
#endif /* BUILD_X11 */
#ifdef __FreeBSD__
END OBJ(sysctlbyname, 0) obj->data.s = STRNDUP_ARG;
obj->callbacks.print = &print_sysctlbyname;
obj->callbacks.free = &gen_free_opaque;
#endif /* __FreeBSD__ */
END OBJ(password, 0) obj->data.s = strndup(arg ? arg : "20", text_buffer_size.get(*state));
obj->callbacks.print = &print_password;
obj->callbacks.free = &gen_free_opaque;

View File

@ -25,7 +25,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <sys/dkstat.h>
@ -34,9 +33,9 @@
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <net/if.h>
@ -704,3 +703,28 @@ int get_entropy_poolsize(unsigned int *val) {
(void)val;
return 1;
}
void print_sysctlbyname(struct text_object *obj, char *p, unsigned int p_max_size) {
u_int val[3] = {0};
char buf[256] = {""};
size_t len = sizeof(val);
size_t len2 = sizeof(buf);
if (0 == strcmp(obj->data.s, "")) {
snprintf(p, p_max_size, "%s", "sysctlbyname takes an argument");
return;
}
if (0 != sysctlbyname(obj->data.s, &val, &len, NULL, 0)) {
if (0 != sysctlbyname(obj->data.s, &buf, &len2, NULL, 0)) {
snprintf(p, p_max_size, "%s", "");
return;
}
}
if (0 != strcmp(buf, "")) {
snprintf(p, p_max_size, "%s", buf);
} else {
snprintf(p, p_max_size, "%lu", (unsigned long)val[0]);
}
}

View File

@ -1,4 +1,31 @@
/* */
/*
*
* Conky, a system monitor, based on torsmo
*
* Any original torsmo code is licensed under the BSD license
*
* All code written since the fork of torsmo is licensed under the GPL
*
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2018 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef FREEBSD_H_
#define FREEBSD_H_
@ -16,5 +43,6 @@
int get_entropy_avail(unsigned int *);
int get_entropy_poolsize(unsigned int *);
void print_sysctlbyname(struct text_object *, char *, unsigned int);
#endif /*FREEBSD_H_*/