mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 18:15:17 +00:00
conky 1.4.6-svn trunk
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@836 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
7011473db2
commit
4f7f4bf11e
@ -1,5 +1,9 @@
|
||||
# $Id$
|
||||
|
||||
2007-02-25
|
||||
* Created branch/1.5 copy of trunk/conky1. Removing all experimental
|
||||
network code from trunk/conky1.
|
||||
|
||||
2007-02-14
|
||||
* Include missing mboxscan.h in conky.h.
|
||||
* Fixed signedness warnings in conky.c.
|
||||
|
@ -21,7 +21,7 @@ sed -e "s/@REVISION@/${revision}/g" \
|
||||
< "configure.ac.in" > "configure.ac"
|
||||
|
||||
echo Running $ACLOCAL ... && $ACLOCAL
|
||||
echo Running $LIBTOOLIZE --force ... && $LIBTOOLIZE --force
|
||||
echo Running $LIBTOOLIZE --force --copy ... && $LIBTOOLIZE --force --copy
|
||||
echo Running $AUTOHEADER ... && $AUTOHEADER
|
||||
echo Running $AUTOMAKE --add-missing ... && $AUTOMAKE --add-missing
|
||||
echo Running $AUTOMAKE --add-missing --copy --gnu ... && $AUTOMAKE --add-missing --copy --gnu
|
||||
echo Running $AUTOCONF ... && $AUTOCONF
|
||||
|
@ -2,8 +2,8 @@ dnl $Id$
|
||||
|
||||
dnl major, minor and micro version macros.
|
||||
m4_define([conky_version_major], [1])
|
||||
m4_define([conky_version_minor], [5])
|
||||
m4_define([conky_version_micro], [0])
|
||||
m4_define([conky_version_minor], [4])
|
||||
m4_define([conky_version_micro], [6])
|
||||
m4_define([conky_version_tag], [svn]) dnl [] for releases
|
||||
m4_define([conky_version_revision],[r@REVISION@])
|
||||
m4_define([conky_version],
|
||||
@ -226,30 +226,6 @@ if test x$want_portmon = xyes; then
|
||||
fi
|
||||
|
||||
|
||||
dnl
|
||||
dnl Network-based monitoring
|
||||
dnl
|
||||
|
||||
AC_ARG_ENABLE([network],
|
||||
AC_HELP_STRING([--disable-network],
|
||||
[disable if you do not want distributed monitoring @<:@default=yes@:>@]),
|
||||
[want_network="$enableval"], [want_network=yes])
|
||||
if test x"$want_network" = x"yes"; then
|
||||
PKG_CHECK_MODULES([LIBDEXTER], [dexter], [], [AC_MSG_RESULT([no]); want_network=no])
|
||||
if test x"$want_network" = x"yes"; then
|
||||
dnl need GNU string stream extensions
|
||||
AC_CHECK_FUNCS([fmemopen open_memstream flockfile funlockfile putc_unlocked], [], [want_network=no])
|
||||
if test x"$want_network" = x"yes"; then
|
||||
CFLAGS="$CFLAGS $LIBDEXTER_CFLAGS"
|
||||
LIBS="$LIBS $LIBDEXTER_LIBS"
|
||||
AC_DEFINE([HAVE_LIBDEXTER], 1, [Define if using Libdexter])
|
||||
dnl _GNU_SOURCE needed for fmemopen, open_memstream
|
||||
AC_DEFINE([_GNU_SOURCE], [], [Define for GNU source and extensions])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
dnl
|
||||
dnl ICONV
|
||||
dnl
|
||||
@ -425,11 +401,14 @@ AC_CHECK_HEADERS([sys/mount.h], [], [],
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
])
|
||||
|
||||
AC_DEFINE([_GNU_SOURCE], [], [Define for GNU source and extensions])
|
||||
|
||||
dnl
|
||||
dnl Some functions
|
||||
dnl
|
||||
|
||||
AC_CHECK_FUNCS([calloc malloc free popen sysinfo getloadavg])
|
||||
AC_CHECK_FUNCS([calloc malloc free popen sysinfo getloadavg memrchr])
|
||||
AC_SEARCH_LIBS(clock_gettime, [rt],
|
||||
[AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()])],
|
||||
[AC_CHECK_FUNCS([gettimeofday], [], [AC_MSG_ERROR([gettimeofday() not available!])])], [])
|
||||
@ -540,5 +519,4 @@ $PACKAGE $VERSION configured successfully:
|
||||
* general:
|
||||
hddtemp: $want_hddtemp
|
||||
portmon: $want_portmon
|
||||
network: $want_network
|
||||
EOF
|
||||
|
@ -28,11 +28,6 @@ double get_time()
|
||||
return tv.tv_sec + (tv.tv_usec / 1000000.0);
|
||||
}
|
||||
|
||||
#if defined(HAVE_LIBDEXTER) && defined(__linux__)
|
||||
#define USE_OS_SPECIFIC_OPEN_FILE
|
||||
#endif
|
||||
|
||||
#ifndef USE_OS_SPECIFIC_OPEN_FILE
|
||||
FILE *open_file(const char *file, int *reported)
|
||||
{
|
||||
FILE *fp = fopen(file, "r");
|
||||
@ -47,7 +42,6 @@ FILE *open_file(const char *file, int *reported)
|
||||
|
||||
return fp;
|
||||
}
|
||||
#endif
|
||||
|
||||
void variable_substitute(const char *s, char *dest, unsigned int n)
|
||||
{
|
||||
|
195
src/conky.c
195
src/conky.c
@ -93,9 +93,6 @@ static void print_version()
|
||||
#ifdef TCP_PORT_MONITOR
|
||||
" * portmon\n"
|
||||
#endif /* TCP_PORT_MONITOR */
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
" * network\n"
|
||||
#endif
|
||||
"\n");
|
||||
|
||||
exit(0);
|
||||
@ -381,11 +378,6 @@ static int pad_percents = 0;
|
||||
tcp_port_monitor_args_t tcp_port_monitor_args;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
/* private config items for libdexter */
|
||||
static char *dexter_config = NULL;
|
||||
#endif
|
||||
|
||||
/* Text that is shown */
|
||||
static char original_text[] =
|
||||
"$nodename - $sysname $kernel on $machine\n"
|
||||
@ -6196,12 +6188,6 @@ void clean_up(void)
|
||||
free (specials);
|
||||
specials=NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
dexter_library_exit ();
|
||||
if (dexter_config)
|
||||
free (dexter_config);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int string_to_bool(const char *s)
|
||||
@ -6809,29 +6795,6 @@ else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
|
||||
/* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
CONF("dexter_client")
|
||||
{
|
||||
if (value)
|
||||
dexter_client = string_to_bool (value);
|
||||
else
|
||||
CONF_ERR;
|
||||
}
|
||||
CONF("dexter_server")
|
||||
{
|
||||
if (value)
|
||||
dexter_server = string_to_bool (value);
|
||||
else
|
||||
CONF_ERR;
|
||||
}
|
||||
CONF("dexter_config")
|
||||
{
|
||||
if (value)
|
||||
dexter_config = strdup (value);
|
||||
else
|
||||
CONF_ERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
else
|
||||
ERR("%s: %d: no such configuration: '%s'", f, line, name);
|
||||
@ -7098,48 +7061,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
memset (&packet_arrival_time, 0, sizeof (struct timespec));
|
||||
dexter_library_init ();
|
||||
if (dexter_client)
|
||||
{
|
||||
/* wait until some data packets arrive, else conky complains
|
||||
* bittery that /proc filesystems cannot be opened and, worse,
|
||||
* will likely segfault when it references unchecked pointers
|
||||
* in get_text_internal() -- those should be cleaned up.
|
||||
*/
|
||||
int try;
|
||||
const int max_tries=30;
|
||||
gboolean got_packet;
|
||||
GTimeVal timeval;
|
||||
fprintf (stderr, "Conky: waiting for data packets to arrive ...\n");
|
||||
for (try=0;try<max_tries;try++)
|
||||
{
|
||||
/* pause main thread for 1 sec */
|
||||
g_get_current_time (&timeval);
|
||||
g_time_val_add (&timeval, G_USEC_PER_SEC);
|
||||
g_mutex_lock (packet_mutex);
|
||||
/* mutex released before sleeping; re-acquired after time elapses */
|
||||
g_cond_timed_wait (packet_cond, packet_mutex, &timeval);
|
||||
got_packet = packet_arrival_time.tv_sec>0;
|
||||
g_mutex_unlock (packet_mutex);
|
||||
|
||||
if (got_packet)
|
||||
break;
|
||||
}
|
||||
if (got_packet)
|
||||
{
|
||||
fprintf(stderr, "Conky: packets arriving ...\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Conky: no data packets ...\n");
|
||||
dexter_library_exit ();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef X11
|
||||
selected_font = 0;
|
||||
update_text_area(); /* to get initial size of the window */
|
||||
@ -7214,119 +7135,3 @@ void signal_handler(int sig)
|
||||
* and do any signal processing there, NOT here. */
|
||||
g_signal_pending=sig;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
void dexter_library_init (void)
|
||||
{
|
||||
/* start libdexter */
|
||||
if (dexter_client || dexter_server)
|
||||
{
|
||||
GError *error = NULL;
|
||||
dexter_init (dexter_config, &error);
|
||||
if (error)
|
||||
CRIT_ERR ("%s", error->message);
|
||||
|
||||
if (dexter_client)
|
||||
{
|
||||
if (!(info.dexter.channel = dexter_channel_new (NULL, NULL, NULL, dexter_channel_events)))
|
||||
CRIT_ERR("unable to create channel to server");
|
||||
dexter_channel_open (info.dexter.channel, &error);
|
||||
if (error)
|
||||
CRIT_ERR ("%s", error->message);
|
||||
dexter_channel_greet (info.dexter.channel, &error);
|
||||
if (error)
|
||||
CRIT_ERR ("%s", error->message);
|
||||
if (dexter_client_init () < 0)
|
||||
CRIT_ERR ("error initializing dexter client");
|
||||
|
||||
packet_mutex = g_mutex_new ();
|
||||
packet_cond = g_cond_new ();
|
||||
}
|
||||
|
||||
if (dexter_server)
|
||||
{
|
||||
if (!(info.dexter.server = dexter_server_new (NULL, NULL, NULL)))
|
||||
CRIT_ERR("unable to create server");
|
||||
dexter_server_start (info.dexter.server, &error);
|
||||
if (error)
|
||||
CRIT_ERR ("%s", error->message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void dexter_library_exit (void)
|
||||
{
|
||||
/* shutdown libdexter */
|
||||
if (dexter_client || dexter_server)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (dexter_client)
|
||||
{
|
||||
if (dexter_client_exit () < 0)
|
||||
ERR ("error de-initializing dexter client");
|
||||
if (info.dexter.channel)
|
||||
{
|
||||
dexter_channel_part (info.dexter.channel, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
dexter_channel_close (info.dexter.channel, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
dexter_channel_free (info.dexter.channel);
|
||||
info.dexter.channel=NULL;
|
||||
}
|
||||
|
||||
if (packet_mutex)
|
||||
{
|
||||
g_mutex_free (packet_mutex);
|
||||
packet_mutex=NULL;
|
||||
}
|
||||
if (packet_cond)
|
||||
{
|
||||
g_cond_free (packet_cond);
|
||||
packet_cond=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (dexter_server)
|
||||
{
|
||||
if (info.dexter.server)
|
||||
{
|
||||
dexter_server_stop (info.dexter.server, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
dexter_server_free (info.dexter.server);
|
||||
info.dexter.server=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
dexter_exit ();
|
||||
}
|
||||
}
|
||||
|
||||
void dexter_channel_events (DexterChannel *channel, gint event)
|
||||
{
|
||||
if (!channel)
|
||||
return;
|
||||
|
||||
/* if server disconnects we get this event. we also get it normally
|
||||
* following dexter_channel_part(). */
|
||||
if (event == DEXTER_CHANNEL_EVENT_NOCONN)
|
||||
{
|
||||
fprintf (stderr, "Conky: channel to server closed\n");
|
||||
if (dexter_client && (dexter_client_exit () < 0))
|
||||
ERR ("error de-initializing dexter client");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
36
src/conky.h
36
src/conky.h
@ -32,10 +32,6 @@
|
||||
#include <machine/apm_bios.h>
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
#include <dexter.h>
|
||||
#endif
|
||||
|
||||
#ifdef AUDACIOUS
|
||||
#include "audacious.h"
|
||||
#endif
|
||||
@ -206,35 +202,6 @@ struct entropy_s {
|
||||
#define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
/* main start/stop for libdexter */
|
||||
void dexter_library_init (void);
|
||||
void dexter_library_exit (void);
|
||||
|
||||
/* os-specific init/exit for libdexter client activity */
|
||||
int dexter_client_init (void);
|
||||
int dexter_client_exit (void);
|
||||
|
||||
/* dexter channel events, i.e. we want to know if channel closes */
|
||||
void dexter_channel_events (DexterChannel *, gint);
|
||||
|
||||
/* info struct for libdexter */
|
||||
struct dexter_s {
|
||||
DexterChannel *channel;
|
||||
DexterServer *server;
|
||||
DexterServiceBroker *broker;
|
||||
};
|
||||
|
||||
/* public config items for libdexter */
|
||||
int dexter_client;
|
||||
int dexter_server;
|
||||
|
||||
/* data packet arrival time */
|
||||
struct timespec packet_arrival_time;
|
||||
GMutex *packet_mutex;
|
||||
GCond *packet_cond;
|
||||
#endif
|
||||
|
||||
enum {
|
||||
INFO_CPU = 0,
|
||||
INFO_MAIL = 1,
|
||||
@ -339,9 +306,6 @@ struct information {
|
||||
unsigned long looped;
|
||||
#ifdef TCP_PORT_MONITOR
|
||||
tcp_port_monitor_collection_t * p_tcp_port_monitor_collection;
|
||||
#endif
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
struct dexter_s dexter;
|
||||
#endif
|
||||
short kflags; /* kernel settings, see enum KFLAG */
|
||||
struct entropy_s entropy;
|
||||
|
@ -918,20 +918,3 @@ void
|
||||
free_all_processes(void)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
/* return 0 on success, -1 on failure */
|
||||
int dexter_client_init (void)
|
||||
{
|
||||
/* init libdexter for freebsd-specific client-side activity */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return 0 on success, -1 on failure */
|
||||
int dexter_client_exit (void)
|
||||
{
|
||||
/* de-init libdexter for freebsd-specific client-side activity */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
440
src/linux.c
440
src/linux.c
@ -35,18 +35,6 @@
|
||||
#define SHORTSTAT_TEMPL "%*s %llu %llu %llu"
|
||||
#define LONGSTAT_TEMPL "%*s %llu %llu %llu "
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
/* need the procraw service from the libdexter dxt-sysinfo plugin */
|
||||
#include <dxt-sysinfo/procraw-public.h>
|
||||
#define PROCRAW_SERVICE_UUID "ce975a10-0e52-458a-a4b9-253734760436"
|
||||
/* timed sampler that delivers the procraw data */
|
||||
static DexterTimedSampler *procraw_sampler = NULL;
|
||||
/* procraw structure used as /proc surrogate */
|
||||
static DxtSysinfoProcrawData procraw_data;
|
||||
/* data selector mask for the service */
|
||||
gint procraw_mask;
|
||||
#endif
|
||||
|
||||
static int show_nice_processes;
|
||||
|
||||
/* this flags tells the linux routines to use the /proc system
|
||||
@ -1845,431 +1833,3 @@ void update_entropy (void)
|
||||
|
||||
info.mask |= (1 << INFO_ENTROPY);
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
FILE *open_file(const char *file, int *reported)
|
||||
{
|
||||
/* this version of open_file() is the hook that ties the client/server code
|
||||
* into conky. if conky wants to open a /proc file that the server is feeding
|
||||
* us, we do not return an ordinary file stream pointer to the local /proc
|
||||
* filesystem. instead, we return a string stream pointer to the proc surrogate,
|
||||
* so conky parses remote data as if it were local.
|
||||
*/
|
||||
FILE *fp;
|
||||
|
||||
if ((strcmp (file,"/proc/cpuinfo")==0) && (procraw_mask & PROCRAW_CPUINFO))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.cpuinfo, procraw_data.cpuinfo_sz, "r");
|
||||
}
|
||||
else if ((strcmp (file,"/proc/loadavg")==0) && (procraw_mask & PROCRAW_LOADAVG))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.loadavg, procraw_data.loadavg_sz, "r");
|
||||
}
|
||||
else if ((strcmp (file,"/proc/meminfo")==0) && (procraw_mask & PROCRAW_MEMINFO))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.meminfo, procraw_data.meminfo_sz, "r");
|
||||
}
|
||||
else if ((strcmp (file,"/proc/stat")==0) && (procraw_mask & PROCRAW_STAT))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.stat, procraw_data.stat_sz, "r");
|
||||
}
|
||||
else if ((strcmp (file,"/proc/uptime")==0) && (procraw_mask & PROCRAW_UPTIME))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.uptime, procraw_data.uptime_sz, "r");
|
||||
}
|
||||
else if ((strcmp (file,"/proc/net/dev")==0) && (procraw_mask & PROCRAW_NET_DEV))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.net_dev, procraw_data.net_dev_sz, "r");
|
||||
}
|
||||
else if ((strcmp (file,"/proc/diskstats")==0) && (procraw_mask & PROCRAW_DISKSTATS))
|
||||
{
|
||||
if (!procraw_sampler)
|
||||
return NULL;
|
||||
fp = fmemopen (procraw_data.diskstats, procraw_data.diskstats_sz, "r");
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = fopen(file, "r");
|
||||
}
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
if (!reported || *reported == 0)
|
||||
{
|
||||
ERR("can't open %s: %s", file, strerror(errno));
|
||||
if (reported)
|
||||
*reported = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
void sampler_data_callback (gpointer sampler, gpointer sampler_data)
|
||||
{
|
||||
/* callback runs in a thread */
|
||||
if (!sampler)
|
||||
return;
|
||||
|
||||
if (sampler_data)
|
||||
{
|
||||
FILE *out;
|
||||
char *p;
|
||||
unsigned int i;
|
||||
DxtSysinfoProcrawData *data = (DxtSysinfoProcrawData *)sampler_data;
|
||||
|
||||
/* use GNU string streams and stdio locking to exchange data with main thread. */
|
||||
|
||||
/* update /proc/cpuinfo surrogate */
|
||||
for (;data->cpuinfo;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.cpuinfo, &procraw_data.cpuinfo_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.cpuinfo)
|
||||
{
|
||||
free (procraw_data.cpuinfo); procraw_data.cpuinfo=NULL;
|
||||
}
|
||||
for (p=data->cpuinfo, i=0; i<data->cpuinfo_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* update /proc/loadavg surrogate */
|
||||
for (;data->loadavg;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.loadavg, &procraw_data.loadavg_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.loadavg)
|
||||
{
|
||||
free (procraw_data.loadavg); procraw_data.loadavg=NULL;
|
||||
}
|
||||
for (p=data->loadavg, i=0; i<data->loadavg_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* update /proc/meminfo surrogate */
|
||||
for (;data->meminfo;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.meminfo, &procraw_data.meminfo_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.meminfo)
|
||||
{
|
||||
free (procraw_data.meminfo); procraw_data.meminfo=NULL;
|
||||
}
|
||||
for (p=data->meminfo, i=0; i<data->meminfo_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* update /proc/stat surrogate */
|
||||
for (;data->stat;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.stat, &procraw_data.stat_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.stat)
|
||||
{
|
||||
free (procraw_data.stat); procraw_data.stat=NULL;
|
||||
}
|
||||
for (p=data->stat, i=0; i<data->stat_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* update /proc/uptime surrogate */
|
||||
for (;data->uptime;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.uptime, &procraw_data.uptime_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.uptime)
|
||||
{
|
||||
free (procraw_data.uptime); procraw_data.uptime=NULL;
|
||||
}
|
||||
for (p=data->uptime, i=0; i<data->uptime_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* update /proc/net/dev surrogate */
|
||||
for (;data->net_dev;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.net_dev, &procraw_data.net_dev_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.net_dev)
|
||||
{
|
||||
free (procraw_data.net_dev); procraw_data.net_dev=NULL;
|
||||
}
|
||||
for (p=data->net_dev, i=0; i<data->net_dev_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* update /proc/diskstats surrogate */
|
||||
for (;data->diskstats;)
|
||||
{
|
||||
if (!(out = open_memstream (&procraw_data.diskstats, &procraw_data.diskstats_sz)))
|
||||
break;
|
||||
|
||||
flockfile (out);
|
||||
if (procraw_data.diskstats)
|
||||
{
|
||||
free (procraw_data.diskstats); procraw_data.diskstats=NULL;
|
||||
}
|
||||
for (p=data->diskstats, i=0; i<data->diskstats_sz; i++, p++)
|
||||
{
|
||||
/* we have the FILE lock so use faster putc_unlocked() */
|
||||
if (fputc_unlocked (*p, out) == EOF)
|
||||
break;
|
||||
}
|
||||
fclose (out);
|
||||
funlockfile (out);
|
||||
break;
|
||||
}
|
||||
|
||||
/* record data packet arrival time */
|
||||
g_mutex_lock (packet_mutex);
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
clock_gettime (CLOCK_REALTIME, &packet_arrival_time);
|
||||
#else
|
||||
{
|
||||
/* fallback to gettimeofday () */
|
||||
struct timeval tv;
|
||||
if (gettimeofday (&tv, NULL) == 0)
|
||||
{
|
||||
packet_arrival_time.tv_sec = tv.tv_sec;
|
||||
packet_arrival_time.tv_nsec = tv.tv_usec * 1000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
g_mutex_unlock (packet_mutex);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Conky: data packet arrived\n");
|
||||
#endif
|
||||
|
||||
} /* if (sampler_data) ... */
|
||||
}
|
||||
|
||||
/* return 0 on success, -1 on failure */
|
||||
int dexter_client_init (void)
|
||||
{
|
||||
/* init libdexter for linux-specific client-side activity */
|
||||
|
||||
DexterServiceBroker *broker;
|
||||
DexterPluginServiceGroup *service_group;
|
||||
DexterPluginService *procraw_service;
|
||||
DexterSamplerDataCallback *callbacks;
|
||||
GError *error = NULL;
|
||||
|
||||
/* create a service broker so we can query the server for its services */
|
||||
if (!(broker = dexter_service_broker_new (info.dexter.channel)))
|
||||
{
|
||||
ERR ("unable to create service broker");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* fetch the services from the server */
|
||||
service_group = dexter_service_broker_get_services (broker, DEXTER_SERVICE_SAMPLER, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
dexter_service_broker_free (broker);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* dont need service broker any more */
|
||||
dexter_service_broker_free (broker);
|
||||
broker=NULL;
|
||||
|
||||
/* find the procraw service */
|
||||
procraw_service=NULL;
|
||||
if (!dexterplugin_service_group_find_uuid (&procraw_service, service_group, PROCRAW_SERVICE_UUID))
|
||||
{
|
||||
ERR ("server doesn't offer the procraw service: (%s)", PROCRAW_SERVICE_UUID);
|
||||
dexterplugin_service_group_free (service_group);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* create null-terminated callback list with one callback on it */
|
||||
callbacks = g_new0 (DexterSamplerDataCallback, 2);
|
||||
callbacks[0] = sampler_data_callback;
|
||||
|
||||
/* create the procraw timed sampler, timed to match conky's update_interval */
|
||||
procraw_sampler = dexter_timedsampler_new (procraw_service, update_interval*1000 /* millsecs */,
|
||||
callbacks, info.dexter.channel, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
dexterplugin_service_group_free (service_group);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* free callbacks as libdexter makes internal copy */
|
||||
g_free (callbacks);
|
||||
callbacks=NULL;
|
||||
|
||||
/* initialize the timed sampler */
|
||||
procraw_mask = 0;
|
||||
if (need_mask & (1 << INFO_FREQ))
|
||||
procraw_mask |= PROCRAW_CPUINFO;
|
||||
if (need_mask & (1 << INFO_LOADAVG))
|
||||
procraw_mask |= PROCRAW_LOADAVG;
|
||||
if ((need_mask & (1 << INFO_MEM)) || (need_mask & (1 << INFO_BUFFERS)))
|
||||
procraw_mask |= PROCRAW_MEMINFO;
|
||||
if ((need_mask & (1 << INFO_CPU)) || (need_mask & (1 << INFO_PROCS)) ||
|
||||
(need_mask & (1 << INFO_RUN_PROCS)) || (need_mask & (1 << INFO_FREQ )))
|
||||
procraw_mask |= PROCRAW_STAT;
|
||||
if (need_mask & (1 << INFO_UPTIME))
|
||||
procraw_mask |= PROCRAW_UPTIME;
|
||||
if (need_mask & (1 << INFO_NET))
|
||||
procraw_mask |= PROCRAW_NET_DEV;
|
||||
if (need_mask & (1 << INFO_DISKIO))
|
||||
procraw_mask |= PROCRAW_DISKSTATS;
|
||||
|
||||
dexter_timedsampler_initialize (procraw_sampler, &procraw_mask, NULL, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
dexter_timedsampler_free (procraw_sampler, NULL);
|
||||
dexterplugin_service_group_free (service_group);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* start the timed sampler and begin receiving updates from server */
|
||||
dexter_timedsampler_start (procraw_sampler, &error);
|
||||
if (error)
|
||||
{
|
||||
ERR("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
dexter_timedsampler_free (procraw_sampler, NULL);
|
||||
dexterplugin_service_group_free (service_group);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
dexterplugin_service_group_free (service_group);
|
||||
|
||||
/* so far, so good. tell the linux routines to read /proc,
|
||||
* even if other api's are available. */
|
||||
prefer_proc = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return 0 on success, -1 on failure */
|
||||
int dexter_client_exit (void)
|
||||
{
|
||||
/* de-init libdexter for linux-specific client-side activity */
|
||||
|
||||
if (procraw_sampler)
|
||||
{
|
||||
dexter_timedsampler_stop (procraw_sampler, NULL);
|
||||
dexter_timedsampler_free (procraw_sampler, NULL);
|
||||
procraw_sampler=NULL;
|
||||
}
|
||||
|
||||
/* free left-over sampler data. ok to do this without thread sync because
|
||||
* this function runs in the same thread that conky issues open_file(). */
|
||||
if (procraw_data.cpuinfo)
|
||||
{
|
||||
free (procraw_data.cpuinfo); procraw_data.cpuinfo=NULL;
|
||||
}
|
||||
if (procraw_data.loadavg)
|
||||
{
|
||||
free (procraw_data.loadavg); procraw_data.loadavg=NULL;
|
||||
}
|
||||
if (procraw_data.meminfo)
|
||||
{
|
||||
free (procraw_data.meminfo); procraw_data.meminfo=NULL;
|
||||
}
|
||||
if (procraw_data.stat)
|
||||
{
|
||||
free (procraw_data.stat); procraw_data.stat=NULL;
|
||||
}
|
||||
if (procraw_data.uptime)
|
||||
{
|
||||
free (procraw_data.uptime); procraw_data.uptime=NULL;
|
||||
}
|
||||
if (procraw_data.net_dev)
|
||||
{
|
||||
free (procraw_data.net_dev); procraw_data.net_dev=NULL;
|
||||
}
|
||||
if (procraw_data.diskstats)
|
||||
{
|
||||
free (procraw_data.diskstats); procraw_data.diskstats=NULL;
|
||||
}
|
||||
|
||||
info.uptime=0.0;
|
||||
info.procs=0;
|
||||
info.mem = info.memmax = info.swap = info.swapmax = info.bufmem = info.buffers = info.cached = 0;
|
||||
info.run_procs=0;
|
||||
if (info.cpu_usage)
|
||||
{
|
||||
memset(info.cpu_usage, 0, info.cpu_count * sizeof (float));
|
||||
}
|
||||
clear_net_stats ();
|
||||
diskio_value=0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
17
src/netbsd.c
17
src/netbsd.c
@ -370,20 +370,3 @@ void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size )
|
||||
void update_entropy (void)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBDEXTER
|
||||
/* return 0 on success, -1 on failure */
|
||||
int dexter_client_init (void)
|
||||
{
|
||||
/* init libdexter for netbsd-specific client-side activity */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return 0 on success, -1 on failure */
|
||||
int dexter_client_exit (void)
|
||||
{
|
||||
/* de-init libdexter for netbsd-specific client-side activity */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user