On 21.03.2017 03:25, Wang Dong wrote: [snip] > Thanks for your reply. > > Yeah, I have read the parted.c as you pointed. The switch here is > */opt_script_mode. > /*But it is a static one/*, *and /libparted is dynamic lib. / > /*/ > /*Actually, I got a scenario in which I need to distinguish the modes and > print different messages to user. But it is disk label related. So it > cannot > be implemented in the front end.*/ > /* > It is an exception, in which I would like to give a interactive question > in interactive mode > and a message in script mode. Well this looks like a feature in the > front end. > > I read the code about the initialization of exception handler. > And all the exception output is redirected to the stderr. > Is there any way to check this, may I ask this?*/
The method of choice is splitting functionality so that a certain error code is returned by a libparted function and the front-end reacts on that return code accordingly by throwing the exception from there. Good examples are: _disk_warn_busy() calling ped_device_is_busy() and _partition_warn_busy() calling ped_partition_is_busy(). ped_exception_throw() is used all over the place. There are yes/no exceptions (PED_EXCEPTION_YES_NO), yes/no/cancel exceptions (PED_EXCEPTION_YES_NO_CANCEL), PED_EXCEPTION_RETRY_CANCEL, PED_EXCEPTION_IGNORE_CANCEL, ... See: include/parted/exception.h If your stuff is disk label related, then you likely need to change do_mklabel(). Cheers, Sebastian

