mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-22 22:58:34 +00:00
fixed some errors
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@658 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
39d836dcb1
commit
536489f676
24
src/conky.c
24
src/conky.c
@ -1996,6 +1996,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
||||
{
|
||||
obj->data.cpu_index=atoi(&arg[0]);
|
||||
}
|
||||
obj->a = 1;
|
||||
END OBJ(freq_g, 0)
|
||||
get_cpu_count();
|
||||
if (!arg
|
||||
@ -2011,6 +2012,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
||||
{
|
||||
obj->data.cpu_index=atoi(&arg[0]);
|
||||
}
|
||||
obj->a = 1;
|
||||
END OBJ(voltage_mv, 0)
|
||||
get_cpu_count();
|
||||
if (!arg
|
||||
@ -2020,12 +2022,13 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
||||
|| (unsigned int)atoi(&arg[0])>info.cpu_count)
|
||||
{
|
||||
obj->data.cpu_index=1;
|
||||
ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
|
||||
// ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->data.cpu_index=atoi(&arg[0]);
|
||||
}
|
||||
obj->a = 1;
|
||||
END OBJ(voltage_v, 0)
|
||||
get_cpu_count();
|
||||
if (!arg
|
||||
@ -2035,12 +2038,13 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
||||
|| (unsigned int)atoi(&arg[0])>info.cpu_count)
|
||||
{
|
||||
obj->data.cpu_index=1;
|
||||
ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
|
||||
// ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->data.cpu_index=atoi(&arg[0]);
|
||||
}
|
||||
obj->a = 1;
|
||||
#else
|
||||
END OBJ(freq, 0);
|
||||
END OBJ(freq_g, 0);
|
||||
@ -3155,16 +3159,24 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
||||
i)+ 40) * 9.0 / 5 - 40));
|
||||
}
|
||||
OBJ(freq) {
|
||||
get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index); /* pk */
|
||||
if (obj->a) {
|
||||
obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index); /* pk */
|
||||
}
|
||||
}
|
||||
OBJ(freq_g) {
|
||||
get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index); /* pk */
|
||||
if (obj->a) {
|
||||
obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index); /* pk */
|
||||
}
|
||||
}
|
||||
OBJ(voltage_mv) {
|
||||
get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index); /* ptarjan */
|
||||
if (obj->a) {
|
||||
obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index); /* ptarjan */
|
||||
}
|
||||
}
|
||||
OBJ(voltage_v) {
|
||||
get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index); /* ptarjan */
|
||||
if (obj->a) {
|
||||
obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index); /* ptarjan */
|
||||
}
|
||||
}
|
||||
|
||||
OBJ(freq_dyn) {
|
||||
|
@ -461,9 +461,9 @@ void update_cpu_usage(void);
|
||||
void update_total_processes(void);
|
||||
void update_running_processes(void);
|
||||
void update_i8k(void);
|
||||
void get_freq( char *, size_t, char *, int, unsigned int ); /* pk */
|
||||
char get_freq( char *, size_t, char *, int, unsigned int ); /* pk */
|
||||
void get_freq_dynamic( char *, size_t, char *, int ); /* pk */
|
||||
void get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
|
||||
char get_voltage(char *, size_t, char *, int, unsigned int ); /* ptarjan */
|
||||
void update_load_average();
|
||||
int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
|
||||
char *devtype);
|
||||
|
67
src/linux.c
67
src/linux.c
@ -851,7 +851,7 @@ void get_freq_dynamic( char * p_client_buffer, size_t client_buffer_size, char *
|
||||
#define CPUFREQ_POSTFIX "cpufreq/scaling_cur_freq"
|
||||
|
||||
/* return system frequency in MHz (use divisor=1) or GHz (use divisor=1000) */
|
||||
void get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_format, int divisor, unsigned int cpu )
|
||||
char get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_format, int divisor, unsigned int cpu )
|
||||
{
|
||||
FILE *f;
|
||||
char frequency[32];
|
||||
@ -864,8 +864,8 @@ void get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
CPUFREQ_PREFIX, cpu, CPUFREQ_POSTFIX);
|
||||
|
||||
if ( !p_client_buffer || client_buffer_size <= 0 || !p_format || divisor <= 0 )
|
||||
return;
|
||||
|
||||
return 0;
|
||||
|
||||
f = fopen(current_freq_file, "r");
|
||||
if (f) {
|
||||
/* if there's a cpufreq /sys node, read the current frequency from this node;
|
||||
@ -876,13 +876,15 @@ void get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
}
|
||||
fclose(f);
|
||||
snprintf( p_client_buffer, client_buffer_size, p_format, (freq/1000)/divisor );
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cpu++;
|
||||
f = fopen("/proc/cpuinfo", "r"); //open the CPU information file
|
||||
if (!f)
|
||||
return;
|
||||
if (!f) {
|
||||
perror("Conky: Failed to access '/proc/cpuinfo' at get_freq()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgets(s, sizeof(s), f) != NULL){ //read the file
|
||||
|
||||
@ -915,13 +917,13 @@ void get_freq( char * p_client_buffer, size_t client_buffer_size, char * p_forma
|
||||
|
||||
fclose(f);
|
||||
snprintf( p_client_buffer, client_buffer_size, p_format, (float)freq/divisor );
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define CPUFREQ_VOLTAGE "cpufreq/scaling_voltages"
|
||||
|
||||
/* return cpu voltage in mV (use divisor=1) or V (use divisor=1000) */
|
||||
void get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_format, int divisor, unsigned int cpu )
|
||||
char get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_format, int divisor, unsigned int cpu )
|
||||
{
|
||||
/* /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages looks
|
||||
something like this:
|
||||
@ -950,7 +952,7 @@ void get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_fo
|
||||
CPUFREQ_PREFIX, cpu, CPUFREQ_POSTFIX);
|
||||
|
||||
if ( !p_client_buffer || client_buffer_size <= 0 || !p_format || divisor <= 0 )
|
||||
return;
|
||||
return 0;
|
||||
|
||||
/* read the current cpu frequency from the /sys node */
|
||||
f = fopen(current_freq_file, "r");
|
||||
@ -960,12 +962,13 @@ void get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_fo
|
||||
freq = strtod(s, NULL);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("voltage: No %s.", current_freq_file);
|
||||
fclose(f);
|
||||
return;
|
||||
} else {
|
||||
fprintf(stderr, "Conky: Failed to access '%s' at ", current_freq_file);
|
||||
perror("get_voltage()");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(current_freq_file, 127, "%s/cpu%d/%s",
|
||||
@ -974,26 +977,24 @@ void get_voltage( char * p_client_buffer, size_t client_buffer_size, char * p_fo
|
||||
/* use the current cpu frequency to find the corresponding voltage */
|
||||
f = fopen(current_freq_file, "r");
|
||||
|
||||
if (f)
|
||||
{
|
||||
while (!feof(f))
|
||||
{
|
||||
char line[256];
|
||||
if (fgets(line, 255, f) == NULL) break;
|
||||
sscanf(line, "%d %d", &freq_comp, &voltage);
|
||||
if(freq_comp == freq) break;
|
||||
}
|
||||
fclose(f);
|
||||
if (f) {
|
||||
while (!feof(f)) {
|
||||
char line[256];
|
||||
if (fgets(line, 255, f) == NULL) break;
|
||||
sscanf(line, "%d %d", &freq_comp, &voltage);
|
||||
if(freq_comp == freq) break;
|
||||
}
|
||||
fclose(f);
|
||||
} else {
|
||||
fprintf(stderr, "Conky: Failed to access '%s' at ", current_freq_file);
|
||||
perror("get_voltage()");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("voltage: No %s.", current_freq_file);
|
||||
fclose(f);
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf( p_client_buffer, client_buffer_size, p_format, (float)voltage/divisor );
|
||||
return;
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user