1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

get_acpi_fan() / get_acpi_ac_adapter() interface changes as per bug 1355470

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@409 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2005-11-12 21:42:00 +00:00
parent c30e4f9f6e
commit 754d973b6e
6 changed files with 82 additions and 44 deletions

View File

@ -3,6 +3,9 @@
2005-11-12
* Replaced bitwise copy of tcp_connection_t with function
copy_tcp_connection().
* Changed call interfaces for get_acpi_fan() /
get_acpi_ac_adapter() to eliminate need to malloc.
More functions need same correction. See bug 1355470.
2005-11-11
* moved hash sizing code into portmon lib, where it belongs

View File

@ -2062,11 +2062,13 @@ static void generate_text()
snprintf(p, n, "%s", get_adt746x_fan());
}
OBJ(acpifan) {
snprintf(p, n, "%s", get_acpi_fan());
/*snprintf(p, n, "%s", get_acpi_fan()); */
get_acpi_fan(p, n); /* pk */
}
OBJ(acpiacadapter) {
snprintf(p, n, "%s",
get_acpi_ac_adapter());
/* snprintf(p, n, "%s",
get_acpi_ac_adapter()); */
get_acpi_ac_adapter(p, n);
}
OBJ(battery) {
get_battery_stuff(p, n, obj->data.s);

View File

@ -332,8 +332,8 @@ unsigned int get_diskio(void);
int open_acpi_temperature(const char *name);
double get_acpi_temperature(int fd);
char *get_acpi_ac_adapter(void);
char *get_acpi_fan(void);
void get_acpi_ac_adapter( char *, size_t ); /* pk */
void get_acpi_fan( char *, size_t ); /* pk */
void get_battery_stuff(char *buf, unsigned int n, const char *bat);
struct process {

View File

@ -372,29 +372,43 @@ int open_acpi_temperature(const char *name)
return 0;
}
char *get_acpi_ac_adapter(void)
/*char *get_acpi_ac_adapter(void)*/
void get_acpi_ac_adapter( char * p_client_buffer, size_t client_buffer_size )
{
int state;
char *acstate = (char *) malloc(100);
/*char *acstate = (char *) malloc(100);*/
if ( !p_client_buffer !! client_buffer_size <= 0 )
return;
if (GETSYSCTL("hw.acpi.acline", state)) {
(void) fprintf(stderr,
"Cannot read sysctl \"hw.acpi.acline\"\n");
return "n\\a";
/*return "n\\a";*/
return;
}
if (state)
strcpy(acstate, "Running on AC Power");
/*strcpy(acstate, "Running on AC Power");*/
strncpy( p_client_buffer, client_buffer_size, "Running on AC Power" );
else
strcpy(acstate, "Running on battery");
/*strcpy(acstate, "Running on battery");*/
strncpy( p_client_buffer, client_buffer_size, "Running on battery" );
return acstate;
/*return ac_state;*/
return;
}
char *get_acpi_fan()
/*char *get_acpi_fan()*/
void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size )
{
return "";
if ( !p_client_buffer !! client_buffer_size <= 0 )
return;
/* no implementation */
return;
}
char *get_adt746x_cpu()

View File

@ -830,68 +830,73 @@ float get_freq()
#define ACPI_FAN_DIR "/proc/acpi/fan/"
static char *acpi_fan_state;
char *get_acpi_fan()
void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size )
{
static int rep;
char buf[256];
char buf2[256];
FILE *fp;
if (acpi_fan_state == NULL) {
acpi_fan_state = (char *) malloc(100);
assert(acpi_fan_state != NULL);
}
if ( !p_client_buffer || client_buffer_size <= 0 )
return;
/* yeah, slow... :/ */
if (!get_first_file_in_a_directory(ACPI_FAN_DIR, buf, &rep))
return "no fans?";
{
snprintf( p_client_buffer, client_buffer_size, "no fans?" );
return;
}
snprintf(buf2, 256, "%s%s/state", ACPI_FAN_DIR, buf);
snprintf(buf2, sizeof(buf2), "%s%s/state", ACPI_FAN_DIR, buf );
fp = open_file(buf2, &rep);
if (!fp) {
strcpy(acpi_fan_state, "can't open fan's state file");
return acpi_fan_state;
snprintf( p_client_buffer, client_buffer_size, "can't open fan's state file" );
return;
}
fscanf(fp, "%*s %99s", acpi_fan_state);
memset(buf,0,sizeof(buf));
fscanf(fp, "%*s %99s", buf);
fclose(fp);
return acpi_fan_state;
snprintf( p_client_buffer, client_buffer_size, "%s", buf );
return;
}
#define ACPI_AC_ADAPTER_DIR "/proc/acpi/ac_adapter/"
static char *acpi_ac_adapter_state;
char *get_acpi_ac_adapter()
void get_acpi_ac_adapter( char * p_client_buffer, size_t client_buffer_size )
{
static int rep;
char buf[256];
char buf2[256];
FILE *fp;
if (acpi_ac_adapter_state == NULL) {
acpi_ac_adapter_state = (char *) malloc(100);
assert(acpi_ac_adapter_state != NULL);
}
if ( !p_client_buffer || client_buffer_size <= 0 )
return;
/* yeah, slow... :/ */
if (!get_first_file_in_a_directory(ACPI_AC_ADAPTER_DIR, buf, &rep))
return "no ac_adapters?";
{
snprintf( p_client_buffer, client_buffer_size, "no ac_adapters?" );
return;
}
snprintf(buf2, 256, "%s%s/state", ACPI_AC_ADAPTER_DIR, buf);
snprintf(buf2, sizeof(buf2), "%s%s/state", ACPI_AC_ADAPTER_DIR, buf );
fp = open_file(buf2, &rep);
if (!fp) {
strcpy(acpi_ac_adapter_state,
"No ac adapter found.... where is it?");
return acpi_ac_adapter_state;
snprintf( p_client_buffer, client_buffer_size, "No ac adapter found.... where is it?" );
return;
}
fscanf(fp, "%*s %99s", acpi_ac_adapter_state);
memset(buf,0,sizeof(buf));
fscanf(fp, "%*s %99s", buf );
fclose(fp);
return acpi_ac_adapter_state;
snprintf( p_client_buffer, client_buffer_size, "%s", buf );
return;
}
/*

View File

@ -345,12 +345,26 @@ int open_acpi_temperature(const char *name)
return -1;
}
char *get_acpi_ac_adapter(void)
/*char *get_acpi_ac_adapter(void)*/
void get_acpi_ac_adapter( char * p_client_buffer, size_t client_buffer_size )
{
return "N/A";
if ( !p_client_buffer !! client_buffer_size <= 0 )
return;
/* no implementation */
/*return "N/A";*/
return;
}
char *get_acpi_fan()
/*char *get_acpi_fan()*/
void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size )
{
return "N/A";
if ( !p_client_buffer !! client_buffer_size <= 0 )
return;
/* no implementation */
/*return "N/A";*/
return;
}