Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 528414 (swtWaylandLauncher)

Summary: [Gtk3][Wayland] Launcher segfault under Wayland when openFile is used
Product: [Eclipse Project] Equinox Reporter: Alexander Kurtakov <akurtakov>
Component: LauncherAssignee: Leo Ufimtsev <lufimtse>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P2 CC: aniefer, ericwill, jan.public, joshbarkovic, Lars.Vogel, lufimtse, ma.becker, platform-swt-inbox, sravankumarl
Version: unspecified   
Target Milestone: Photon M5   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/113159
https://bugs.eclipse.org/bugs/show_bug.cgi?id=528926
https://git.eclipse.org/r/114524
https://bugs.eclipse.org/bugs/show_bug.cgi?id=529151
https://git.eclipse.org/r/115203
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=70bc724bdc4e8386426bb111135ed74b336c4fae
https://bugs.eclipse.org/bugs/show_bug.cgi?id=529695
https://git.eclipse.org/r/115336
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=d20833d611fabe3f4a3379e7f84c5548311c7aa2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=525305
https://git.eclipse.org/r/115481
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=c335e1d1f3363d6b3668013e0b9897acb09559d1
https://git.eclipse.org/c/equinox/rt.equinox.framework.git/commit/?id=5282e51a49c640f347e112faa9b2305ff5ed4111
https://bugs.eclipse.org/bugs/show_bug.cgi?id=530012
https://bugs.eclipse.org/bugs/show_bug.cgi?id=530324
https://bugs.eclipse.org/bugs/show_bug.cgi?id=530397
https://bugs.eclipse.org/bugs/show_bug.cgi?id=566133
Whiteboard:
Bug Depends on: 529352, 529781    
Bug Blocks: 525305    
Attachments:
Description Flags
Proof of concept: Open file from command line via gdbus. none

Description Alexander Kurtakov CLA 2017-12-11 07:34:23 EST
Gnome wayland session:
./eclipse --launcher.openFile /home/akurtakov/tasks.txt
Segmentation fault (core dumped

if GDK_BACKEND=x11 it works aka issue visible under wayland only.

If run through gdb the backtrace is:
#0  0x00007fffed78329e in _XInternAtom () at /lib64/libX11.so.6
#1  0x00007fffed78363a in XInternAtom () at /lib64/libX11.so.6
#2  0x00007ffff07f4961 in reuseWorkbench (filePath=0x609c70, timeout=60) at eclipseGtk.c:199
#3  0x00007ffff07f05d2 in _run (argc=1, argv=0x609160, vmArgs=0x0) at ../eclipse.c:538
#4  0x00007ffff07f03ec in run (argc=1, argv=0x609160, vmArgs=0x0) at ../eclipse.c:476
#5  0x000000000040163e in main (argc=10, argv=0x609160) at ../eclipseMain.c:217
Comment 1 Alexander Kurtakov CLA 2017-12-11 07:45:24 EST
Reimplementing around GdkAtom and gdk_property_change looks promising path.
Comment 2 Eclipse Genie CLA 2017-12-11 08:54:10 EST
New Gerrit change created: https://git.eclipse.org/r/113159
Comment 3 Alexander Kurtakov CLA 2017-12-14 02:43:46 EST
Heh, and now gdk_property* and gdk_atom* APIs are gone for gtk4 so we should think of some forward viable solution. See https://git.gnome.org/browse/gtk+/commit/?id=f2bb2024c87dae1ce655154fb5bea0eb07cef48c
Comment 4 Alexander Kurtakov CLA 2017-12-14 06:49:46 EST
Based on comment 3 the approach taken is not viable. So here is a new proposal how to do it:
* SWT registers dbus interface on the session bus (if not registered already) - smth like org.eclipse.swt with single method openFile taking file name as a parameter. When it receives such a message it fires SWT.OpenDocument event. This could be done first and independently of launcher changes and easily tested with smth like d-feet. Ideally the dbus interface registration should happen in separate thread to not slow down swt startup.
* Launcher if passed openFile checks whether the interface exists and if does calls it. If not it should give time of SWT to initialize and calls the method. If it's possible to listen for interface creation somehow (to not do polling) that should be preferred otherwise some timeout period like the one in the launcher currently should be used.
Comment 5 Alexander Kurtakov CLA 2017-12-14 06:51:20 EST
What I like about this proposal is that it will open the possibility for opening files to be delivered by other means not just launcher but anything that does dbus.
Comment 6 Leo Ufimtsev CLA 2017-12-19 16:23:58 EST
Created attachment 271968 [details]
Proof of concept: Open file from command line via gdbus.

With some hacks, as proof of concept, I can open a file (/tmp/test) from the command line via gdbus call and it opens in Eclipse.

The full implementation however will take me a 1-3 weeks probably as I have to do some research and move a fair bit of code around.

But tentativley, looks doable.
Comment 7 Eclipse Genie CLA 2017-12-20 15:58:49 EST
New Gerrit change created: https://git.eclipse.org/r/114519
Comment 8 Leo Ufimtsev CLA 2017-12-20 16:01:34 EST
One thing that I was concerned about is that if it's permissible for one application to have multiple gdbus names. (One for webextension, which needs to be unique, and one that is well-known and always the same for opening files).

I've just tried it with a proof-of-concept, it works:
https://git.eclipse.org/r/#/c/114519/

So I'll work on implementing a general purpose GDBus interface now for fileOpen mechanism.
Comment 9 Eclipse Genie CLA 2017-12-20 19:07:33 EST
New Gerrit change created: https://git.eclipse.org/r/114524
Comment 10 Leo Ufimtsev CLA 2018-01-02 09:38:33 EST
Need to move GDBus native calls out of Webkit into common code.
Reason: GDBus can be used without webkit being initialized.
-> Bug 529151
Comment 11 Alexander Kurtakov CLA 2018-01-02 10:28:02 EST
(In reply to Leo Ufimtsev from comment #10)
> Need to move GDBus native calls out of Webkit into common code.
> Reason: GDBus can be used without webkit being initialized.
> -> Bug 529151

It's an actual bug that the gdbus bindings are not in OS. As GTK 2.24 requires glib 2.28+ there is no need for these g_* bindinds to be dynamic so this bug  is not really a dependency AFAICT and the binding can be moved directly.
Comment 12 Leo Ufimtsev CLA 2018-01-02 11:08:12 EST
(In reply to Alexander Kurtakov from comment #11)
> (In reply to Leo Ufimtsev from comment #10)
> > Need to move GDBus native calls out of Webkit into common code.
> > Reason: GDBus can be used without webkit being initialized.
> > -> Bug 529151
> 
> It's an actual bug that the gdbus bindings are not in OS. As GTK 2.24
> requires glib 2.28+ there is no need for these g_* bindinds to be dynamic so
> this bug  is not really a dependency AFAICT and the binding can be moved
> directly.

It would be time consuming to move things to OS.java and then to GTK.java.
Comment 13 Alexander Kurtakov CLA 2018-01-02 11:16:28 EST
(In reply to Leo Ufimtsev from comment #12)
> (In reply to Alexander Kurtakov from comment #11)
> > (In reply to Leo Ufimtsev from comment #10)
> > > Need to move GDBus native calls out of Webkit into common code.
> > > Reason: GDBus can be used without webkit being initialized.
> > > -> Bug 529151
> > 
> > It's an actual bug that the gdbus bindings are not in OS. As GTK 2.24
> > requires glib 2.28+ there is no need for these g_* bindinds to be dynamic so
> > this bug  is not really a dependency AFAICT and the binding can be moved
> > directly.
> 
> It would be time consuming to move things to OS.java and then to GTK.java.

As long as there is a crasher and unsolved question(verifying lib*.so loading) for moving to GTK.java I would go with time consuming and not crashing app.
Comment 14 Leo Ufimtsev CLA 2018-01-02 17:19:13 EST
(In reply to Alexander Kurtakov from comment #13)
> (In reply to Leo Ufimtsev from comment #12)
> > (In reply to Alexander Kurtakov from comment #11)
> > > (In reply to Leo Ufimtsev from comment #10)
> > > > Need to move GDBus native calls out of Webkit into common code.
> > > > Reason: GDBus can be used without webkit being initialized.
> > > > -> Bug 529151
> > > 
> > > It's an actual bug that the gdbus bindings are not in OS. As GTK 2.24
> > > requires glib 2.28+ there is no need for these g_* bindinds to be dynamic so
> > > this bug  is not really a dependency AFAICT and the binding can be moved
> > > directly.
> > 
> > It would be time consuming to move things to OS.java and then to GTK.java.
> 
> As long as there is a crasher and unsolved question(verifying lib*.so
> loading) for moving to GTK.java I would go with time consuming and not
> crashing app.

Yes, I agree, fixing crasher is top priority. I think if there is time I can make the gdbus calls static afterwards. For now the fastest thing to do is just leave them dynamic and move them over.

See WIP:
https://git.eclipse.org/r/#/c/114524/

It depends on the previous two patches to be merged first.
Comment 15 Eclipse Genie CLA 2018-01-10 17:21:29 EST
New Gerrit change created: https://git.eclipse.org/r/115203
Comment 17 Eclipse Genie CLA 2018-01-12 17:20:40 EST
New Gerrit change created: https://git.eclipse.org/r/115336
Comment 18 Alexander Kurtakov CLA 2018-01-16 02:23:05 EST
*** Bug 316821 has been marked as a duplicate of this bug. ***
Comment 20 Eclipse Genie CLA 2018-01-16 16:48:12 EST
New Gerrit change created: https://git.eclipse.org/r/115481
Comment 23 Leo Ufimtsev CLA 2018-01-19 13:13:47 EST
Verified GDBus implementation with /I20180119-0110/ on Fedora27 (gtk3.22) and RHEL 7.4 (gtk3.22).

1) Open file when eclipse is already running:
./eclipse
....
./eclipse testFile

2) Open eclipse with file.
./eclipse testFile

Also tested on Gtk.2.24.31  (with SWT_GTK3=0). Works on gtk2 as well.

Works well.

There is a still a bit of clean-up work to do on this bug, but major functionality is in place.
Comment 24 Leo Ufimtsev CLA 2018-01-23 15:02:21 EST
Fixed and verified with today's build on Gtk3.22, Cocoa, Win10.
Build #339 (Jan 23, 2018 10:14:17 AM)
Comment 25 Eric Williams CLA 2018-05-11 14:27:35 EDT
*** Bug 441818 has been marked as a duplicate of this bug. ***