⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daemon.c

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 C
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%//////////////////////////////////////////////////////////////////////////////*!  \file daemon.c  \brief Remote daemon launcher.  This program is to be run on remote host to enable them for remote  providers. It loads predefined communication libraries and initializes  them. Afterwards the remote daemon thread enters the cleanup procedure  that checks for unused remote providers to be unloaded.  \sa remote_broker.c*/#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <string.h>#include <stdlib.h>#include <fcntl.h>#include <errno.h>#include <unistd.h>#include <signal.h>#ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM#include <dlfcn.h>#else#include <dll.h>#endif#include "../native/mm.h"#include "remote.h"#include "native.h"#include "../ip.h"#include "../io.h"#include "../tcpcomm.h"#include "../serialization.h"#include "debug.h"#include <Pegasus/Common/Config.h>typedef int (* START_DAEMON) ();typedef struct {	const char * libname;	void * hLibrary;	CMPI_THREAD_TYPE thread;} comm_lib;//! List of communication libraries to be initialized.static comm_lib __libs[] = {	{ "CMPIRTCPCommRemote",0 ,0 },};int nativeSide=1;static const struct BinarySerializerFT *__sft = &binarySerializerFT;/***************************************************************************///! Initializes a remote communication library./*!  Opens the communication library, searches the entry points and executes  it. The communication layer may then spawn additional listener threads,  if necessary.  \param comm pointer to the communication library to be loaded. */static void __init_remote_comm_lib ( comm_lib * comm ){	void * hdl = comm->hLibrary = tool_mm_load_lib ( comm->libname );	if ( hdl ) {#ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM		START_DAEMON fp = (START_DAEMON) dlsym ( hdl, "start_remote_daemon" );#else		START_DAEMON fp = (START_DAEMON) dllqueryfn ( (dllhandle*) hdl, "start_remote_daemon" );#endif		if ( fp ) {			if ( fp () )				fprintf ( stderr,					  "Failed to initialize library." );			return;		}	}#ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM	fprintf ( stderr, "%s\n", dlerror () );#else	fprintf( stderr, "%s\n", strerror(errno) );#endif}void _usage(){    printf ( "Usage: CMPIRDaemon [--foreground | --stop | --help]\n" );    printf ( "--foreground : Runs the daemon in the foreground.\n");    printf ( "--stop       : Stops the daemon.\n" );    printf ( "--help       : Prints this message.\n" );}//! Loads all communication libraries./*!  The function initializes the de-/activation context for remote providers,  then loads all the communication layers. Finally it enters the cleanup  loop.  \sa init_activation_context()  \sa cleanup_remote_brokers() */int main (int argc, char *argv[]){	unsigned int i;        int foreground = 0;        int unix_platform = 0;        int daemon_stop = 0;        char* message_code;        pid_t pid, sid;        int socket;        if (argc > 2)        {            _usage();            return 0;        }        if (argc == 2)        {            if (!strcmp (argv[1], "--foreground" ))            {                foreground = 1;            }            else if (!strcmp (argv[1], "--stop" ))            {                daemon_stop = 1;            }            else            {                _usage();                return 0;            }        }        // "tickle" the connection.        socket = open_connection ( "127.0.0.1", REMOTE_LISTEN_PORT,                                   PEGASUS_SUPPRESS_ERROR_MESSAGE);        if (socket >= 0)        {            if( daemon_stop)            {                message_code = PEGASUS_CMPIR_DAEMON_STOP;                printf ("CMPIRDaemon stopped.\n");            }            else            {                message_code = PEGASUS_CMPIR_DAEMON_IS_RUNNING;                printf ("CMPIRDaemon is already started.\n");            }            __sft->serialize_string (socket, message_code );            close (socket);            return 0;        }        else if (daemon_stop)        {                printf ("CMPIRDaemon is not running.\n");                return 0;        }        // Start daemon on unix platforms        if (!foreground)        {#if defined(PEGASUS_OS_TYPE_UNIX)            unix_platform = 1;            pid = fork ();            if (pid > 0)            {                exit(0); // Parent, die now...            }            if (pid < 0 || setsid() < 0 || chdir("/") < 0)            {                printf ("CMPIRDaemon: Can't run as daemon.\n");                return -1;            }            printf ("CMPIRDaemon started.\n");            /* Close out the standard file descriptors */            close (STDIN_FILENO);            close (STDOUT_FILENO);            close (STDERR_FILENO);#endif        }        if (!unix_platform && !foreground)        {            printf ("Daemon is supported only on UNIX platforms, running in foreground.\n" );        }	CMPIContext * ctx = native_new_CMPIContext ( TOOL_MM_NO_ADD );	init_activation_context ( ctx );	for ( i = 0;	      i < sizeof ( __libs ) / sizeof ( comm_lib );	      i++ ) {		__init_remote_comm_lib ( __libs + i );	}        if (foreground || !unix_platform)        {	    TRACE_NORMAL(("All remote daemons started.\n"));	    TRACE_NORMAL(("Entering provider cleanup loop ...\n"));        }	cleanup_remote_brokers ( 100, 30 );	return 0;}/*** Local Variables:  ***//*** mode: C           ***//*** c-basic-offset: 8 ***//*** End:              ***/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -