[powertop] Catch fstream exceptions

Jaroslav Škarvada jskarvad at fedoraproject.org
Wed Jul 4 08:09:43 UTC 2012


commit 89070cf48e13d3b027bff0d65ff999a3de527bc7
Author: Jaroslav Škarvada <jskarvad at redhat.com>
Date:   Wed Jul 4 10:09:35 2012 +0200

    Catch fstream exceptions
    
      Resolves: rhbz#832497

 powertop-2.0-catch-fstream-errors.patch |   98 +++++++++++++++++++++++++++++++
 powertop.spec                           |    9 +++-
 2 files changed, 106 insertions(+), 1 deletions(-)
---
diff --git a/powertop-2.0-catch-fstream-errors.patch b/powertop-2.0-catch-fstream-errors.patch
new file mode 100644
index 0000000..f56600f
--- /dev/null
+++ b/powertop-2.0-catch-fstream-errors.patch
@@ -0,0 +1,98 @@
+commit e3a0dce60a1ff1663dab0f91cc4dacf89b565dea
+Author: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
+Date:   Fri May 18 13:17:39 2012 +0300
+
+    catch fstream exceptions in lib routines
+    
+    Catch possible fstream and traits_type exceptions in lib.
+    
+    Reported-by: Lekensteyn <lekensteyn at gmail.com>
+    Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
+
+diff --git a/src/lib.cpp b/src/lib.cpp
+index 53638dd..bcd809f 100644
+--- a/src/lib.cpp
++++ b/src/lib.cpp
+@@ -172,8 +172,13 @@ void write_sysfs(const string &filename, const string &value)
+ 	file.open(filename.c_str(), ios::out);
+ 	if (!file)
+ 		return;
+-	file << value;
+-	file.close();
++	try 
++	{
++		file << value;
++		file.close();
++	} catch (std::exception &exc) {
++		return;
++	}
+ }
+ 
+ int read_sysfs(const string &filename, bool *ok)
+@@ -187,10 +192,17 @@ int read_sysfs(const string &filename, bool *ok)
+ 			*ok = false;
+ 		return 0;
+ 	}
+-	file >> i;
++	try
++	{
++		file >> i;
++		if (ok)
++			*ok = true;
++	} catch (std::exception &exc) {
++		if (ok)
++			*ok = "false";
++		i = 0;
++	}
+ 	file.close();
+-	if (ok)
+-		*ok = true;
+ 	return i;
+ }
+ 
+@@ -203,11 +215,17 @@ string read_sysfs_string(const string &filename)
+ 	file.open(filename.c_str(), ios::in);
+ 	if (!file)
+ 		return "";
+-	file.getline(content, 4096);
+-	file.close();
+-	c = strchr(content, '\n');
+-	if (c)
+-		*c = 0;
++	try
++	{
++		file.getline(content, 4096);
++		file.close();
++		c = strchr(content, '\n');
++		if (c)
++			*c = 0;
++	} catch (std::exception &exc) {
++		file.close();
++		return "";
++	}
+ 	return content;
+ }
+ 
+@@ -224,11 +242,17 @@ string read_sysfs_string(const char *format, const char *param)
+ 	file.open(filename, ios::in);
+ 	if (!file)
+ 		return "";
+-	file.getline(content, 4096);
+-	file.close();
+-	c = strchr(content, '\n');
+-	if (c)
+-		*c = 0;
++	try
++	{
++		file.getline(content, 4096);
++		file.close();
++		c = strchr(content, '\n');
++		if (c)
++			*c = 0;
++	} catch (std::exception &exc) {
++		file.close();
++		return "";
++	}
+ 	return content;
+ }
+ 
diff --git a/powertop.spec b/powertop.spec
index 4e09c44..f75502a 100644
--- a/powertop.spec
+++ b/powertop.spec
@@ -1,6 +1,6 @@
 Name:          powertop
 Version:       2.0
-Release:       2%{?dist}
+Release:       3%{?dist}
 Summary:       Power consumption monitor
 
 Group:         Applications/System
@@ -17,6 +17,8 @@ Patch2:        powertop-2.0-show-watts-only-if-discharging.patch
 Patch3:        powertop-2.0-valid-html-output.patch
 # Patch for rhbz#823502, backported from upstream
 Patch4:        powertop-2.0-factor-out-powertop-init.patch
+# Patch for rhbz#832497, backported from upstream
+Patch5:        powertop-2.0-catch-fstream-errors.patch
 BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires: gettext, ncurses-devel, pciutils-devel, zlib-devel, libnl-devel
 
@@ -31,6 +33,7 @@ computer use more power than necessary while it is idle.
 %patch2 -p1 -b .show-watts-only-if-discharging
 %patch3 -p1 -b .valid-html-output
 %patch4 -p1 -b .factor-out-powertop-init
+%patch5 -p1 -b .catch-fstream-errors
 
 %build
 %configure
@@ -62,6 +65,10 @@ rm -rf %{buildroot}
 #%{_mandir}/man8/powertop.8*
 
 %changelog
+* Wed Jul  4 2012 Jaroslav Škarvada <jskarvad at redhat.com> - 2.0-3
+- Catch fstream exceptions
+  Resolves: rhbz#832497
+
 * Mon May 21 2012 Jaroslav Škarvada <jskarvad at redhat.com> - 2.0-2
 - Fixed segfault during calibration
   Resolves: rhbz#823502


More information about the scm-commits mailing list