Discussion:
Start X11 automatically when launching programs from Terminal
Leo Singer
2013-05-17 01:46:12 UTC
Permalink
Hi,

On Mountain Lion, how do you configure X11 (provided by MacPorts' xorg port) to start automatically as needed? When I am Terminal.app, if I run 'xclock', I just get:

Error: Can't open display:

It works fine if I open /Applications/MacPorts/X11.app, then open an xterm window, and then run 'xclock' from there.

Thanks,
Leo Singer
Graduate Student @ LIGO-Caltech
Lawrence Velázquez
2013-05-17 02:05:54 UTC
Permalink
Post by Leo Singer
It works fine if I open /Applications/MacPorts/X11.app, then open an xterm window, and then run 'xclock' from there.
Did you load the xorg-server LaunchAgent, then log out and back in?

% launchctl load -w /Library/LaunchAgents/org.macports.startx.plist

Yeah, the xinit install tells you to do this. Very briefly. If you're paying attention.

http://trac.macports.org/browser/trunk/dports/x11/xinit/Portfile#L82

vq
Lawrence Velázquez
2013-05-17 02:07:25 UTC
Permalink
Post by Lawrence Velázquez
Did you load the xorg-server LaunchAgent
Er, I guess it's technically xinit's LaunchAgent.

vq
Leo Singer
2013-05-17 02:11:27 UTC
Permalink
Post by Lawrence Velázquez
Post by Leo Singer
It works fine if I open /Applications/MacPorts/X11.app, then open an xterm window, and then run 'xclock' from there.
Did you load the xorg-server LaunchAgent, then log out and back in?
% launchctl load -w /Library/LaunchAgents/org.macports.startx.plist
Thanks, that worked!
Post by Lawrence Velázquez
Yeah, the xinit install tells you to do this. Very briefly. If you're paying attention.
http://trac.macports.org/browser/trunk/dports/x11/xinit/Portfile#L82
Indeed. I never noticed that message.

Could you add a startupitem so that you can load/unload X11 with 'port (un)load) xinit'?

Thanks,
Leo
Lawrence Velázquez
2013-05-17 02:55:23 UTC
Permalink
Post by Leo Singer
Could you add a startupitem so that you can load/unload X11 with 'port (un)load) xinit'?
Jeremy's the authority, of course, but I'm not sure how this would work. There are two launchd items involved with xinit:

- /Library/LaunchDaemons/org.macports.privileged_startx.plist
- /Library/LaunchAgents/org.macports.startx.plist

Which one would "port load" affect? Only one of these is a daemon, but it's probably not the one you're thinking of flipping the switch for.

vq
Leo Singer
2013-05-17 03:00:08 UTC
Permalink
Post by Lawrence Velázquez
Post by Leo Singer
Could you add a startupitem so that you can load/unload X11 with 'port (un)load) xinit'?
- /Library/LaunchDaemons/org.macports.privileged_startx.plist
- /Library/LaunchAgents/org.macports.startx.plist
Which one would "port load" affect? Only one of these is a daemon, but it's probably not the one you're thinking of flipping the switch for.
I don't know how they differ. I do notice that there is the line:

system "launchctl load /Library/LaunchDaemons/org.macports.privileged_startx.plist"

in the port's post-activate stage. What does that do? Could the port also do:

system "launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"

?

Leo
Ryan Schmidt
2013-05-17 03:12:28 UTC
Permalink
Post by Leo Singer
system "launchctl load /Library/LaunchDaemons/org.macports.privileged_startx.plist"
system "launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
?
No it couldn't because launchagents are per-user processes launched at login, whereas launchdaemons are pre-computer processes launched at system startup. Each user needs to start the launchagents themselves if they want them.
Leo Singer
2013-05-17 03:45:35 UTC
Permalink
Post by Ryan Schmidt
Post by Leo Singer
system "launchctl load /Library/LaunchDaemons/org.macports.privileged_startx.plist"
system "launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
?
No it couldn't because launchagents are per-user processes launched at login, whereas launchdaemons are pre-computer processes launched at system startup. Each user needs to start the launchagents themselves if they want them.
Ah... which is why this can't be done with 'port load' either, because 'port load' handles launchdaemons.

Is it really just the patchfile https://trac.macports.org/browser/trunk/dports/x11/xinit/files/disable-launchagent.patch that disables on-demand loading of X11.app by default?

Leo
Leo Singer
2013-05-17 04:33:07 UTC
Permalink
Post by Leo Singer
Post by Ryan Schmidt
Post by Leo Singer
system "launchctl load /Library/LaunchDaemons/org.macports.privileged_startx.plist"
system "launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
?
No it couldn't because launchagents are per-user processes launched at login, whereas launchdaemons are pre-computer processes launched at system startup. Each user needs to start the launchagents themselves if they want them.
Ah... which is why this can't be done with 'port load' either, because 'port load' handles launchdaemons.
Is it really just the patchfile https://trac.macports.org/browser/trunk/dports/x11/xinit/files/disable-launchagent.patch that disables on-demand loading of X11.app by default?
Yes.
This approach was taken because X11.app shipped before some Snow Leopard 10.6.3 would not work correctly if $DISPLAY belonged to another server. This is also why the XQuartz package requires 10.6.3 to install.
It might be worth revisiting this and perhaps just disabling it on Leopard.
Yes, please! It would be really nice if the MacPorts X11.app started automatically on Mountain Lion, without any further user intervention.
Ryan Schmidt
2013-05-17 04:59:17 UTC
Permalink
Post by Leo Singer
Post by Leo Singer
Is it really just the patchfile https://trac.macports.org/browser/trunk/dports/x11/xinit/files/disable-launchagent.patch that disables on-demand loading of X11.app by default?
Yes.
This approach was taken because X11.app shipped before some Snow Leopard 10.6.3 would not work correctly if $DISPLAY belonged to another server. This is also why the XQuartz package requires 10.6.3 to install.
It might be worth revisiting this and perhaps just disabling it on Leopard.
Yes, please! It would be really nice if the MacPorts X11.app started automatically on Mountain Lion, without any further user intervention.
I would rather work on the proposed extension of MacPorts startupitems to let a port auto-load them; this would be useful for xorg-server, certsync, dbus, etc.

https://trac.macports.org/ticket/35474#comment:15
Leo Singer
2013-05-17 05:03:24 UTC
Permalink
Post by Ryan Schmidt
Post by Leo Singer
Post by Leo Singer
Is it really just the patchfile https://trac.macports.org/browser/trunk/dports/x11/xinit/files/disable-launchagent.patch that disables on-demand loading of X11.app by default?
Yes.
This approach was taken because X11.app shipped before some Snow Leopard 10.6.3 would not work correctly if $DISPLAY belonged to another server. This is also why the XQuartz package requires 10.6.3 to install.
It might be worth revisiting this and perhaps just disabling it on Leopard.
Yes, please! It would be really nice if the MacPorts X11.app started automatically on Mountain Lion, without any further user intervention.
I would rather work on the proposed extension of MacPorts startupitems to let a port auto-load them; this would be useful for xorg-server, certsync, dbus, etc.
https://trac.macports.org/ticket/35474#comment:15
I agree that there should be an option to auto-load LaunchDaemons that are wrapped by startupitems, but I also think that the LaunchAgent should be on by default. They are separate issues. The startupitem handles the LaunchDaemon, not the LaunchAgent.
Ryan Schmidt
2013-05-17 05:09:21 UTC
Permalink
Post by Leo Singer
Post by Ryan Schmidt
Post by Leo Singer
Yes, please! It would be really nice if the MacPorts X11.app started automatically on Mountain Lion, without any further user intervention.
I would rather work on the proposed extension of MacPorts startupitems to let a port auto-load them; this would be useful for xorg-server, certsync, dbus, etc.
https://trac.macports.org/ticket/35474#comment:15
I agree that there should be an option to auto-load LaunchDaemons that are wrapped by startupitems, but I also think that the LaunchAgent should be on by default. They are separate issues. The startupitem handles the LaunchDaemon, not the LaunchAgent.
…you're right; I spaced.

dbus also has a launchagent that could benefit from this (and a launchdaemon that could benefit from the other thing).
Lawrence Velázquez
2013-05-17 05:40:11 UTC
Permalink
Post by Leo Singer
Post by Leo Singer
Is it really just the patchfile https://trac.macports.org/browser/trunk/dports/x11/xinit/files/disable-launchagent.patch that disables on-demand loading of X11.app by default?
Yes.
This approach was taken because X11.app shipped before some Snow Leopard 10.6.3 would not work correctly if $DISPLAY belonged to another server. This is also why the XQuartz package requires 10.6.3 to install.
It might be worth revisiting this and perhaps just disabling it on Leopard.
Yes, please! It would be really nice if the MacPorts X11.app started automatically on Mountain Lion, without any further user intervention.
If we remove that patch, which user would the LaunchAgent end up being active for?

vq
Leo Singer
2013-05-17 05:53:58 UTC
Permalink
Post by Lawrence Velázquez
Post by Leo Singer
Post by Leo Singer
Is it really just the patchfile https://trac.macports.org/browser/trunk/dports/x11/xinit/files/disable-launchagent.patch that disables on-demand loading of X11.app by default?
Yes.
This approach was taken because X11.app shipped before some Snow Leopard 10.6.3 would not work correctly if $DISPLAY belonged to another server. This is also why the XQuartz package requires 10.6.3 to install.
It might be worth revisiting this and perhaps just disabling it on Leopard.
Yes, please! It would be really nice if the MacPorts X11.app started automatically on Mountain Lion, without any further user intervention.
If we remove that patch, which user would the LaunchAgent end up being active for?
It would become enabled by default for all users. After installing xorg, users logging back in would find it enabled, and it would stay enabled until they <launchctl unload -w>'d it.

See <https://trac.macports.org/ticket/39129>.

Leo
Lawrence Velázquez
2013-05-17 13:28:06 UTC
Permalink
Post by Leo Singer
Post by Lawrence Velázquez
If we remove that patch, which user would the LaunchAgent end up being active for?
It would become enabled by default for all users.
So, it would theoretically be possible for User A to log out and back in and find that their X11 has changed (perhaps they were using XQuartz) because User B had in the meantime installed xorg-server (which I know is the same, it's a thought experiment)? Or am I missing something? That doesn't seem like a situation we want to enable.

vq
Ryan Schmidt
2013-05-17 21:10:50 UTC
Permalink
Post by Lawrence Velázquez
Post by Leo Singer
Post by Lawrence Velázquez
If we remove that patch, which user would the LaunchAgent end up being active for?
It would become enabled by default for all users.
So, it would theoretically be possible for User A to log out and back in and find that their X11 has changed (perhaps they were using XQuartz) because User B had in the meantime installed xorg-server (which I know is the same, it's a thought experiment)? Or am I missing something? That doesn't seem like a situation we want to enable.
It's been done:

https://trac.macports.org/changeset/106166

It doesn't seem so objectionable to me. Anyone who has permission to run `sudo` is an administrator, who by definition is the one who makes decisions about what software to use on the computer.
Jeremy Huddleston Sequoia
2013-05-17 04:24:40 UTC
Permalink
Post by Leo Singer
Post by Lawrence Velázquez
Post by Leo Singer
Could you add a startupitem so that you can load/unload X11 with 'port (un)load) xinit'?
What is it that you wish to accomplish with this?
Post by Leo Singer
Post by Lawrence Velázquez
- /Library/LaunchDaemons/org.macports.privileged_startx.plist
- /Library/LaunchAgents/org.macports.startx.plist
Which one would "port load" affect? Only one of these is a daemon, but it's probably not the one you're thinking of flipping the switch for.
system "launchctl load /Library/LaunchDaemons/org.macports.privileged_startx.plist"
in the port's post-activate stage. What does that do?
It loads the org.macports.privileged_startx daemon into the system launchd bootstrap (which will normally happen at boot after this point).
Post by Leo Singer
system "launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
That's what the xinit port tells you to do if you want MacPorts' X11.app to be default. I see no reason to force that in the portfile.
Ryan Schmidt
2013-05-17 05:02:28 UTC
Permalink
Post by Jeremy Huddleston Sequoia
Post by Leo Singer
system "launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
That's what the xinit port tells you to do if you want MacPorts' X11.app to be default. I see no reason to force that in the portfile.
I see no *mechanism* in MacPorts today by which we could force it in the portfile. LaunchAgents need to be started per-user, and MacPorts doesn't have permission to modify user-owned files; user settings are things MacPorts has historically left to the user to implement themselves (with the notable exception of the one-time setup of the user's shell profile at MacPorts installation time).
Alejandro Imass
2013-05-17 02:12:37 UTC
Permalink
Post by Leo Singer
Hi,
It works fine if I open /Applications/MacPorts/X11.app, then open an xterm window, and then run 'xclock' from there.
Strange because I've been using X11 apps for years and they always
launch X11 automatically.

I'm currently running on OS X 10.7.5
--
Alejandro Imass
Lawrence Velázquez
2013-05-17 02:30:01 UTC
Permalink
Post by Alejandro Imass
Strange because I've been using X11 apps for years and they always
launch X11 automatically.
I'm currently running on OS X 10.7.5
Not strange at all. I think the installer for XQuartz (and for Apple's X11.app, before they stopped shipping it) automatically takes care of the DISPLAY business for you, but the xorg-server port does not.

vq
Alejandro Imass
2013-05-17 03:57:20 UTC
Permalink
On Thu, May 16, 2013 at 10:30 PM, Lawrence Velázquez
Post by Lawrence Velázquez
Post by Alejandro Imass
Strange because I've been using X11 apps for years and they always
launch X11 automatically.
I'm currently running on OS X 10.7.5
Not strange at all. I think the installer for XQuartz (and for Apple's X11.app, before they stopped shipping it) automatically takes care of the DISPLAY business for you, but the xorg-server port does not.
I see. So they will probably break when I upgrade ? - good thing I
read the thread
Thanks for the heads up ;-)
--
Alejandro Imass
Post by Lawrence Velázquez
vq
Ryan Schmidt
2013-05-17 04:02:10 UTC
Permalink
Post by Alejandro Imass
Post by Lawrence Velázquez
Not strange at all. I think the installer for XQuartz (and for Apple's X11.app, before they stopped shipping it) automatically takes care of the DISPLAY business for you, but the xorg-server port does not.
I see. So they will probably break when I upgrade ? - good thing I
read the thread
It shouldn't break when you upgrade… Does it seem like it will?
Alejandro Imass
2013-05-17 04:06:07 UTC
Permalink
Post by Ryan Schmidt
Post by Alejandro Imass
Post by Lawrence Velázquez
Not strange at all. I think the installer for XQuartz (and for Apple's X11.app, before they stopped shipping it) automatically takes care of the DISPLAY business for you, but the xorg-server port does not.
I see. So they will probably break when I upgrade ? - good thing I
read the thread
It shouldn't break when you upgrade… Does it seem like it will?
Don't really know but if they do I'll know why. I'll just have to wait
and see...

Best,
--
Alejandro Imass
Loading...