Starting OS X and Aqua command line?

zpincus

Registered
I've installed Xfree86 on my system, so at times I log in as >console to use the X system without having to go through a VNC or Xtools intermediate.

I have one question:
If I log in as >console, is there any way to get back to aqua? I'm trying to make a "startaqua" shell script a bit like "startx" but I can't find anywhere (i've looked through all the rc files and other startup files I know of), but I can't figure the order of operations.

Now, this question has a lot more general applicability (than just to Xfree86 users) because of the cool things you could do if you could control the Aqua/Loginwindow startup. Among many other reasons, I've been hunting for configurable aqua startup files ever since i looked at the man pages for loginwindow -- there is a lot of neat stuff you could have that do if you could find the startup script (if any) that launches it from the command line. Like apps/scripts that are executed every time any login or logout happens (customized logging? A better implementation of the "theme per user" idea?) and a lot of other possibly useful stuff. (Provided the out-of-date man page still has valid info.)


So as far as starting aqua de novo :

I know it involves opening (perhaps in this order?):
/System/Library/CoreServices/WindowServer
/System/Library/Frameworks/CoreGraphics.framework/Resources/Window\ Manager
/System/Library/CoreServices/loginwindow.app

so I tried lopgging into console as root and then typing
cd /System/Library/CoreServices/
./WindowServer ; open ./loginwindow.app


This opened the window server and the login window, but pooped out when I tried to login. I then tried to do the same trick but instead of opening the login window, i tried to have it open terminal.app. this did not work at all, and it chewed a few B-tree nodes on my filesystem for my troubles.

I tired to look for the OS X boot scripts that control this part of startup, but /etc/rc was only minimally helpful...

So there would be a lot of cool possibilities if we could find:
1) The scripts that start the window server, window manager, and loginwindow to configure
and 2) How to get back into aqua from a >console login.

Any thoughts?
-zach
 
Wow, that is some pretty interesting stuff. As you say, provided the man page still has valid information.

The man page says that the user running loginwindow is usually root, but ps lists the currently logged-in user as the owner of the loginwindow process. the process id is in line with the process having been started when I logged in (ie. climbing through the thousands as the uptime progresses).

I think the script that calls loginwindow is /etc/ttys. The contents of the file is consistent with what the manpage says, anyway.

Have you tried making a separate user for X sessions, and setting their default Workspace value to your X startup script? The man page mentioned making a user called power with Workspace /sbin/halt, and then you'd have password controlled power-down. Might be generally applicable...
 
Good ideas, scruffy.

I tried to create a new user that would have a non-desktop.app workspace, by creating a user and then su'ing to him and typing:
defaults write loginwindow Workspace /usr/X11R6/bin/startx
defaults write loginwindow workspace /usr/X11R6/bin/startx

(just in case it was case sensitive)

But logging in as the new user did not start X windows. Instead, it just started aqua like normal. I think I have to somehow kill the aqua window server first? I haven't yet tried the shutdown user, but that sounds like a great idea. I like the idea of disabling shutdown, and this solves the one problem with that for me, (if it works).


Update on starting aqua from command line:

cd /System/Library/CoreServices/
./WindowServer ; open ./loginwindow.app

does work, (as root, as long as you don't then try to re-log in as >console.)
The only problem is that when you log out, the system hangs. Maybe because I forgot to specify that when loginwindow exits it should spawn another copy?

Also, I realized that
/System/Library/CoreServices/WindowServer
and
/System/Library/Frameworks/CoreGraphics.framework/Resources/Window\ Manager
are the same. The former is a symlink to the latter.
So aqua is pretty interesting -- the window server and the window manager are rolled into one, unlike X11R6 where you need a separate window manager (like afterstep, or fvwm, etc) to do anything with X.

I am still no closer to altering how X boots up, as I am not convinced that /etc/ttys is actually called. I need to check this, but I think that /etc/rc (which I know to be a boot script that does get called) has no reference to ttys, and in fact calls "SystemStarter" to finish starting. "SystemStarter" is in fact an Aqua app. Try opening it from the terminal. Its sort of funny to see it like that!

So thanks, scruffy. Hopefully people will be interested in this and help us figure out what's going on. I'm especially interested in how other BSD or Mach systems boot -- which I have little knowledge of.

Zach
 
<i> am not convinced that /etc/ttys is actually called. I need to check this, but I think that /etc/rc (which I know to be a boot script that does get called)</i>

To find out, I rebooted, and then immediately logged in and started Teminal.app. My .login script starts with "uptime". This was its output:

10:19PM up 3 mins, 2 users, load averages: 1.88, 1.57, 1.38

Then I checked the last access time of each script:

[poppacrow:~] mark% ls -ul /etc/rc /etc/ttys
-r--r--r-- 1 root wheel 3452 Dec 13 22:17 /etc/rc
-rw-r--r-- 1 root wheel 1663 Dec 13 22:19 /etc/ttys

So it seems that /etc/ttys is run right near the end of the boot process, whereas /etc/rc is run much earlier.
 
Very clever scruffy. You are wise in the ways of ls. I'm sure I'll find a lot of uses for the "last read" bit of data. That's a real nice thing to be able to know. (Too bad the inspector, AFAIK, doesn't do this.)

I still can't get the alternate workspace thing to work right. No matter what the workspace value in the defaults "database" (or, if you prefer, big load of text files) for loginwindow, aqua always starts up.

I have found that just as >console drops you into a console,
>power shuts down the machine and >reboot reboots it. (I think that these are the ones. I don't want to find out right now, but I'll try, and if I'm wrong, modify the post)

Zach
 
Update:
>power and >reboot work, but only if the buttons that do the same are not disabled in the prefs.
It sure would be nice to have password-protected rebooting, though.

Also, thanks AppleWatcher, exit from a Darwin login boots you back to loginwindow.app . Now, my question for anyone who knows: What does the shell do on "exit" ? How are Aqua and Loginwindow invoked?

Is this a feature of some script somewhere? (the logout script in /usr/share/init/tcsh/ doesn't have it...) This is still something I think would be cool to play with, but I just can't figger it out...

Zach
 
Hi,

I really want to help you to "hack" Mac OS X.
But I don't really know how it works with all these scripts
where you are talking about, but I know/think that the command "exit" IS a script, 'cause if you type it, the command "logout" appears. So I think "logout" is really the script, and "exit" only "links" to "logout".


<QUOTE>
It sure would be nice to have password-protected rebooting, though. </QUOTE>

I think this isn't so difficult to make:

-The command "reboot" is a script, of course.
-Find the script
-Change it, so that a windows appears
-I don't really know about the UNIX-language where you make
the scripts in (<B> Learn me PLEASE!!! </B>) but I DO know about other programming languages (VB, Qbasic, Java)

<B> So I think the code should be something like this:

reboot.script

disp window(input), "Password:", "Mac OS X", a
if a = "OK" then
<HERE COMES THE ORIGINAL SCRIPT>
else
window(msg), "Wrong"</B>

So please learn me about the scripts, where they are and
how there work and etc.

I think you think (!) I'm a newbie, but I'm really interested!!!

Thankx,

AppleWatcher
 
And, of course, in loginwindow.app or something,
all the commands like >console and >power and >reboot
are descripted!

AppleWatcher
 
If you are logged in as >console, enter exit and aqua will boot.
it's that easy.
I know that beyond this you are after customizing the bootup sequence (which I am interested in too: who needs most of that networking nonsense anyway), but I haven't seen anyoone write this and it looks to answer your main question.

just type exit.
 
You're not very accurate, Gametes:

<HR>
<I>How you come back from the Darwin to aqua is simply typing <B>"exit"</B></I>

AppleWatcher
<HR>

and here:


<HR>
<I>Also, thanks AppleWatcher, <B>exit</B> from a Darwin login boots you back to loginwindow.app </I>
<HR>

AppleWatcher
 
Gametes -- thanks for the post.
What I'm trying to figure out is the specific way Aqua gets invoked from the Darwin startup process. The fact that it is also re-invoked on typing exit after a >console log in is very interesting. I thought "exit" was a script, but it is not -- typing where exit replies shell builtin or something similar. So is the Aqua startup hard-coded into Apple's tcsh implementation? I find this unlikely.
Bash users -- does an "exit" also return you to Aqua? (Bash was not compiled by Apple as are the others.)

So, does anyone know what happens after a shell exits in UNIX? The logout scripts are empty, so this has to be something after, I think.

For invoking Aqua from startup:
The startup process is script controlled, sort of.
/etc/rc is run, which itself calls /etc/rc.common, and then /etc/rc calls SystemStarter, which seems to be an Aqua app (try from the terminal open -a SystemStarter) but may just forcibly draw istelf on the screen. At any rate, the wierd thing is that neither rc file calls etc/ttys which is run AFTER SystemStarter is (from ls -ul information, thanks Scruffy). Though the Aqua window manager and loginwindow.app seem to be called by /etc/ttys, this is not possible since
1)SystemStarter behaves a lot like an Aqua app, but if etc/ttys is what starts Aqua, Aqua can't be run until the ttys script is, which the SystemStarter itself seems to call on its completion.
2) Anyway, loginwindow and Window Manager are executed before the ttys script is during startup.

Summarry: Mysterys Remaining
Do you think SystemStarter "bootstraps" itself by starting the Window Manager and loginwindow?
Where else might they be called? What about on exiting a shell after a >console Darwin login?
What does /etc/ttys do?

Caveat: This might all be "cleaned up" by apple for X 1.0, and SystemStarter might do everything. While that is probably cleaner, I sure wish apple would leave a way to customize it. (For example, security and the single-user-mode are concerns which editing bootfiles can alleviate. There was some discussion of this on here, on macfixit.com)

Sorry for the numbingly long post.
applewatcher -- there are numerous OS X sites with numerous links to UNIX FAQs. What you have asked me to teach you is a huge body of knowledge that I am just getting comfortable with myself. Please understand that you can and should find things out for yourself when ever possible.

[Edited by zpincus on 12-16-2000 at 06:46 AM]
 
Originally posted by zpincus
So, does anyone know what happens after a shell exits in UNIX? The logout scripts are empty, so this has to be something after, I think.

I suppose /etc/ttys defines "listening sockets" on certain devices (serial lines originally) that spawn the processes listed for a given device when there's a new connection.

Now when you exit from a console login, the listeners for the console device get spawned, which are the loginwindow, window server programs.

This is just like modem connections on a serial line that spawn some program that knows how to communicate with a modem or a teminal login that connects you to a shell.

HTH,
Sven
 
zpincus:

<i>This might all be "cleaned up" by apple for X 1.0, and SystemStarter might do everything.</i>

I remember reading somewhere, afraid I can't recall where anymore, that Apple wanted to move as much of the startup process as possible out of /etc, and into {/System}/Library/StartupItems.

Looking through the string constants in SystemStarter (using less, cat, or more according to taste), it has things like "StartupParameters.plist" and various strings that are found in those plists, to do with startup order, services provided/required, and such. It does not contain the string "/etc". This seems to support your theory.

It also has "Welcome to Macintosh" and "/System/Library/CoreServices/Resources/BootPanel.pdf", which perhaps supports the "it forcibly draws itself on the screen" idea. My understanding is, for a pdf to be displayed, Quartz has to have started, but not Aqua, window manager, etc.

<i>Anyway, loginwindow and Window Manager are executed before the ttys script is during startup.</i>

Hmm. So much for that theory then. Have you checked what gets run, not on reboot, but after logging out and in again, both as >console and as a regular user?
 
Oh, yeah, one other thing.

<i>does anyone know what happens after a shell exits in UNIX?</i>

When you tell a shell to exit, it basically "cleans up after itself" - flushes any buffers, closes opened files, sends a SIGHUP (hangup signal) to any child processes. (The usual reaction is for the child to exit on receiving a HUP). Then it determines whether it was a login shell (ie. one that owned a tty) and if so, runs its logout procedure. I'm not really sure what that involves, other than reading your .logout script. Finally, it exits with an exit status of 0 if all went well, or some non-zero error signal it had problems along the way.

It is not up to the shell to determine whether it's on a tty* or on the console, and decide what should happen then. That's up to the shell's parent process. And, when you're logged onto the console, the parent process is process ID 1, init - the mother of all processes. This applies both to loginwindow's parent process, and to tcsh's when you type >console (try "ps -xO ppid" to check this)

In their rather gappy man page coverage, Apple has included a page for init, and it looks like what we had been saying earlier is about right - whenever the line goes dead (phone hangup / logout ), it runs the second field of the appropriate entry in /etc/ttys. So, when someone logs out of the console (visually or from the >console prompt) it restarts the loginwindow.

In the (known inaccurate) man page for loginwindow, it says that if someone enters ">console", loginwindow exits with status 1. Perhaps this signals init to run the "onoption" field of /etc/ttys?

Here's a possible explanation of the peculiar ordering of last access times for /etc/ttys vs. loginwindow - the console is the first entry. Perhaps then init reads the file one entry at a time, so it reads the first line, runs loinwindow, then reads the next line and runs getty on the next terminal, and so on. Here I really am guessing wildly, so get out your salt shakers.
 
Nice thinking, amadaeus and scruffy. You guys know your stuff. This is starting to make some sense to me, probably in time for Apple to change everything.

I'm at home, harassing my OS X box over ssh, so I can't monkey with the loginwindow hoo-haw too much. I guess the next step when I get back (or for any other intrepid souls) is to start (carefully) knocking holes in these files or strategically changing their calls to see how and when system behavior changes. (Done on a backed-up HD, with a separate drive/partition for 9, with a ssh terminal on another box nearby.)

While I don't know if this sort of experimental approach is condoned in computer science, making "knockouts" is absolutely essential to understanding gene function in biology (my background). So we'll see how far that gets me. For example, the (definitive, scary, stupid?) way to solve the question of whether /etc/ttys calls loginwindow on reboot is to just comment out that call and see what happens on reboot. I am wary of doing this remotely, so that will have to wait.

Thanks to all.
Zach

Applewatcher -- try osxfaq.com, osxhints.com (?), osx areas on macnn and macfixit, and anywhere. a simple google search for "Mac OS X FAQ" will probably be instructive.
 
I am a unix newbie, so I am not sure if this will help, but: you can hold down 'v' durring startup (verbose startup). All it does is go into text mode up until the login window comes up. I am not sure, but it might have some useful information to you.....
Good Luck!
 
Back
Top