|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
preventing abort on "package require Tk"This has vexed me for some time, and we're a ways behind on Tcl/Tk revisions so perhaps it's fixed already in a different way, but I finally found a workable solution for us, and thought I would share. Problem: If you have an Aqua build of Tk and attempt to load it dynamically using "package require Tk" (or Tcl_PkgRequire), and you are not logged in at the console, then the require doesn't just fail and return an error, but causes the application to terminate with SIGABRT. After much digging, I found that you can use SessionGetInfo() from the Security framework to determine if a GUI environment was available, and it also seems to work for detecting both Aqua and X11: #include <Security/AuthSession.h> OSStatus error; SecuritySessionId mySession; SessionAttributeBits sessionInfo; error = SessionGetInfo(callerSecuritySession, &mySession, &sessionInfo); Need to link with -framework Security. If successful, sessionInfo will have sessionHasGraphicAccess set if the user is logged into the console. It also appears to be set if you're logged in remotely via ssh and tunneling to a local X server yet not logged into the console, but for Tk's purposes it probably only needs to be checked in the Aqua TkpInit (where, if it's not set, it would return TCL_ERROR). Source: http://developer.apple.com/documentation/MacOSX/Conceptual/BPMultipleUsers/Concepts/FastUserSwitching.html [Though that page has the wrong header file in the snippet and I found the flag while digging through the headers.] Caveat: Assuming you are logged in at the console (or are root), without this check it's possible to log into the machine remotely via ssh, run wish (or tclsh and require Tk) and the Tk GUI will be sent to the console. I find that the bit is NOT set if you are logged in remotely via ssh and not able to tunnel X to a local X server, even if you are logged in at the console, so using this check you can't remotely send windows to the console. Whether the ability to do so without the check would be considered a feature or not, I can't say, but maybe to preserve that ability while still allowing developers to catch Tk failing to load (due to no console -or- X) could be done with a flag in the env or tcl_platform arrays. -- Michael Kirkham President & CEO Muonics, Inc. http://www.muonics.com/ ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ Tcl-mac mailing list tcl-mac@... https://lists.sourceforge.net/lists/listinfo/tcl-mac |
| Free Forum Powered by Nabble | Forum Help |