[SOLVED] View the commands that run from right-click menu

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks, acerimusdux

I began this thread because I wanted to know what does Caja to safely remove, eject or extract an USB flash drive, after asking for it from the right-click context menu. But I made the thread more general, so me & any other person interested can know the command(s) that Caja calls, runs or executes when we click on any option of the right-click menu. And I'm still with that objective ... (yes, I like to learn & understand things, I'm curious ... something very human, not?). OK ...

1. Looking at external signs

* top: you have to be quick to see things here ... I've used screenshots to help me ... I've seen that just after clicking on "Safely Remove Drive" udisksd appears. This is not a command, but could be the abbreviation of udisks --detach . But no umount appears in the screenshots as it should (if udisksd stands for udisks --detach). Perhaps umount does appear in top but disappears too quick ...

* lastcomm| tail -50: [to install it you have to run sudo apt-get install acct]. just after clicking on "Safely Remove Drive" several umount appear, but no udisksd nor udisks --detach . Nevertheless several udisks-part-id appear, that could mean udisks --detach (they also appear after plugging the USB flash drive: in that case they could mean udisks --mount ).

In summary: as no eject appears after running these 2 commands, and according to what has been found, it seems that Caja runs umount first and udisks --detach later to safely remove the USB flash drives.

[As I said "strace caja" doesn't work here]

2. Looking at the origin

With mate-search-tool , using the option "Contains the text" with "FM_ACTION_EJECT_VOLUME" only 2 occurrences appear: one in /path/of/caja-1.8.1/src/file-manager/fm-actions.h (definition ot the action) and another in /path/of/caja-1.8.1/src/file-manager/fm-directory-view.c , from where the action is called. But if I search the text "udisks" 0 occurences appear (umount only appears in 3 translation files)!!??

Can somebody help to trace "FM_ACTION_EJECT_VOLUME" to umount + udisks --detach or the libraries that they use, please?

Regards
altair4
Level 20
Level 20
Posts: 11454
Joined: Tue Feb 03, 2009 10:27 am

Re: View the commands that run from right-click menu

Post by altair4 »

Why not ask the source: http://forums.mate-desktop.org/
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Buzzsaw
Level 6
Level 6
Posts: 1318
Joined: Sat Aug 23, 2014 12:53 pm

Re: View the commands that run from right-click menu

Post by Buzzsaw »

I began this thread because I wanted to know what does Caja to safely remove, eject or extract an USB flash drive, after asking for it from the right-click context menu.
Ahh well that's an easy one. You should have said this at the start and I would have told you:

(Probably) all Linux file mangers use the udisks system daemon, 'udisksd' for mounting/unmounting and possibly for all of the 'safely remove' process too. This is what the 'udisksd' you see in top refers to. It even has a man page:

Code: Select all

man udisksd
Using udisksd enables file managers to mount/unmount volumes without needing to ask for the root password.

If you want a command line equivalent, the closest thing to it is:

Code: Select all

udisksctl power-off /dev/sdx
I advise against using 'udisks --detach /dev/sdx' because udisksctl has superseded udisks, and it doesn't seem to work anyway. I once tried to safely remove an external drive with 'udisks --detach /dev/sdb', and all it did was power off the drive and then immediately power it on again before I had a chance to unplug it.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks, Buzzsaw

The correct command is like this:

Code: Select all

udisksctl power-off --block-device /dev/sdc
Before you have to unmount the partitions of the drive, like this:

Code: Select all

umount /dev/sdc1
umount /dev/sdc2
umount /dev/sdc3
or

Code: Select all

udisksctl unmount --block-device /dev/sdc1
udisksctl unmount --block-device /dev/sdc2
udisksctl unmount --block-device /dev/sdc3
But using mate-search-tool with the source code of Caja, using the option "Contains the text" with "udisksd" 0 occurrences appear. The same searching with "udisksctl". How is this possible?
Buzzsaw
Level 6
Level 6
Posts: 1318
Joined: Sat Aug 23, 2014 12:53 pm

Re: View the commands that run from right-click menu

Post by Buzzsaw »

Before you have to unmount the partitions of the drive
Are you sure? According to the udisksctl man page:
['power-off'] includes ensuring that no process is using the drive, then requesting that in-flight buffers and caches are committed to stable storage...
This wouldn't be possible if the drive were first unmounted, since the buffers/caches would already be cleared.
But using mate-search-tool with the source code of Caja, using the option "Contains the text" with "udisksd" 0 occurrences appear. The same searching with "udisksctl". How is this possible?
It possibly refers to udisksd by its process ID, or some other method. I'm not an expert in this department, so I might be wrong.
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

Thanks, Buzzsaw

If I run ...

Code: Select all

udisksctl power-off --block-device /dev/sdc
... before umounting I get ...

Code: Select all

Error powering off drive: The drive in use: Device /dev/sdc3 is mounted (udisks-error-quark, 14)
Until I unmount all the partitions of the drive I can't safely extract or remove it with that command.

I think that one command can have different process IDs. I think that these numbers are given randomly (or ...) when it's required. So ...

Where/how in the source code of Caja appear "udisksd", "udisksctl" or something related to them, please?
biluluki

Re: View the commands that run from right-click menu

Post by biluluki »

In MATE the applications seem to communicate between them using D-Bus: http://wiki.mate-desktop.org/matecorba_to_dbus . So this powerfull tool seems to make unnecessary commands (like udisks, or daemons like udisksd) to be in the source code (of Caja in this case).

This thread could be considered [SOLVED], in the end!!

Thanks to everybody!!
User avatar
joe_evans
Level 1
Level 1
Posts: 4
Joined: Sat Oct 13, 2012 10:16 am

Re: Re: View the commands that run from right-click menu

Post by joe_evans »

Dngrsone wrote:
I use Linux Mint 17 MATE. But in the preferences of the Caja file manager I see no way to customize the right-click context menu.

Any ideas?

1/ Add an executable script with your command(s) in and place it in /home/<username>/.config/caja/scripts
2/ Caja context-menu will now have an extra line in right-click-actions called Scripts.
3/ Follow this through and you will find your script that you have just written.

H.I.H. Joe
J.Evans

as@ May2022 - LM 19.3 Tricia, Cinnamon & Mate Ubuntu-Bionic
Locked

Return to “Other topics”