diff --git a/ChangeLog b/ChangeLog index 66123264..73ff1802 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/src/conky.c b/src/conky.c index 3dc2429d..da229d2b 100644 --- a/src/conky.c +++ b/src/conky.c @@ -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); diff --git a/src/conky.h b/src/conky.h index f1f5eb7d..d59c23be 100644 --- a/src/conky.h +++ b/src/conky.h @@ -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 { diff --git a/src/freebsd.c b/src/freebsd.c index a70530a3..056f2069 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -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() diff --git a/src/linux.c b/src/linux.c index fb57fe7e..619ed551 100644 --- a/src/linux.c +++ b/src/linux.c @@ -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; } /* diff --git a/src/netbsd.c b/src/netbsd.c index 6e4fcbfa..4849e9e8 100644 --- a/src/netbsd.c +++ b/src/netbsd.c @@ -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; }