Skip to contentSkip to conversation

fix some compiler warnings

PATCH In review Danny Al-Gaaf 3 participants 7 messages Jan 27, 2013 – Jan 29, 2013

lore
Share & tools
lore
#0 lore raw

cover fix some compiler warnings

Attached two patches to fix some compiler warnings.

Danny Al-Gaaf (2):
utime: fix narrowing conversion compiler warning in sleep()
rbd: don't ignore return value of system()

 src/include/utime.h |  2 +-
 src/rbd.cc          | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 31 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.1.1
#1 lore raw

PATCH 1/2 utime: fix narrowing conversion compiler warning in sleep()

Fix compiler warning:
./include/utime.h: In member function 'void utime_t::sleep()':
./include/utime.h:139:50: warning: narrowing conversion of
'((utime_t*)this)->utime_t::tv.utime_t::<anonymous struct>::tv_sec' from '__u32 {aka unsigned int}' to '__time_t {aka long int}' inside { } is ill-formed in C++11 [-Wnarrowing]
./include/utime.h:139:50: warning: narrowing conversion of
'((utime_t*)this)->utime_t::tv.utime_t::<anonymous struct>::tv_nsec' from '__u32 {aka unsigned int}' to 'long int' inside { } is ill-formed in C++11 [-Wnarrowing]

---
 src/include/utime.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/include/utime.h +1 -1
index 526dec5..f433fff 100644
@@ -136,7 +136,7 @@ public:
   }
 
   void sleep() {
-    struct timespec ts = { tv.tv_sec, tv.tv_nsec };
+    struct timespec ts = { (__time_t)tv.tv_sec, (long)tv.tv_nsec };
     nanosleep(&ts, &ts);
   }
 
Signature · 1 line
1.8.1.1
#2 lore raw

Re: [PATCH 1/2] utime: fix narrowing conversion compiler warning in sleep()

Hi,

could someone cherry-pick this patch to the bobtail branch? I see the same issue there.

Thanks!

Danny

Am 27.01.2013 21:57, schrieb Danny Al-Gaaf:

Quoted 30 lines

Fix compiler warning:
./include/utime.h: In member function 'void utime_t::sleep()':
./include/utime.h:139:50: warning: narrowing conversion of
'((utime_t*)this)->utime_t::tv.utime_t::<anonymous struct>::tv_sec' from '__u32 {aka unsigned int}' to '__time_t {aka long int}' inside { } is ill-formed in C++11 [-Wnarrowing]
./include/utime.h:139:50: warning: narrowing conversion of
'((utime_t*)this)->utime_t::tv.utime_t::<anonymous struct>::tv_nsec' from '__u32 {aka unsigned int}' to 'long int' inside { } is ill-formed in C++11 [-Wnarrowing]

---
 src/include/utime.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/include/utime.h +1 -1
index 526dec5..f433fff 100644
@@ -136,7 +136,7 @@ public:
   }
 
   void sleep() {
-    struct timespec ts = { tv.tv_sec, tv.tv_nsec };
+    struct timespec ts = { (__time_t)tv.tv_sec, (long)tv.tv_nsec };
     nanosleep(&ts, &ts);
   }
 
#3 lore raw

Re: [PATCH 1/2] utime: fix narrowing conversion compiler warning in sleep()

Quoted 4 lines · Danny Al-Gaaf

Hi,

could someone cherry-pick this patch to the bobtail branch? I see the same issue there.

Cherry-picked, thanks!

s

Quoted 39 lines

Thanks!

Danny

Am 27.01.2013 21:57, schrieb Danny Al-Gaaf:

Quoted 30 lines

Fix compiler warning:
./include/utime.h: In member function 'void utime_t::sleep()':
./include/utime.h:139:50: warning: narrowing conversion of
'((utime_t*)this)->utime_t::tv.utime_t::<anonymous struct>::tv_sec' from '__u32 {aka unsigned int}' to '__time_t {aka long int}' inside { } is ill-formed in C++11 [-Wnarrowing]
./include/utime.h:139:50: warning: narrowing conversion of
'((utime_t*)this)->utime_t::tv.utime_t::<anonymous struct>::tv_nsec' from '__u32 {aka unsigned int}' to 'long int' inside { } is ill-formed in C++11 [-Wnarrowing]

---
 src/include/utime.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/include/utime.h +1 -1
index 526dec5..f433fff 100644
@@ -136,7 +136,7 @@ public:
   }
 
   void sleep() {
-    struct timespec ts = { tv.tv_sec, tv.tv_nsec };
+    struct timespec ts = { (__time_t)tv.tv_sec, (long)tv.tv_nsec };
     nanosleep(&ts, &ts);
   }
 
#4 lore raw

PATCH 2/2 rbd: don't ignore return value of system()

In reply to Danny Al-Gaaf

Check for the return value of system() and handle the error if needed

---
 src/rbd.cc | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)
src/rbd.cc +30 -6
index 833188a..bdbc684 100644
@@ -1428,8 +1428,16 @@ static int do_kernel_add(const char *poolname, const char *imgname,
 
   // modprobe the rbd module if /sys/bus/rbd doesn't exist
   struct stat sb;
-  if ((stat("/sys/bus/rbd", &sb) < 0) || (!S_ISDIR(sb.st_mode)))
-    system("/sbin/modprobe rbd");
+  if ((stat("/sys/bus/rbd", &sb) < 0) || (!S_ISDIR(sb.st_mode))) {
+    r = system("/sbin/modprobe rbd");
+    if (r) {
+      if (r < 0)  
+        cerr << "rbd: error executing modprobe as shell command!" << std::endl;
+      else
+        cerr << "rbd: modprobe rbd failed! (" << r << ")" <<std::endl;
+      return r;
+    }
+  }
 
   // write to /sys/bus/rbd/add
   int fd = open("/sys/bus/rbd/add", O_WRONLY);
@@ -1448,8 +1456,16 @@ static int do_kernel_add(const char *poolname, const char *imgname,
   close(fd);
 
   // let udevadm do its job before we return
-  if (udevadm_settle)
-    system("/sbin/udevadm settle");
+  if (udevadm_settle) {
+    r = system("/sbin/udevadm settle");
+    if (r) {
+      if (r < 0)  
+        cerr << "rbd: error executing udevadm as shell command!" << std::endl;
+      else
+        cerr << "rbd: '/sbin/udevadm settle' failed! (" << r << ")" <<std::endl;
+      return r;
+    }
+  }
 
   return r;
 }
@@ -1664,8 +1680,16 @@ static int do_kernel_rm(const char *dev)
   r = close(fd);
 
   // let udevadm finish, if present
-  if (udevadm_settle)
-    system("/sbin/udevadm settle");
+  if (udevadm_settle){
+    r = system("/sbin/udevadm settle");
+    if (r) {
+      if (r < 0)  
+        cerr << "rbd: error executing udevadm as shell command!" << std::endl;
+      else
+        cerr << "rbd: '/sbin/udevadm settle' failed! (" << r << ")" <<std::endl;
+      return r;
+    }
+  }
 
   if (r < 0)
     r = -errno;
Signature · 1 line
1.8.1.1
#5 lore raw
In reply to Danny Al-Gaaf

I'd just noticed utime on my laptop 32-bit build and was trying to figure out why our 32-bit nightly didn't see it. And Greg had seen the system build problem where I didn't, and I was isolating differences there as well.

I purposely didn't spend time on the system() error handling because I was thinking of those calls as best-effort, if they fail the map will likely fail anyway, but there's no harm in handling errors, particularly if it'll shit the compiler up :)

Quoted 17 lines · Danny Al-Gaaf

Attached two patches to fix some compiler warnings.

Danny Al-Gaaf (2):
utime: fix narrowing conversion compiler warning in sleep()
rbd: don't ignore return value of system()

src/include/utime.h | 2 +-
src/rbd.cc | 36 ++++++++++++++++++++++++++++++------

2 files changed, 31 insertions(+), 7 deletions(-)
Signature · 6 lines
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
In reply to Danny Al-Gaaf

Sage merged these into master. Thanks!

Quoted 10 lines · Danny Al-Gaaf

Attached two patches to fix some compiler warnings.

Danny Al-Gaaf (2):
utime: fix narrowing conversion compiler warning in sleep()
rbd: don't ignore return value of system()

  src/include/utime.h |  2 +-
  src/rbd.cc          | 36 ++++++++++++++++++++++++++++++------
  2 files changed, 31 insertions(+), 7 deletions(-)