[parted-devel] [PATCH] fix for 'parted --list' option -- does not	generate an exception in non superuser mode
    Rakesh Pandit 
    rakesh.pandit at gmail.com
       
    Wed Apr  9 16:15:00 UTC 2008
    
    
  
Hello All,
  I used 'parted -l' in non-superuser mode and it responded back with
no message. Was skimming through the code base and looked at other
functionality to check what should be the response.
'parted' alone gives :
WARNING: You are not superuser.  Watch out for permissions.
Error: No device found
Retry/Cancel?
So, essentially parted -l should also give same message if we run it
in non super user mode and if it does not have permission to open disk
as in my system.
To me best solution looked this small patch:
diff --git a/parted/parted.c b/parted/parted.c
index 46999f5..be66620 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1566,9 +1566,26 @@ _print_list ()
 {
         PedDevice *current_dev = NULL;
-        ped_device_probe_all();
+#ifdef HAVE_GETUID
+        if (getuid() != 0 && !opt_script_mode) {
+                puts (_("WARNING: You are not superuser.  Watch out for "
+                        "permissions."));
+        }
+#endif
+
+retry:
+        ped_device_probe_all ();
+        current_dev = ped_device_get_next (NULL);
+
+        if (!current_dev) {
+                if (ped_exception_throw (PED_EXCEPTION_ERROR,
+                        PED_EXCEPTION_RETRY_CANCEL,
+                        _("No device found"))
+                                == PED_EXCEPTION_RETRY)
+                        goto retry;
+	}
-        while ((current_dev = ped_device_get_next(current_dev))) {
+        while (current_dev) {
                 do_print (¤t_dev);
                 putchar ('\n');
         }
What are your suggestions?
--
Rakesh Pandit
    
    
More information about the parted-devel
mailing list