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

📄 init.c

📁 公关系统服务器后台程序
💻 C
字号:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include <signal.h>#include <sys/param.h>#include <sys/stat.h>#include "opepool.h"#include "opepipe.h"#include "socksystem.h"#include "msg.h"#include "global.h"int serverType=SERVERMAIN;#define SERVER_PORT	8018extern int chkConnect();extern int checkTime();extern void cmdsockhandle(int);extern void cmdsockmsghandle(int);extern void cmdpipehandle(int);void showHelp();int main(int argc,char *argv[]){	//进入后台运行模式	int ret;	int sockrequest,sockmsg;	int pipe_read_from_gui;	int maxfd;	fd_set severfds;	struct timeval chktime;	int para;	serverType=SERVERMAIN;	while(1)	{		para=getopt(argc,(char**)argv,"v:h");		if(para==-1)			break;		if(para=='v')		{			if(strcmp(optarg,"MAIN")==0)			{				serverType=SERVERMAIN;				continue;			}			if(strcmp(optarg,"EXT")==0)			{				serverType=SERVEREXT;				continue;			}		}		if(para=='h')		{			showHelp();			exit(0);		}	}#if !DEBUG	initDaemon();#endif	system("rm -f /tmp/systemGuard.log");	if(serverType)	{		ret=macPoolInit();		if(ret==-1)		{			printf("pool init error ..\n");			exit(0);		}		else if(ret==0)		{			printf("can not get num from system card..\n");			sleep(5);			exit(0);		}	}	sockrequest=openSock();#if DEBUG	printf("start system server.\n");#endif	startServer(sockrequest,SERVER_PORT);#if DEBUG	printf("start message server.\n");#endif	if(serverType)		sockmsg=msgBegin(SERVER_PORT);	pipe_read_from_gui=startPipeGui();	if(checkTime()==0)	{		close(sockrequest);		if(serverType)			close(sockmsg);		close(pipe_read_from_gui);		exit(0);	}	maxfd=pipe_read_from_gui+1;	while(1)	{		if(serverType)		{			chktime.tv_sec=180;			chktime.tv_usec=0;		}		FD_SET(sockrequest,&severfds);		if(serverType)			FD_SET(sockmsg,&severfds);		FD_SET(pipe_read_from_gui,&severfds);		if(select(maxfd,&severfds,NULL,NULL,&chktime))		{			if(FD_ISSET(sockrequest,&severfds))			{				cmdsockhandle(sockrequest);				continue;			}			if(serverType)			{				if(FD_ISSET(sockmsg,&severfds))				{					cmdsockmsghandle(sockmsg);					continue;				}			}			if(FD_ISSET(pipe_read_from_gui,&severfds))			{				cmdpipehandle(pipe_read_from_gui);				continue;			}		}		else		{#if DEBUG			printf("begin chkConnect.......\n");#endif			if(serverType)				chkConnect();		}	}	return 0;}void showHelp(){	printf("system guard program.\n");	printf("usage:\n");	printf("\t./systemguard [-v]\n");	printf("\tpara [MAIN] [EXT]\n");	printf("\tMAIN : main server.\n");	printf("\tEXT  : external server.\n");	printf("\tExample:./systemguard -v MAIN\n");}

⌨️ 快捷键说明

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