]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
ras-record: don't try to record if database open failed
authorMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 13 Mar 2013 11:43:50 +0000 (08:43 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 13 Mar 2013 11:43:50 +0000 (08:43 -0300)
Check if ras->stmt is not null before writing it. That avoids
the risk of trying to write something if the database was not
opened.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
ras-record.c

index 52d1c6ea45fbf8e3022f3224f71cf58cf5e9fbf0..8773ab216df543c9a3656bba01063343190934cd 100644 (file)
@@ -73,6 +73,8 @@ sqlite3 *ras_mc_event_opendb(struct ras_events *ras)
        sqlite3 *db;
        char sql[1024];
 
+       ras->stmt = NULL;
+
        rc = sqlite3_initialize();
        if (rc != SQLITE_OK) {
                printf("Failed to initialize sqlite: error = %d\n", rc);
@@ -126,6 +128,9 @@ int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev)
 {
        int rc;
 
+       if (!ras->stmt)
+               return;
+
        sqlite3_bind_text(ras->stmt,  1, ev->timestamp, -1, NULL);
        sqlite3_bind_int (ras->stmt,  2, ev->error_count);
        sqlite3_bind_text(ras->stmt,  3, ev->error_type, -1, NULL);