Ticket #7060: libs_libmyth-check-return-value-ticket-7060

File libs_libmyth-check-return-value-ticket-7060, 8.2 KB (added by Erik Hovland <erik@…>, 11 years ago)

Same patch as before but against trunk as of 2010-02-03

Line 
1A bunch of functions (like read and write) return status values. They should be checked.
2
3From: Erik Hovland <erik@hovland.org>
4
5
6---
7
8 mythtv/libs/libmyth/dbutil.cpp          |   16 ++++++++++------
9 mythtv/libs/libmyth/mythcdrom-linux.cpp |    5 ++++-
10 mythtv/libs/libmyth/mythcontext.cpp     |   26 ++++++++++++++++++++------
11 mythtv/libs/libmyth/remoteutil.cpp      |   21 +++++++++++++++------
12 mythtv/libs/libmyth/remoteutil.h        |    2 +-
13 5 files changed, 50 insertions(+), 20 deletions(-)
14
15
16diff --git a/mythtv/libs/libmyth/dbutil.cpp b/mythtv/libs/libmyth/dbutil.cpp
17index 7cafe50..4416ae1 100644
18--- a/mythtv/libs/libmyth/dbutil.cpp
19+++ b/mythtv/libs/libmyth/dbutil.cpp
20@@ -220,9 +220,11 @@ MythDBBackupStatus DBUtil::BackupDB(QString &filename)
21     bool result = false;
22     MSqlQuery query(MSqlQuery::InitCon());
23 
24-    gContext->SaveSettingOnHost("BackupDBLastRunStart",
25-                                QDateTime::currentDateTime()
26-                                .toString("yyyy-MM-dd hh:mm:ss"), NULL);
27+    result = gContext->SaveSettingOnHost("BackupDBLastRunStart",
28+                                         QDateTime::currentDateTime()
29+                                         .toString("yyyy-MM-dd hh:mm:ss"), NULL);
30+    if (!result)
31+        VERBOSE(VB_IMPORTANT, "SaveSettingOnHost failed.");
32 
33     if (!backupScript.isEmpty())
34     {
35@@ -235,9 +237,11 @@ MythDBBackupStatus DBUtil::BackupDB(QString &filename)
36     if (!result)
37         result = DoBackup(filename);
38 
39-    gContext->SaveSettingOnHost("BackupDBLastRunEnd",
40-                                QDateTime::currentDateTime()
41-                                .toString("yyyy-MM-dd hh:mm:ss"), NULL);
42+    result = gContext->SaveSettingOnHost("BackupDBLastRunEnd",
43+                                         QDateTime::currentDateTime()
44+                                         .toString("yyyy-MM-dd hh:mm:ss"), NULL);
45+    if (!result)
46+        VERBOSE(VB_IMPORTANT, "SaveSettingOnHost failed.");
47 
48     if (query.isConnected())
49     {
50diff --git a/mythtv/libs/libmyth/mythcdrom-linux.cpp b/mythtv/libs/libmyth/mythcdrom-linux.cpp
51index 600eb1c..72669a9 100644
52--- a/mythtv/libs/libmyth/mythcdrom-linux.cpp
53+++ b/mythtv/libs/libmyth/mythcdrom-linux.cpp
54@@ -285,7 +285,10 @@ int MythCDROMLinux::SCSIstatus()
55 MediaError MythCDROMLinux::eject(bool open_close)
56 {
57     if (!isDeviceOpen())
58-        openDevice();
59+    {
60+        if (!openDevice())
61+            return MEDIAERR_FAILED;
62+    }
63 
64     if (open_close)
65         return (ioctl(m_DeviceHandle, CDROMEJECT) == 0) ? MEDIAERR_OK
66diff --git a/mythtv/libs/libmyth/mythcontext.cpp b/mythtv/libs/libmyth/mythcontext.cpp
67index 4b112ac..8ef7fa9 100644
68--- a/mythtv/libs/libmyth/mythcontext.cpp
69+++ b/mythtv/libs/libmyth/mythcontext.cpp
70@@ -185,7 +185,10 @@ static void exec_program_tv_cb(const QString &cmd)
71     else
72         strlist << "LOCK_TUNER";
73 
74-    gContext->SendReceiveStringList(strlist);
75+    if (!gContext->SendReceiveStringList(strlist))
76+        VERBOSE(VB_IMPORTANT,
77+                "SendReceiveStringList() for LOCK_TUNER failed");
78+
79     int cardid = strlist[0].toInt();
80 
81     if (cardid >= 0)
82@@ -198,7 +201,10 @@ static void exec_program_tv_cb(const QString &cmd)
83         myth_system(s);
84 
85         strlist = QStringList(QString("FREE_TUNER %1").arg(cardid));
86-        gContext->SendReceiveStringList(strlist);
87+        if (!gContext->SendReceiveStringList(strlist))
88+            VERBOSE(VB_IMPORTANT,
89+                    "SendReceiveStringList() for FREE_TUNER failed");
90+
91         QString ret = strlist[0];
92     }
93     else
94@@ -1039,7 +1045,11 @@ int MythContextPrivate::ChooseBackend(const QString &error)
95     switch (selected)
96     {
97         case kDialogCodeButton0:
98-            WriteSettingsFile(m_DBparams, true);
99+            if (!WriteSettingsFile(m_DBparams, true))
100+            {
101+                VERBOSE(VB_IMPORTANT, "WriteSettingsFile failed.");
102+                return -1;
103+            }
104             // User prefers mysql.txt, so throw away default UPnP backend:
105             m_XML->SetValue(kDefaultUSN, "");
106             m_XML->Save();
107@@ -1813,7 +1823,9 @@ bool MythContext::IsFrontendOnly(void)
108     QStringList strlist("QUERY_IS_ACTIVE_BACKEND");
109     strlist << GetHostName();
110 
111-    SendReceiveStringList(strlist);
112+    if (!SendReceiveStringList(strlist))
113+        VERBOSE(VB_IMPORTANT,
114+                "SendReceiveStringList() for QUERY_IS_ACTIVE_BACKEND failed");
115 
116     if (QString(strlist[0]) == "FALSE")
117         backendOnLocalhost = false;
118@@ -2009,7 +2021,8 @@ bool MythContext::SendReceiveStringList(QStringList &strlist,
119     if (!d->serverSock)
120     {
121         bool blockingClient = gContext->GetNumSetting("idleTimeoutSecs",0) > 0;
122-        ConnectToMasterServer(blockingClient);
123+        if (!ConnectToMasterServer(blockingClient))
124+            return false;
125     }
126 
127     bool ok = false;
128@@ -2026,7 +2039,8 @@ bool MythContext::SendReceiveStringList(QStringList &strlist,
129             d->serverSock = NULL;
130 
131             bool blockingClient = gContext->GetNumSetting("idleTimeoutSecs",0) > 0;
132-            ConnectToMasterServer(blockingClient);
133+            if (!ConnectToMasterServer(blockingClient))
134+                return false;
135 
136             if (d->serverSock)
137             {
138diff --git a/mythtv/libs/libmyth/remoteutil.cpp b/mythtv/libs/libmyth/remoteutil.cpp
139index 9740907..a1084d0 100644
140--- a/mythtv/libs/libmyth/remoteutil.cpp
141+++ b/mythtv/libs/libmyth/remoteutil.cpp
142@@ -171,7 +171,9 @@ bool RemoteUndeleteRecording(uint chanid, const QDateTime &recstartts)
143     strlist.push_back(QString::number(chanid));
144     strlist.push_back(recstartts.toString(Qt::ISODate));
145 
146-    gContext->SendReceiveStringList(strlist);
147+    if (!gContext->SendReceiveStringList(strlist))
148+        VERBOSE(VB_IMPORTANT,
149+                "SendReceiveStringList() for UNDELETE_RECORDING failed");
150 
151     if (strlist[0].toInt() == 0)
152         result = true;
153@@ -185,10 +187,10 @@ void RemoteGetAllScheduledRecordings(vector<ProgramInfo *> &scheduledlist)
154     RemoteGetRecordingList(&scheduledlist, strList);
155 }
156 
157-void RemoteGetAllExpiringRecordings(vector<ProgramInfo *> &expiringlist)
158+int RemoteGetAllExpiringRecordings(vector<ProgramInfo *> &expiringlist)
159 {
160     QStringList strList(QString("QUERY_GETEXPIRING"));
161-    RemoteGetRecordingList(&expiringlist, strList);
162+    return RemoteGetRecordingList(&expiringlist, strList);
163 }
164 
165 int RemoteGetRecordingList(vector<ProgramInfo *> *reclist, QStringList &strList)
166@@ -226,7 +228,9 @@ vector<ProgramInfo *> *RemoteGetConflictList(const ProgramInfo *pginfo)
167 
168     vector<ProgramInfo *> *retlist = new vector<ProgramInfo *>;
169 
170-    RemoteGetRecordingList(retlist, strlist);
171+    if (!RemoteGetRecordingList(retlist, strlist))
172+        retlist->clear();
173+
174     return retlist;
175 }
176 
177@@ -257,7 +261,10 @@ void RemoteSendMessage(const QString &message)
178     QStringList strlist( "MESSAGE" );
179     strlist << message;
180 
181-    gContext->SendReceiveStringList(strlist);
182+    if (!gContext->SendReceiveStringList(strlist))
183+        VERBOSE(VB_IMPORTANT,
184+                QString("SendReceiveStringList() for MESSAGE %1 failed")
185+                    .arg(message));
186 }
187 
188 void RemoteSendEvent(const MythEvent &event)
189@@ -280,7 +287,9 @@ void RemoteGeneratePreviewPixmap(const ProgramInfo *pginfo)
190     QStringList strlist( "QUERY_GENPIXMAP" );
191     pginfo->ToStringList(strlist);
192 
193-    gContext->SendReceiveStringList(strlist);
194+    if (!gContext->SendReceiveStringList(strlist))
195+        VERBOSE(VB_IMPORTANT,
196+                "SendReceiveStringList() for QUERY_GENPIXMAP failed");
197 }
198     
199 QDateTime RemoteGetPreviewLastModified(const ProgramInfo *pginfo)
200diff --git a/mythtv/libs/libmyth/remoteutil.h b/mythtv/libs/libmyth/remoteutil.h
201index f71da48..3983e79 100644
202--- a/mythtv/libs/libmyth/remoteutil.h
203+++ b/mythtv/libs/libmyth/remoteutil.h
204@@ -45,7 +45,7 @@ bool RemoteUndeleteRecording(uint chanid, const QDateTime &recstartts);
205 MPUBLIC
206 void RemoteGetAllScheduledRecordings(vector<ProgramInfo *> &scheduledlist);
207 MPUBLIC
208-void RemoteGetAllExpiringRecordings(vector<ProgramInfo *> &expiringlist);
209+int RemoteGetAllExpiringRecordings(vector<ProgramInfo *> &expiringlist);
210 MPUBLIC int RemoteGetRecordingList(vector<ProgramInfo *> *reclist,
211                                    QStringList &strList);
212 MPUBLIC vector<ProgramInfo *> *RemoteGetConflictList(const ProgramInfo *pginfo);