1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-11 18:38:45 +00:00

support displaying current nameservers

* gathers information from /etc/resolv.conf
* included (still commented) code to prevent reading too often,
  as I'm not sure whether reading from a real FS (not /proc or /sys)
  could generate higher load in some cases -> comments please!


git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1035 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Phil 2008-03-22 22:58:26 +00:00
parent bcbca8cb5b
commit 6a528f4e17
5 changed files with 86 additions and 5 deletions

View File

@ -1004,6 +1004,10 @@ Prints the file name of the current MPD song
\fB\*(T<\fBmpd_smart\fR\*(T>\fR
Prints the song name in either the form "artist - title" or file name, depending on whats available
.TP
\fB\*(T<\fBnameserver\fR\*(T>\fR \*(T<\fB(index)\fR\*(T>
Print a nameserver from /etc/resolv.conf. Index starts at and defaults to 0.
.TP
\fB\*(T<\fBnew_mails\fR\*(T>\fR \*(T<\fB(mailbox)\fR\*(T> \*(T<\fB(interval)\fR\*(T>
Unread mail count in the specified mailbox or mail spool if

View File

@ -1421,6 +1421,16 @@
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>nameserver</option></command>
<option>(index)</option>
</term>
<listitem>
Print a nameserver from /etc/resolv.conf. Index starts at and defaults to 0.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>new_mails</option></command>

View File

@ -160,6 +160,50 @@ void clear_net_stats(void)
memset(netstats, 0, sizeof(netstats));
}
void free_dns_data(void)
{
int i;
struct dns_data *data = &info.nameserver_info;
for (i = 0; i < data->nscount; i++)
free(data->ns_list[i]);
if (data->ns_list)
free(data->ns_list);
memset(data, 0, sizeof(struct dns_data));
}
//static double last_dns_update;
void update_dns_data(void)
{
FILE *fp;
char line[256];
struct dns_data *data = &info.nameserver_info;
/* maybe updating too often causes higher load because of /etc lying on a real FS
if (current_update_time - last_dns_update < 10.0)
return;
else
last_dns_update = current_update_time;
*/
free_dns_data();
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
return;
while(!feof(fp)) {
if (fgets(line, 255, fp) == NULL)
goto OUT;
if (!strncmp(line, "nameserver ", 11)) {
line[strlen(line) - 1] = '\0'; // remove trailing newline
data->nscount++;
data->ns_list = realloc(data->ns_list, data->nscount * sizeof(char *));
data->ns_list[data->nscount - 1] = strdup(line + 11);
}
}
OUT:
fclose(fp);
}
void format_seconds(char *buf, unsigned int n, long t)
{
if (t >= 24 * 60 * 60) { /* hours necessary when there are days? */
@ -314,6 +358,9 @@ void update_stuff()
if (NEED(INFO_GW)) {
update_gateway_info();
}
if (NEED(INFO_DNS)) {
update_dns_data();
}
}
int round_to_int(float f)

View File

@ -1185,6 +1185,7 @@ enum text_object_type {
OBJ_mixerbar,
OBJ_mixerlbar,
OBJ_mixerrbar,
OBJ_nameserver,
OBJ_new_mails,
OBJ_nodename,
OBJ_pre_exec,
@ -2177,6 +2178,9 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
free(objs[i].data.texeci.cmd);
free(objs[i].data.texeci.buffer);
break;
case OBJ_nameserver:
free_dns_data();
break;
case OBJ_top:
case OBJ_top_mem:
if (info.first_process) {
@ -2850,6 +2854,8 @@ static struct text_object *construct_text_object(const char *s,
obj->data.fs = prepare_fs_stat(arg);
END OBJ(hr, 0)
obj->data.i = arg ? atoi(arg) : 1;
END OBJ(nameserver, INFO_DNS)
obj->data.i = arg ? atoi(arg) : 0;
END OBJ(offset, 0)
obj->data.i = arg ? atoi(arg) : 1;
END OBJ(voffset, 0)
@ -5130,6 +5136,11 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(hr) {
new_hr(p, obj->data.i);
}
OBJ(nameserver) {
if (cur->nameserver_info.nscount > obj->data.i)
snprintf(p, p_max_size, "%s",
cur->nameserver_info.ns_list[obj->data.i]);
}
#ifdef RSS
OBJ(rss) {
PRSS *data = get_rss_info(obj->data.rss.uri,

View File

@ -135,6 +135,11 @@ struct net_stat {
char ap[18];
};
struct dns_data {
int nscount;
char **ns_list;
};
unsigned int diskio_value;
unsigned int diskio_read_value;
unsigned int diskio_write_value;
@ -305,7 +310,8 @@ enum {
INFO_SMAPI = 25,
#endif
INFO_USERS = 26,
INFO_GW = 27
INFO_GW = 27,
INFO_DNS = 28
};
/* get_battery_stuff() item selector */
@ -369,6 +375,7 @@ struct information {
#endif
struct usr_info users;
struct gateway_info gw_info;
struct dns_data nameserver_info;
struct process *cpu[10];
struct process *memu[10];
struct process *first_process;
@ -515,6 +522,8 @@ void format_seconds(char *buf, unsigned int n, long t);
void format_seconds_short(char *buf, unsigned int n, long t);
struct net_stat *get_net_stat(const char *dev);
void clear_net_stats(void);
void free_dns_data(void);
void update_dns_data(void);
void update_users();
void update_stuff();