~ubuntu-branches/debian/sid/conky/sid

« back to all changes in this revision

Viewing changes to src/entropy.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Tirabassi
  • Date: 2010-03-28 21:19:51 UTC
  • mfrom: (1.3.1 upstream) (16.1.17 lucid)
  • Revision ID: james.westby@ubuntu.com-20100328211951-ejq536k2r858srli
Tags: 1.8.0-1
* New upstream release:
  - add AF_UNIX socket support
  - fix sigsegv if config file is deleted (LP: #525926)
  - the following debian bugs are closed by this upload:
    + change automake1.10 to automake1.11 (Closes: #550929)
    + hwmon made compatible with kernels >= 2.6.31 (Closes: #556926)
    + text_buffer_size change is well documented (Closes: #519401)
    + fix diskio for not existing devices (Closes: #536557)
    + fix wrong mixer values on some systems (Closes: #540282)
    + fix minor memory leak (Closes: #566524)
    + fix some documentation error re. graphs (Closes: #564518)
    + add -p/--pause startup option (Closes: #513440)
    + fix documentation about mixer values (Closes: #538760)
* This release is based on the Ubuntu package with the following changes
  necessary for Debian (Closes: #536320):
  - change control and rules to build correctly on non-Linux arches
    (Closes: #536326)
  - updated NEWS, descriptions in control and changelog
  - change archive area to contrib
* Change priority of metapackage to extra
* My utmost thanks go to Kapil Hari Paranjape for his packaging work and to
  Luca Falavigna for being so kind to review and sponsor this release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
 
2
 * vim: ts=4 sw=4 noet ai cindent syntax=c
 
3
 *
 
4
 * Conky, a system monitor, based on torsmo
 
5
 *
 
6
 * Any original torsmo code is licensed under the BSD license
 
7
 *
 
8
 * All code written since the fork of torsmo is licensed under the GPL
 
9
 *
 
10
 * Please see COPYING for details
 
11
 *
 
12
 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
 
13
 * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
 
14
 *      (see AUTHORS)
 
15
 * All rights reserved.
 
16
 *
 
17
 * This program is free software: you can redistribute it and/or modify
 
18
 * it under the terms of the GNU General Public License as published by
 
19
 * the Free Software Foundation, either version 3 of the License, or
 
20
 * (at your option) any later version.
 
21
 *
 
22
 * This program is distributed in the hope that it will be useful,
 
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
25
 * GNU General Public License for more details.
 
26
 * You should have received a copy of the GNU General Public License
 
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
28
 *
 
29
 */
 
30
 
 
31
#include "config.h"
 
32
#include "conky.h"
 
33
#include "text_object.h"
 
34
 
 
35
/* check for OS and include appropriate headers */
 
36
#if defined(__linux__)
 
37
#include "linux.h"
 
38
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 
39
#include "freebsd.h"
 
40
#elif defined(__OpenBSD__)
 
41
#include "openbsd.h"
 
42
#endif
 
43
 
 
44
static struct {
 
45
        unsigned int avail;
 
46
        unsigned int poolsize;
 
47
} entropy = {
 
48
        .avail = 0,
 
49
        .poolsize = 0,
 
50
};
 
51
 
 
52
void update_entropy(void)
 
53
{
 
54
        get_entropy_avail(&entropy.avail);
 
55
        get_entropy_poolsize(&entropy.poolsize);
 
56
}
 
57
 
 
58
void print_entropy_avail(struct text_object *obj, char *p, int p_max_size)
 
59
{
 
60
        (void)obj;
 
61
        snprintf(p, p_max_size, "%u", entropy.avail);
 
62
}
 
63
 
 
64
void print_entropy_perc(struct text_object *obj, char *p, int p_max_size)
 
65
{
 
66
        (void)obj;
 
67
        percent_print(p, p_max_size, entropy.avail *
 
68
                        100 / entropy.poolsize);
 
69
}
 
70
 
 
71
void print_entropy_poolsize(struct text_object *obj, char *p, int p_max_size)
 
72
{
 
73
        (void)obj;
 
74
        snprintf(p, p_max_size, "%u", entropy.poolsize);
 
75
}
 
76
 
 
77
void print_entropy_bar(struct text_object *obj, char *p, int p_max_size)
 
78
{
 
79
        double ratio;
 
80
 
 
81
        (void)obj;
 
82
 
 
83
        ratio = (double) entropy.avail /
 
84
                (double) entropy.poolsize;
 
85
        new_bar(obj, p, p_max_size, (int) (ratio * 255.0f));
 
86
}