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 (&current_dev);
                 putchar ('\n');
         }



What are your suggestions?
--
Rakesh Pandit

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to