Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sawmill_logger: don't try to access sysfs entries when not existent #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/pwrevents/sawmill_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ static long unsigned int sTotalMSScreenOff = 0;
static bool sIsAwake = true;
static guint sTimerEventSource = 0;

#define SYSFS_A6_DEVICE "/sys/class/misc/a6_0/regs/"
#define DEF_BATTERY_PATH "/sys/devices/w1 bus master/w1_master_slaves/"

static bool sSysfsA6DeviceNodeExists = false;
static bool sSysfsBatteryPathExists = false;


#define NS_PER_MS 1000000
#define MS_PER_S 1000
long int
Expand Down Expand Up @@ -437,19 +444,22 @@ void read_proc_net_dev()

void get_battery_coulomb_reading(double *rc, double *c)
{
#define SYSFS_A6_DEVICE "/sys/class/misc/a6_0/regs/"
#define DEF_BATTERY_PATH "/sys/devices/w1 bus master/w1_master_slaves/"

if (g_file_test(SYSFS_A6_DEVICE, G_FILE_TEST_IS_DIR))
if (sSysfsA6DeviceNodeExists)
{
SysfsGetDouble(SYSFS_A6_DEVICE "getrawcoulomb", rc);
SysfsGetDouble(SYSFS_A6_DEVICE "getcoulomb", c);
}
else
else if (sSysfsBatteryPathExists)
{
SysfsGetDouble(DEF_BATTERY_PATH "getrawcoulomb", rc);
SysfsGetDouble(DEF_BATTERY_PATH "getcoulomb", c);
}
else
{
/* we don't have support for getrawcoulomb/getcoulomb */
*rc = 0.0;
*c = 0.0;
}
}

gboolean
Expand Down Expand Up @@ -521,6 +531,9 @@ _sawlog_init(void)
sTimeScreenOff = time_now_ms();
sTimerEventSource = g_timeout_add_full(G_PRIORITY_DEFAULT, PRINT_INTERVAL_MS, sawmill_logger_update, GINT_TO_POINTER(TRUE), NULL);

sSysfsA6DeviceNodeExists = g_file_test(SYSFS_A6_DEVICE, G_FILE_TEST_IS_DIR);
sSysfsBatteryPathExists = g_file_test(DEF_BATTERY_PATH, G_FILE_TEST_IS_DIR);

return 0;
}

Expand Down