Page MenuHomePhabricator

xdg-open Writes To Previous Instance
Closed, InvalidPublic

Description

I used xdg-mime to set new defaults for terminology links. Yet they are not working properly.

When you change a default setting using xdg-mime. It works fine from the commandline using xdg-open but if you click the link in terminology seemingly nothing happens.

Eg.

$> cd /tmp; ls > testfile.txt; xdg-mime query filetype /tmp/testfile.txt
text/plain 
$> xdg-mime query default text/plain 
geany.desktop 
$> var=$(cat<<EOF
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=true
Exec=/bin/more %F
Name=more
Icon=more
MimeType=text/plain;
EOF
)
$> echo "$var" > ~/.local/share/applications/more.desktop  
$> xdg-mime default more.desktop text/plain 
$> xdg-mime query default text/plain 
more.desktop 
$> readlink -f /tmp/testfile.txt 
/tmp/testfile.txt 
<click on /tmp/testfile> <nothing happens> 

But if you open a new terminology: 
$> terminology & 
$> readlink -f /tmp/testfile.txt 
<click on /tmp/testfile> 

It outputs the testfile using more except not in this new terminology window, instead it writes it 
to the previous terminology instance.

Using xdg-open works fine. I have tried rebooting, no change.

Terminology Version: 1.3.2
Distributor ID: Ubuntu
Description: Ubuntu 19.04
Release: 19.04
Codename: disco

AdamDanischewski updated the task description. (Show Details)
AdamDanischewski updated the task description. (Show Details)
billiob claimed this task.

Your bug report is great! Thanks.
I can reproduce your issue but I don't know how to fix it yet.

billiob closed this task as Wontfix.Oct 28 2019, 2:45 PM

Ok, I understood what is going on!
When you run xdg-open in your shell, it spawns more that write to its standard output… your shell.
When Terminology starts xdg-open, it's not spawning it inside the shell (and it can't do it), but as a child. When `more' write to its standard output, it writes to Terminology's output (they use the same file descriptor), which is actually printed by the parent program: the shell that started Terminology.

Hi Billiob, thanks for replying. I realize that children inherit the parent's fd's but Terminology obviously has somewhere the fd's to write to the Terminology terminal since that's what it normally does. Maybe within the Ecore_Fd_Handler?

To not have this functionality really hampers the utility of Terminology. Since there are many use case scenarios where you don't want an external program, you simply want to click a link to: cat, more or less a file.
In termpty.c lines 697-699:

dup2(ty->slavefd, 0);
dup2(ty->slavefd, 1);
dup2(ty->slavefd, 2);

If you dup the fd onto 0,1,2 then call a shell script like xdg-open then it will have those fd's, no?

billiob reopened this task as Open.Nov 4 2019, 11:35 AM

So, I did give your thoughts a chance and a bit of hacking (See https://github.com/billiob/terminology/commit/3892e3eb87be33809f0df5d64a167aca8b9ebaa5 ).
I won't finish that as I consider it to be too difficult/impossible to do it correctly.
1/ It is not writing to the terminal's fd as that would create a security issue.
2/ It is only writing text to the terminal, but that might create issues because it moves the cursor and writes stuff that the application underneath does not know about.

billiob closed this task as Invalid.Nov 4 2019, 2:32 PM