/*
The compilation of software known as FreeBSD GraphicBoot is distributed under
the following terms:
Copyright (C) 2005 Matthew Holder. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
$SixXGate: motifapps/graphicboot/graphicboot.c,v 1.7 2005/08/11 07:43:15 matthew Exp $
*/
#define _GRAPHICBOOT_C_1700E96A_FE1A_11D9_A94B_0050FC0DCA2A
#include "graphicboot.h"
XmString szGeneric;
static char *fallbackResources[] = {
"*EnableThinThickness: True",
"*XmText.highlightThickness: 0"
};
/**
* Startup
*/
int main(int argc, char *argv[])
{
long nFailTime;
int nWidth, nHeight;
Display *pDpy = NULL;
Screen *AppScreen = NULL;
XtAppContext xtAppContext;
Arg args[20]; Cardinal n;
Widget wndBoot, frmBoot;
nPTYFile = -1; nTTYFile = -1;
nServer = -1; nClient = -1;
szStatus[0] = 0; szPrev[0] = 0;
/*
Since this program is designed to startup before an actual X
server has been started, we will first try to start X, then
attempt to connect to the server.
*/
system("/etc/Xboot/Xserver vt12 -quiet -config /etc/Xboot/xorg.conf -dpms -terminate -nolisten tcp > /dev/null&");
nFailTime = time(NULL) + CONNECT_TIMEOUT;
/* Only str to connect for so long then give up */
setenv("DISPLAY", ":0.0", TRUE);
while(time(NULL) < nFailTime)
{
pDpy = XOpenDisplay(NULL);
if (pDpy != NULL) break;
}
if (pDpy == NULL)
{
printf("graphicboot: Unable to connect to X server\n");
exit(0);
}
system(XSETROOT " -solid \"#0A246A\" -cursor_name watch");
system(XLOADIMAGE " -onroot /etc/Xboot/Xsplash.jpg > /dev/null");
system(XRDB " /etc/Xboot/Xresources > /dev/null");
wndBoot = XtVaOpenApplication
(
&xtAppContext, "FreeBSDGraphicBoot", (XrmOptionDescList)NULL, 0,
&argc, argv, fallbackResources, applicationShellWidgetClass, NULL
);
AppScreen = XtScreen(wndBoot);
nWidth = XWidthOfScreen(AppScreen);
nHeight = XHeightOfScreen(AppScreen);
XtMoveWidget(wndBoot, 0, nHeight / 2);
XtResizeWidget(wndBoot, nWidth, nHeight / 2, 0);
n = 0;
XtSetArg(args[n], XmNmarginHeight, 7); n++;
XtSetArg(args[n], XmNmarginWidth, 7); n++;
XtSetArg(args[n], XmNverticalSpacing, 3); n++;
XtSetArg(args[n], XmNhorizontalSpacing, 3); n++;
frmBoot = XmCreateForm(wndBoot, "frmBoot", args, n);
n = 0;
szGeneric = XmStringCreateLocalized("Starting FreeBSD...");
XtSetArg(args[n], XmNlabelString, szGeneric); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
lblStatus = XmCreateLabel(frmBoot, "lblStatus", args, n);
XmStringFree(szGeneric);
n = 0;
XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
XtSetArg(args[n], XmNeditable, FALSE); n++;
XtSetArg(args[n], XmNrows, 15); n++;
XtSetArg(args[n], XmNcolumns, 80); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, lblStatus); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
txtConsole = XmCreateText(frmBoot, "txtConsole", args, n);
XtManageChild(txtConsole);
XtManageChild(lblStatus);
XtManageChild(frmBoot);
XtRealizeWidget(wndBoot);
if (OpenConsole(txtConsole) == False)
{
XCloseDisplay(pDpy);
exit(0);
}
switch (fork())
{
case 0:
break;
case -1:
perror("graphicboot: Failed to fork to background\n");
CleanupAndExit();
break;
default:
exit(0);
}
CreateServer();
XtAppMainLoop(xtAppContext);
unlink(CONTROL_SOCKET);
XCloseDisplay(pDpy);
exit(1);
return 1;
}
/**
* Cleans up the programs and exits
*/
MAINCALL void CleanupAndExit()
{
XtRemoveInput(input_id);
unlink(CONTROL_SOCKET);
if (nServer != -1) close(nServer);
if (nClient != -1) close(nClient);
if (nPTYFile != -1) close(nPTYFile);
if (nTTYFile != -1) close(nTTYFile);
exit(0);
}
syntax highlighted by Code2HTML, v. 0.9.1