/* 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/gbserver.c,v 1.4 2005/08/04 05:08:57 matthew Exp $ */ #define _GBSERVER_C_1700E96A_FE1A_11D9_A94B_0050FC0DCA2A #include "graphicboot.h" struct sockaddr_un saServer, saClient; pthread_t thServer; SERVERCALL void CheckForConnection(void *vp) { pthread_t thClient; int nLen = sizeof(saClient); for (;;) { if ((nClient = accept(nServer, (struct sockaddr *)&saClient, &nLen)) == -1) { perror("graphicboot: Unable to accept connection to client\n"); CleanupAndExit(); } if (pthread_create(&thClient, pthread_attr_default, (void*)ProcessClientMessage, (void*)&nClient) != 0) { perror("graphicboot: Unable to create client processing thread\n"); CleanupAndExit(); } } } SERVERCALL void ProcessClientMessage(void *vp) { int nConnection = *(int*)vp; int nRet; do { nRet = recv(nConnection, szStatus, MAX_LINE_SIZE, 0); if(strncmp(szStatus, "_XGB_EGB", 8) == 0) { CleanupAndExit(); } if (strncmp(szPrev, szStatus, MAX_LINE_SIZE) != 0) { SetStatusMessage(szStatus); strncpy(szPrev, szStatus, MAX_LINE_SIZE); } } while (nRet != -1); } SERVERCALL int CreateServer() { int nLen; /* We must create a socket for the control program */ if (access(CONTROL_SOCKET, F_OK) == 0) unlink(CONTROL_SOCKET); if ((nServer = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { perror("graphicboot: Unable to create control socket\n"); return FALSE; } /* Bind the socket to the control socket file */ saServer.sun_family = AF_UNIX; strcpy(saServer.sun_path, CONTROL_SOCKET); nLen = strlen(saServer.sun_path) + sizeof(saServer.sun_family) + 1; if (bind(nServer, (struct sockaddr *)&saServer, nLen) == -1) { perror("graphicboot: Unable to bind server to socket\n"); return FALSE; } /* Listen for a connect */ if (listen(nServer, 5) == -1) { perror("graphicboot: Unable to listen on socket\n"); return FALSE; } /* Create a thread to listen for connections */ if (pthread_create(&thServer, pthread_attr_default, (void*)CheckForConnection, NULL) != 0) { perror("graphicboot: Unable to create server thread\n"); return FALSE; } return TRUE; }