From: Kamala Narasimhan Date: Tue, 30 Jun 2009 18:37:21 +0000 (-0400) Subject: xenpmd syslog support. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=06011497d8406a37729f53f27a474380eaa912f9;p=xenclient%2Fxen-pq.git xenpmd syslog support. --- diff --git a/master/oem-features b/master/oem-features index fa7ed2b..06cc5aa 100644 --- a/master/oem-features +++ b/master/oem-features @@ -2639,22 +2639,23 @@ index 0000000..f60b372 +} + diff --git a/tools/xenpmd/acpi-events.c b/tools/xenpmd/acpi-events.c -index 8baf720..dfd9b84 100644 +index d991eb0..0293975 100644 --- a/tools/xenpmd/acpi-events.c +++ b/tools/xenpmd/acpi-events.c -@@ -79,6 +79,11 @@ void handle_sbtn_pressed_event(void) +@@ -87,6 +87,12 @@ void handle_sbtn_pressed_event(void) xs_write(xs, XBT_NULL, XS_SBTN_EVENT_PATH, "1", 1); } +void handle_oem_event(void) +{ ++ xenpmd_log(LOG_INFO, "Received oem event\n"); + xs_write(xs, XBT_NULL, XS_OEM_EVENT_PATH, "1", 1); +} + void process_acpi_message(char *acpi_buffer) { if ( strstr(acpi_buffer, "ac_adapter") ) -@@ -101,7 +106,14 @@ void process_acpi_message(char *acpi_buffer) +@@ -109,7 +115,14 @@ void process_acpi_message(char *acpi_buffer) } if ( strstr(acpi_buffer, "SBTN") ) @@ -2670,12 +2671,14 @@ index 8baf720..dfd9b84 100644 static void *acpi_events_thread(void *arg) diff --git a/tools/xenpmd/xenpmd.h b/tools/xenpmd/xenpmd.h -index 062675c..c1a462c 100644 +index 211e847..48cece1 100644 --- a/tools/xenpmd/xenpmd.h +++ b/tools/xenpmd/xenpmd.h -@@ -101,4 +101,5 @@ void acpi_events_cleanup(void); +@@ -106,6 +106,7 @@ void acpi_events_cleanup(void); #define XS_LID_EVENT_PATH "/pm/events/lidstatechanged" #define XS_PBTN_EVENT_PATH "/pm/events/powerbuttonpressed" #define XS_SBTN_EVENT_PATH "/pm/events/sleepbuttonpressed" +#define XS_OEM_EVENT_PATH "/oem/event" + #ifndef RUN_STANDALONE + #define xenpmd_log(priority, format, p...) syslog(priority, format, ##p) diff --git a/master/power-management-enhancement b/master/power-management-enhancement index f1a7f3d..9cb887b 100644 --- a/master/power-management-enhancement +++ b/master/power-management-enhancement @@ -699,10 +699,10 @@ index 10cb2fb..6881169 100644 --include $(DEPS) diff --git a/tools/xenpmd/acpi-events.c b/tools/xenpmd/acpi-events.c new file mode 100644 -index 0000000..8baf720 +index 0000000..d991eb0 --- /dev/null +++ b/tools/xenpmd/acpi-events.c -@@ -0,0 +1,149 @@ +@@ -0,0 +1,164 @@ +/* + * acpi-events.c + * @@ -742,7 +742,11 @@ index 0000000..8baf720 + xs_write(xs, XBT_NULL, xenstore_path, default_value, strlen(default_value)); + file = fopen(file_path, "r"); + if ( file == NULL ) ++ { ++ xenpmd_log(LOG_NOTICE, "File %s failed to open with error %d\n", ++ file_path, errno); + return; ++ } + + memset(file_data, 0, 1024); + fgets(file_data, 1024, file); @@ -762,6 +766,7 @@ index 0000000..8baf720 + +void handle_ac_adapter_state_change(void) +{ ++ xenpmd_log(LOG_INFO, "AC adapter state change event\n"); + write_state_info_in_xenstore(AC_ADAPTER_STATE_FILE_PATH, + XS_AC_ADAPTER_STATE_PATH, "off-line", "1", "0"); + xs_write(xs, XBT_NULL, XS_AC_ADAPTER_EVENT_PATH, "1", 1); @@ -769,6 +774,7 @@ index 0000000..8baf720 + +void handle_lid_state_change(void) +{ ++ xenpmd_log(LOG_INFO, "LID state change event\n"); + write_state_info_in_xenstore(LID_STATE_FILE_PATH, XS_LID_STATE_PATH, + "closed", "1", "0"); + xs_write(xs, XBT_NULL, XS_LID_EVENT_PATH, "1", 1); @@ -776,11 +782,13 @@ index 0000000..8baf720 + +void handle_pbtn_pressed_event(void) +{ ++ xenpmd_log(LOG_INFO, "Power button pressed event\n"); + xs_write(xs, XBT_NULL, XS_PBTN_EVENT_PATH, "1", 1); +} + +void handle_sbtn_pressed_event(void) +{ ++ xenpmd_log(LOG_INFO, "Sleep button pressed event\n"); + xs_write(xs, XBT_NULL, XS_SBTN_EVENT_PATH, "1", 1); +} + @@ -817,14 +825,20 @@ index 0000000..8baf720 + + socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); + if ( socket_fd == -1) ++ { ++ xenpmd_log(LOG_ERR, "socket function failed with error - %d\n", errno); + return (void *)socket_fd; ++ } + + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, ACPID_SOCKET_PATH, strlen(ACPID_SOCKET_PATH)); + addr.sun_path[strlen(ACPID_SOCKET_PATH)] = '\0'; + ret = connect(socket_fd, (struct sockaddr *)&addr, sizeof(addr)); + if ( ret == -1 ) ++ { ++ xenpmd_log(LOG_ERR, "Socket connection function failed with error - %d\n", errno); + return (void *)ret; ++ } + + while( 1 ) + { @@ -846,6 +860,7 @@ index 0000000..8baf720 + +void acpi_events_cleanup(void) +{ ++ xenpmd_log(LOG_INFO, "In acpi events cleanup\n"); + if ( socket_fd != -1 ) + close(socket_fd); + @@ -853,7 +868,7 @@ index 0000000..8baf720 +} + diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c -index 28de744..50583b8 100644 +index 28de744..ff6d39d 100644 --- a/tools/xenpmd/xenpmd.c +++ b/tools/xenpmd/xenpmd.c @@ -33,68 +33,10 @@ @@ -968,7 +983,7 @@ index 28de744..50583b8 100644 if (type == BIF) memset(info_or_status, 0, sizeof(struct battery_info)); else -@@ -306,8 +257,11 @@ int get_next_battery_info_or_status(DIR *battery_dir, +@@ -306,31 +257,34 @@ int get_next_battery_info_or_status(DIR *battery_dir, if ( !file ) return 0; @@ -981,46 +996,99 @@ index 28de744..50583b8 100644 fclose(file); return 1; -@@ -317,14 +271,14 @@ int get_next_battery_info_or_status(DIR *battery_dir, + } + +-#ifdef RUN_STANDALONE ++#ifdef XENPMD_DEBUG void print_battery_info(struct battery_info *info) { - printf("present: %d\n", info->present); +- printf("present: %d\n", info->present); - printf("design capacity: %d\n", info->design_capacity); - printf("last full capacity: %d\n", info->last_full_capacity); -+ printf("design capacity: %d\n", (int) info->design_capacity); -+ printf("last full capacity: %d\n", (int) info->last_full_capacity); - printf("battery technology: %d\n", info->battery_technology); +- printf("battery technology: %d\n", info->battery_technology); - printf("design voltage: %d\n", info->design_voltage); - printf("design capacity warning:%d\n", info->design_capacity_warning); - printf("design capacity low: %d\n", info->design_capacity_low); - printf("capacity granularity 1: %d\n", info->capacity_granularity_1); - printf("capacity granularity 2: %d\n", info->capacity_granularity_2); -+ printf("design voltage: %d\n", (int) info->design_voltage); -+ printf("design capacity warning:%d\n", (int) info->design_capacity_warning); -+ printf("design capacity low: %d\n", (int) info->design_capacity_low); -+ printf("capacity granularity 1: %d\n", (int) info->capacity_granularity_1); -+ printf("capacity granularity 2: %d\n", (int) info->capacity_granularity_2); - printf("model number: %s\n", info->model_number); - printf("serial number: %s\n", info->serial_number); - printf("battery type: %s\n", info->battery_type); -@@ -406,10 +360,11 @@ int write_one_time_battery_info(void) +- printf("model number: %s\n", info->model_number); +- printf("serial number: %s\n", info->serial_number); +- printf("battery type: %s\n", info->battery_type); +- printf("OEM info: %s\n", info->oem_info); ++ xenpmd_log(LOG_DEBUG, "present: %d\n", info->present); ++ xenpmd_log(LOG_DEBUG, "design capacity: %d\n", (int) info->design_capacity); ++ xenpmd_log(LOG_DEBUG, "last full capacity: %d\n", (int) info->last_full_capacity); ++ xenpmd_log(LOG_DEBUG, "battery technology: %d\n", info->battery_technology); ++ xenpmd_log(LOG_DEBUG, "design voltage: %d\n", (int) info->design_voltage); ++ xenpmd_log(LOG_DEBUG, "design capacity warning:%d\n", (int) info->design_capacity_warning); ++ xenpmd_log(LOG_DEBUG, "design capacity low: %d\n", (int) info->design_capacity_low); ++ xenpmd_log(LOG_DEBUG, "capacity granularity 1: %d\n", (int) info->capacity_granularity_1); ++ xenpmd_log(LOG_DEBUG, "capacity granularity 2: %d\n", (int) info->capacity_granularity_2); ++ xenpmd_log(LOG_DEBUG, "model number: %s\n", info->model_number); ++ xenpmd_log(LOG_DEBUG, "serial number: %s\n", info->serial_number); ++ xenpmd_log(LOG_DEBUG, "battery type: %s\n", info->battery_type); ++ xenpmd_log(LOG_DEBUG, "OEM info: %s\n", info->oem_info); + } +-#endif /*RUN_STANDALONE*/ ++#endif /*XENPMD_DEBUG*/ + + void write_ulong_lsb_first(char *temp_val, unsigned long val) + { +@@ -383,16 +337,21 @@ int write_one_time_battery_info(void) + + dir = opendir(BATTERY_DIR_PATH); + if ( !dir ) ++ { ++ xenpmd_log(LOG_ERR, "Failed to open dir %s with error - %d\n", ++ BATTERY_DIR_PATH, errno); + return 0; ++ } + + while ( get_next_battery_info_or_status(dir, BIF, (void *)&info) ) + { +-#ifdef RUN_STANDALONE ++#ifdef XENPMD_DEBUG + print_battery_info(&info); + #endif + if ( info.present == YES ) + { + write_battery_info_to_xenstore(&info); ++ xenpmd_log(LOG_INFO, "One time battery information written to xenstore\n"); + ret = 1; + break; /* rethink this... */ + } +@@ -402,16 +361,17 @@ int write_one_time_battery_info(void) + return ret; + } + +-#ifdef RUN_STANDALONE ++#ifdef XENPMD_DEBUG void print_battery_status(struct battery_status *status) { - printf("present: %d\n", status->present); +- printf("present: %d\n", status->present); - printf("Battery state %d\n", status->state); - printf("Battery present rate %d\n", status->present_rate); - printf("Battery remining capacity %d\n", status->remaining_capacity); - printf("Battery present voltage %d\n", status->present_voltage); -+ printf("Battery state %d\n", (int) status->state); -+ printf("Battery present rate %d\n", (int) status->present_rate); -+ printf("Battery remining capacity %d\n", ++ xenpmd_log(LOG_DEBUG, "present: %d\n", status->present); ++ xenpmd_log(LOG_DEBUG, "Battery state %d\n", (int) status->state); ++ xenpmd_log(LOG_DEBUG, "Battery present rate %d\n", (int) status->present_rate); ++ xenpmd_log(LOG_DEBUG, "Battery remining capacity %d\n", + (int) status->remaining_capacity); -+ printf("Battery present voltage %d\n", (int) status->present_voltage); ++ xenpmd_log(LOG_DEBUG, "Battery present voltage %d\n", (int) status->present_voltage); } - #endif /*RUN_STANDALONE*/ +-#endif /*RUN_STANDALONE*/ ++#endif /*XENPMD_DEBUG*/ + + void write_battery_status_to_xenstore(struct battery_status *status) + { +@@ -427,55 +387,78 @@ void write_battery_status_to_xenstore(struct battery_status *status) + write_ulong_lsb_first(val+26, status->present_voltage); -@@ -429,46 +384,59 @@ void write_battery_status_to_xenstore(struct battery_status *status) xs_write(xs, XBT_NULL, "/pm/bst", val, 35); ++#ifdef XENPMD_DEBUG ++ xenpmd_log(LOG_DEBUG, "Updated battery information in xenstore\n"); ++#endif } -int wait_for_and_update_battery_status_request(void) @@ -1032,26 +1100,30 @@ index 28de744..50583b8 100644 struct battery_status status; - while ( true ) -- { ++ /* KN:@TODO - It is rather inefficient to not cache the file handle. ++ * Switch to caching file handle. ++ */ ++ dir = opendir(BATTERY_DIR_PATH); ++ if ( !dir ) + { - /* KN:@TODO - It is rather inefficient to not cache the file handle. - * Switch to caching file handle. - */ - dir = opendir(BATTERY_DIR_PATH); - if ( !dir ) - return 0; -+ /* KN:@TODO - It is rather inefficient to not cache the file handle. -+ * Switch to caching file handle. -+ */ -+ dir = opendir(BATTERY_DIR_PATH); -+ if ( !dir ) ++ xenpmd_log(LOG_ERR, "opendir failed for directory %s with error - %d\n", ++ BATTERY_DIR_PATH, errno); + return; ++ } - while ( get_next_battery_info_or_status(dir, BST, (void *)&status) ) - { +-#ifdef RUN_STANDALONE +- print_battery_status(&status); + while ( get_next_battery_info_or_status(dir, BST, (void *)&status) ) + { - #ifdef RUN_STANDALONE -- print_battery_status(&status); ++#ifdef XENPMD_DEBUG + print_battery_status(&status); #endif - if ( status.present == YES ) @@ -1081,8 +1153,8 @@ index 28de744..50583b8 100644 - return ret; + closedir(dir); + return; -+} -+ + } + +void wait_for_and_update_power_mgmt_info(void) +{ + char **buffer; @@ -1101,13 +1173,39 @@ index 28de744..50583b8 100644 + } + free(buffer); + } - } - ++} ++ +#ifndef RUN_STANDALONE /* Borrowed daemonize from xenstored - Initially written by Stevens. */ static void daemonize(void) { -@@ -493,24 +461,51 @@ static void daemonize(void) + pid_t pid; + + if ( (pid = fork()) < 0 ) ++ { ++ xenpmd_log(LOG_ERR, "Failed to fork - %d\n", errno); + exit(1); ++ } + + if ( pid != 0 ) + exit(0); +@@ -483,34 +466,73 @@ static void daemonize(void) + setsid(); + + if ( (pid = fork()) < 0 ) ++ { ++ xenpmd_log(LOG_ERR, "Failed to fork - %d\n", errno); + exit(1); ++ } + + if ( pid != 0 ) + exit(0); + + if ( chdir("/") == -1 ) ++ { ++ xenpmd_log(LOG_ERR, "chdir failed with error - %d\n", errno); + exit(1); ++ } umask(0); } @@ -1133,7 +1231,10 @@ index 28de744..50583b8 100644 - if ( xs == NULL ) - return -1; + if ( xs == NULL ) ++ { ++ xenpmd_log(LOG_ERR, "Unable to get a handle to XS daemon\n"); + return NULL; ++ } - if ( write_one_time_battery_info() == 0 ) + initialize_system_state_info(); @@ -1142,6 +1243,7 @@ index 28de744..50583b8 100644 { xs_daemon_close(xs); - return -1; ++ xenpmd_log(LOG_ERR, "Unable to write one time battery information\n"); + return NULL; } @@ -1150,6 +1252,7 @@ index 28de744..50583b8 100644 + acpi_events_cleanup(); xs_daemon_close(xs); - return 0; ++ closelog(); + return NULL; } @@ -1157,7 +1260,8 @@ index 28de744..50583b8 100644 +int main(int argc, char *argv[]) +{ +#ifndef RUN_STANDALONE -+ daemonize(); ++ openlog("xenpmd", 0, LOG_DAEMON); ++ daemonize(); +#endif + + /* Refer to worker_thread_routine for why we create additional thread */ @@ -1171,10 +1275,10 @@ index 28de744..50583b8 100644 +} diff --git a/tools/xenpmd/xenpmd.h b/tools/xenpmd/xenpmd.h new file mode 100644 -index 0000000..778ba38 +index 0000000..211e847 --- /dev/null +++ b/tools/xenpmd/xenpmd.h -@@ -0,0 +1,107 @@ +@@ -0,0 +1,115 @@ +/* + * xenpmd.h + * @@ -1212,10 +1316,12 @@ index 0000000..778ba38 +#include +#include +#include ++#include +#include + +/* #define RUN_STANDALONE */ +/* #define RUN_IN_SIMULATE_MODE */ ++/* #define XENPMD_DEBUG */ + +enum BATTERY_INFO_TYPE { + BIF, @@ -1282,3 +1388,9 @@ index 0000000..778ba38 +#define XS_PBTN_EVENT_PATH "/pm/events/powerbuttonpressed" +#define XS_SBTN_EVENT_PATH "/pm/events/sleepbuttonpressed" + ++#ifndef RUN_STANDALONE ++ #define xenpmd_log(priority, format, p...) syslog(priority, format, ##p) ++#else ++ #define xenpmd_log(priority, format, p...) printf(format, ##p) ++#endif ++ diff --git a/master/thermal-management b/master/thermal-management index 9eb05b0..0bad114 100644 --- a/master/thermal-management +++ b/master/thermal-management @@ -43,10 +43,10 @@ index 8f2d7a7..6f2ade9 100644 * changes like ac power to battery use etc. */ diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c -index 50583b8..72742a8 100644 +index 7ac6a87..9f84992 100644 --- a/tools/xenpmd/xenpmd.c +++ b/tools/xenpmd/xenpmd.c -@@ -416,14 +416,144 @@ void update_battery_status(void) +@@ -428,14 +428,147 @@ void update_battery_status(void) return; } @@ -175,6 +175,9 @@ index 50583b8..72742a8 100644 + + snprintf(buffer, 32, "%d", critical_trip_point); + xs_write(xs, XBT_NULL, "/pm/critical_temperature", buffer, strlen(buffer)); ++#ifdef XENPMD_DEBUG ++ xenpmd_log(LOG_DEBUG, "Updated thermal information in xenstore\n"); ++#endif +} + void wait_for_and_update_power_mgmt_info(void) @@ -191,7 +194,7 @@ index 50583b8..72742a8 100644 while ( true ) { buffer = xs_read_watch(xs, &count); -@@ -431,7 +561,11 @@ void wait_for_and_update_power_mgmt_info(void) +@@ -443,7 +576,11 @@ void wait_for_and_update_power_mgmt_info(void) continue; if (!strcmp(buffer[XS_WATCH_TOKEN], "refreshbatterystatus")) { update_battery_status(); @@ -204,10 +207,10 @@ index 50583b8..72742a8 100644 } } diff --git a/tools/xenpmd/xenpmd.h b/tools/xenpmd/xenpmd.h -index c1a462c..508196e 100644 +index 48cece1..a44c73c 100644 --- a/tools/xenpmd/xenpmd.h +++ b/tools/xenpmd/xenpmd.h -@@ -84,10 +84,14 @@ void acpi_events_cleanup(void); +@@ -89,10 +89,14 @@ void acpi_events_cleanup(void); #define BATTERY_DIR_PATH "/tmp/battery" #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info" #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"