📄 eibdrv_serv.c
字号:
/* --------------------------------------------------------------------------- eibdrv_serv.c --------------------------------------------------------------------------- eibdrv Version 0.2.1 Copyright (C) 2002, Wolfgang Tumfart Donaustrasse 104/9 A-2344 Maria Enzersdorf Austria (Europe) tumfart@auto.tuwien.ac.at This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. --------------------------------------------------------------------------- */#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <linux/fcntl.h>#include <linux/ioctl.h>#include <sys/time.h>#include <sys/types.h>#include "eibdrv.h"void eibdrv_serv(char *device,int serv_no){ int eib_fd; int result; if (setsid()==-1) { printf("eibdrv_serv <%i>: cannot create new session\n",serv_no); exit(3); } if (chdir("/")==-1) { printf("eibdrv_serv <%i>: cannot change to root directory\n",serv_no); exit(3); } umask(0); if ((eib_fd=open(device,O_RDWR))<0) { switch(result=errno) { case ENOENT: printf("eibdrv_serv <%i>: device node %s not found\n",serv_no,device); exit(3); case EBUSY: printf("eibdrv_serv <%i>: module is shutdown or all server processes connected\n",serv_no); exit(3); case ENOBUFS: printf("eibdrv_serv <%i>: all server processes connected\n",serv_no); exit(3); default: printf("eibdrv_serv <%i>: cannot open device %s\n",serv_no,device); exit(3); } } if (ioctl(eib_fd,FT_ISSERVPROC)<0) { switch(result=errno) { case EINVAL: switch(ioctl(FT_GET_MODE)) { case FT_STANDARDMODE: printf("eibdrv_serv <%i>: module is loaded in standard mode\n",serv_no); close(eib_fd); exit(3); case FT_SERVERMODE: printf("eibdrv_serv <%i>: all server processes connected\n",serv_no); close(eib_fd); exit(3); } } } if (close(eib_fd)<0) { printf("eibdrv_serv <%i>: cannot close device %s\n",serv_no,device); exit(3); } exit(0); }main(int argc,char *argv[]){ pid_t pid1,pid2; if (argc!=2) { printf("usage: eibdrv_serv node\n"); exit(1); } switch(pid1=fork()) // fork server process 1 { case -1: printf("eibdrv_serv: cannot fork server process1\n"); exit(2); case 0: eibdrv_serv(argv[1],1); break; } switch(pid2=fork()) // fork server process 2 { case -1: printf("eibdrv_serv: cannot fork server process2\n"); exit(2); case 0: eibdrv_serv(argv[1],2); break; } exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -