当前位置: 首页>>代码示例>>C++>>正文


C++ err_sys函数代码示例

本文整理汇总了C++中err_sys函数的典型用法代码示例。如果您正苦于以下问题:C++ err_sys函数的具体用法?C++ err_sys怎么用?C++ err_sys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了err_sys函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(void)
{
    int n, fd1[2], fd2[2];
    pid_t pid;
    char line[MAXLINE];

    // 创建信号,用于接受SIGPIPE信号,用自定义sig_pipe()函数进行处理.
    if (signal(SIGPIPE, sig_pipe) == SIG_ERR) {
        err_sys("signal error");
    }

    // 创建两个管道
    if (pipe(fd1) < 0 || pipe(fd2) < 0) {
        err_sys("pipe error");
    }

    // 创建子进程
    if ((pid = fork()) < 0) {
        err_sys("fork error");
    } else if (pid > 0) {           // 父进程
        close(fd1[0]);
        close(fd2[1]);

        while (fgets(line, MAXLINE, stdin) != NULL) {   // 从标准输入读取数据写入到fd1管道
            n = strlen(line);
            if (write(fd1[1], line, n) != n) {
                err_sys("write error to pipe");
            }
            if ((n = read(fd2[0], line, MAXLINE)) < 0) {    // 从fd2管道读取结果
                err_sys("read error from pipe");
            }
            if (n == 0) {
                err_msg("child closed pipe");
                break;
            }
            line[n] = 0;
            if (fputs(line, stdout) == EOF) {
                err_sys("fputs error");
            }
        }

        if (ferror(stdin)) {
            err_sys("fgets error on stdin");
        }
        exit(0);
    } else {                // 子进程
        close(fd1[1]);
        close(fd2[0]);

        if (fd1[0] != STDIN_FILENO) {
            if (dup2(fd1[0], STDIN_FILENO) != STDIN_FILENO) {
                err_sys("dup2 error to stdin");
            }
            close(fd1[0]);
        }

        if (fd2[1] != STDOUT_FILENO) {
            if (dup2(fd2[1], STDOUT_FILENO) != STDOUT_FILENO) {
                err_sys("dup2 error to stdout");
            }
            close(fd2[1]);
        }

        if (execl("./add2", "add2", (char *)0) < 0) {   // 执行过滤程序
            err_sys("execl error");
        }
    }
    exit(0);
}
开发者ID:SummonY,项目名称:APUE,代码行数:69,代码来源:coprocess.c

示例2: Bind

void
Bind(int fd, const struct sockaddr *sa, socklen_t salen)
{
    if (bind(fd, sa, salen) < 0)
        err_sys("bind error");
}
开发者ID:dot-Sean,项目名称:unix_networking_projects,代码行数:6,代码来源:main.c

示例3: Getsockname

void
Getsockname(int fd, struct sockaddr *sa, socklen_t *salenptr)
{
    if (getsockname(fd, sa, salenptr) < 0)
        err_sys("getsockname error");
}
开发者ID:dot-Sean,项目名称:unix_networking_projects,代码行数:6,代码来源:main.c

示例4: get_ifi_info

struct ifi_info * 
get_ifi_info(int family, int doaliases) 
{ 
	struct ifi_info *ifi, *ifihead, **ifipnext; 
	int sockfd, len, lastlen, flags, myflags, idx = 0, hlen = 0; 
	char *ptr, *buf, lastname[IFNAMSIZ], *cptr, *haddr, *sdlname; 
	struct ifconf ifc; 
	struct ifreq *ifr, ifrcopy; 
	struct sockaddr_in *sinptr; 
	struct sockaddr_in6 *sin6ptr; 
	int bufsz;
	
	sockfd = Socket(AF_INET, SOCK_DGRAM, 0); 
 
	lastlen = 0;
	if (ioctl(sockfd, SIOCGIFIFNUM, &bufsz) > 0) {
		len = bufsz;
	} else {
		len = 100 * sizeof(struct ifreq); /* initial buffer size guess */
	}

	for ( ; ; ) { 
		buf = Malloc(len); 
		ifc.ifc_len = len; 
		ifc.ifc_buf = buf; 
		if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) { 
			if (errno != EINVAL || lastlen != 0) 
				err_sys("ioctl error"); 
		} else { 
			if (ifc.ifc_len == lastlen) 
				break; /* success, len has not changed */ 
			lastlen = ifc.ifc_len; 
		} 
		len += 10 * sizeof(struct ifreq); /* increment */ 
		free(buf); 
	} 
	ifihead = NULL; 
	ifipnext = &ifihead; 
	lastname[0] = 0; 
	sdlname = NULL; 
/* end get_ifi_info1 */ 
 
/* include get_ifi_info2 */ 
	for (ptr = buf; ptr < buf + ifc.ifc_len; ) { 
		ifr = (struct ifreq *) ptr; 
 
#ifdef HAVE_SOCKADDR_SA_LEN 
		len = max(sizeof(struct sockaddr), ifr->ifr_addr.sa_len); 
#else 
		switch (ifr->ifr_addr.sa_family) { 
#ifdef IPV6 
		case AF_INET6: 
			len = sizeof(struct sockaddr_in6); 
			break; 
#endif 
		case AF_INET: 
		default: 
			len = sizeof(struct sockaddr); 
			break; 
		} 
#endif /* HAVE_SOCKADDR_SA_LEN */ 
		ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 
 
#ifdef HAVE_SOCKADDR_DL_STRUCT 
		/* assumes that AF_LINK precedes AF_INET or AF_INET6 */ 
		if (ifr->ifr_addr.sa_family == AF_LINK) { 
			struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; 
			sdlname = ifr->ifr_name; 
			idx = sdl->sdl_index; 
			haddr = sdl->sdl_data + sdl->sdl_nlen; 
			hlen = sdl->sdl_alen; 
		} 
#endif 
 
		if (ifr->ifr_addr.sa_family != family) 
			continue; /* ignore if not desired address family */ 
 
		myflags = 0; 
		if ( (cptr = strchr(ifr->ifr_name, ':')) != NULL) 
			*cptr = 0; /* replace colon with null */ 
		if (strncmp(lastname, ifr->ifr_name, IFNAMSIZ) == 0) { 
			if (doaliases == 0) 
				continue; /* already processed this interface */ 
			myflags = IFI_ALIAS; 
		} 
		memcpy(lastname, ifr->ifr_name, IFNAMSIZ); 
 
		ifrcopy = *ifr; 
		Ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy); 
		flags = ifrcopy.ifr_flags; 
		if ((flags & IFF_UP) == 0) 
			continue; /* ignore if interface not up */ 
/* end get_ifi_info2 */ 
 
/* include get_ifi_info3 */ 
		ifi = Calloc(1, sizeof(struct ifi_info)); 
		*ifipnext = ifi; /* prev points to this new one */ 
		ifipnext = &ifi->ifi_next; /* pointer to next one goes here */ 
 
		ifi->ifi_flags = flags; /* IFF_xxx values */ 
//.........这里部分代码省略.........
开发者ID:tcharding,项目名称:self_learning,代码行数:101,代码来源:get_ifi_info-ex-17.4.c

示例5: Send

void
Send(int fd, const void *ptr, size_t nbytes, int flags)
{
    if (send(fd, ptr, nbytes, flags) != (ssize_t)nbytes)
        err_sys("send error");
}
开发者ID:dot-Sean,项目名称:unix_networking_projects,代码行数:6,代码来源:main.c

示例6: Shutdown

void
Shutdown(int fd, int how)
{
    if (shutdown(fd, how) < 0)
        err_sys("shutdown error");
}
开发者ID:dot-Sean,项目名称:unix_networking_projects,代码行数:6,代码来源:main.c

示例7: Connect

void
Connect(int fd, const struct sockaddr *sa, socklen_t salen)
{
    if ( connect( fd, sa, salen) < 0)
        err_sys( "connect error");
}
开发者ID:dot-Sean,项目名称:unix_networking_projects,代码行数:6,代码来源:main.c

示例8: main

int
main ( int argc, char *argv[] )
{
   struct stat struct_stat;
   pthread_t pid;
   pthread_attr_t attr;
   int i, num_sources;
   uid_t gmetad_uid;
   mode_t rrd_umask;
   char * gmetad_username;
   struct passwd *pw;
   char hostname[HOSTNAMESZ];
   gmetad_config_t *c = &gmetad_config;
   apr_interval_time_t sleep_time;
   apr_time_t last_metadata;
   double random_sleep_factor;
   unsigned int rand_seed;

   /* Ignore SIGPIPE */
   signal( SIGPIPE, SIG_IGN );

   if (cmdline_parser(argc, argv, &args_info) != 0)
      err_quit("command-line parser error");

   num_sources = number_of_datasources( args_info.conf_arg );
   if(!num_sources)
      {
         err_quit("%s doesn't have any data sources specified", args_info.conf_arg);
      }

   memset(&root, 0, sizeof(root));
   root.id = ROOT_NODE;

   /* Get the real number of data sources later */
   sources = hash_create( num_sources + 10 );
   if (! sources )
      {
         err_quit("Unable to create sources hash\n");
      }

   root.authority = hash_create( num_sources + 10 );
   if (!root.authority)
      {
         err_quit("Unable to create root authority (our grids and clusters) hash\n");
      }

   root.metric_summary = hash_create (DEFAULT_METRICSIZE);
   if (!root.metric_summary)
      {
         err_quit("Unable to create root summary hash");
      }

   parse_config_file ( args_info.conf_arg );
    /* If given, use command line directives over config file ones. */
   if (args_info.debug_given)
      {
         c->debug_level = args_info.debug_arg;
      }
   debug_level = c->debug_level;
   set_debug_msg_level(debug_level);

   /* Setup our default authority pointer if the conf file hasnt yet.
    * Done in the style of hash node strings. */
   if (!root.stringslen)
      {
         gethostname(hostname, HOSTNAMESZ);
         root.authority_ptr = 0;
         sprintf(root.strings, "http://%s/ganglia/", hostname);
         root.stringslen += strlen(root.strings) + 1;
      }

   rand_seed = apr_time_now() * (int)pthread_self();
   for(i = 0; i < root.stringslen; rand_seed = rand_seed * root.strings[i++]);

   /* Debug level 1 is error output only, and no daemonizing. */
   if (!debug_level)
      {
         rrd_umask = c->umask;
         daemon_init (argv[0], 0, rrd_umask);
      }

   if (args_info.pid_file_given)
     {
       update_pidfile (args_info.pid_file_arg);
     }

   /* The rrd_rootdir must be writable by the gmetad process */
   if( c->should_setuid )
      {
         if(! (pw = getpwnam(c->setuid_username)))
            {
               err_sys("Getpwnam error");
            }
         gmetad_uid = pw->pw_uid;
         gmetad_username = c->setuid_username;
      }
   else
      {
         gmetad_uid = getuid();
         if(! (pw = getpwuid(gmetad_uid)))
//.........这里部分代码省略.........
开发者ID:ClodoCorp,项目名称:debian-ganglia,代码行数:101,代码来源:gmetad.c

示例9: main

int main(int argc, char **argv)
{
    int i, maxi, listenfd, connfd, sockfd;
	int nready;
	ssize_t n;
	char buf[MAXLINE];
	socklen_t clilen;
	struct pollfd client[OPEN_MAX];
	struct sockaddr_in cliaddr, servaddr;

	listenfd = Socket(AF_INET, SOCK_STREAM, 0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(SERV_PORT);

	Bind(listenfd, (SA *)&servaddr, sizeof(servaddr));

	Listen(listenfd, LISTENQ);

	client[0].fd = listenfd;
	client[0].events = POLLIN;
	for (i = 1; i < OPEN_MAX; i++)
		client[1].fd = -1;
	maxi = 0;

	for ( ; ; )
	{
		nready = Poll(client, maxi + 1, INFTIM);

		if (client[0].revents & POLLIN)   /* new client connection */
		{
            clilen = sizeof(cliaddr);
			connfd = Accept(listenfd, (SA *)&cliaddr, &clilen);

			for (i = 1; i < OPEN_MAX; i++)
				if (client[i].fd < 0)
				{
					client[i].fd = connfd;   /* save descriptor */
					break;
				}

			if (i == OPEN_MAX)
                err_quit("too many clients");
            
			client[i].events = POLLIN;
			if (i > maxi)
				maxi = i;   /* max index in client[] array */

			if (--nready <= 0)
				continue;   /* no more readable descriptors */
		}

		for (i = 1; i <= maxi; i++)   /* check all clients for data */
		{
            if ((sockfd = client[i].fd) < 0)
				continue;

			if (client[i].revents & (POLLIN | POLLERR))
			{
				if ((n = read(sockfd, buf, MAXLINE)) < 0)
				{
					if (errno == ECONNRESET)   /* connection reset by client */
					{
                        Close(sockfd);
						client[i].fd = -1;
					}
					else
						err_sys("read error");
				}
				else if (n == 0)   /* connection closed by client */
				{
					Close(sockfd);
					client[i].fd = -1;
				}
				else
				    Writen(sockfd, buf, n);

				if (--nready <= 0)   /* no more readable descriptors */
					break;
			}
		}
	}
}
开发者ID:CanuxCheng,项目名称:UNP1,代码行数:85,代码来源:tcpservpoll.c

示例10: main

int
main(void)
{
	int fd1[2], fd2[2];
	pid_t pid;
	char line[MAXLINE];
	FILE *infp, *outfp;

	if (signal(SIGPIPE, sig_pipe) == SIG_ERR)
		err_sys("signal error");

	if (pipe(fd1) < 0 || pipe(fd2) < 0)
		err_sys("pipe error");

	if ((pid = fork()) < 0) {
		err_sys("fork error");
	} else if (pid > 0) {	/* parent */
		close(fd1[IN]),	close(fd2[OUT]);

		if (((infp = fdopen(fd2[IN], "r")) == NULL) ||
		    ((outfp = fdopen(fd1[OUT], "w")) == NULL))  
			err_sys("fdopen error");
		
		if ((setvbuf(infp, NULL, _IOLBF, 0) != 0) ||
		    (setvbuf(outfp, NULL, _IOLBF, 0) != 0))
			err_sys("setvbuf error");
				
		while (fgets(line, MAXLINE, stdin) != NULL) {
			if (fputs(line, outfp) == EOF)
				err_sys("fputs error");
			if (fgets(line, MAXLINE, infp) == NULL) {
				if (ferror(infp) != 0)
					err_sys("fgets error");
				else
					err_msg("child closed pipe");
			}
			if (fputs(line, stdout) == EOF)
				err_sys("fputs error");
		}
		Fclose(infp);
		Fclose(outfp);
		if (ferror(stdin))
			err_sys("fgets error on stdin");
		exit(0);
	} else {		/* child */
		close(fd1[OUT]);
		close(fd2[IN]);
		if (fd1[IN] != STDIN_FILENO) {
			if (dup2(fd1[IN], STDIN_FILENO) != STDIN_FILENO)
				err_sys("dup2 error to stdin");
			close(fd1[IN]);
		}

		if (fd2[OUT] != STDOUT_FILENO) {
			if (dup2(fd2[OUT], STDOUT_FILENO) != STDOUT_FILENO)
				err_sys("dup2 error to stdout");
			close(fd2[OUT]);
		}
		if (execl("./add2", "add2", (char *)0))
			err_sys("execl error");
	}
	exit(0);
}
开发者ID:tcharding,项目名称:self_learning,代码行数:63,代码来源:coprocess.c

示例11: init_fpga_task

static int 
init_fpga_task(void)
{
  int j, i;
  int ans;
  static int firsttime = TRUE;
  
 

  //enter code
    /* get home path */
    homePath= getenv ("HOME");
  
 
     //////////////////////////////////////////////////////////////////////////
    // Create a MMAP
    //////////////////////////////////////////////////////////////////////////
#ifdef WIN32
	/*// Create a 4K memory-mapped file (MMF)
	hFile = CreateFile((LPCTSTR) "input.dat", 
		GENERIC_WRITE | GENERIC_READ, 
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 
		OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	
	if(hFile == INVALID_HANDLE_VALUE) 
	{
		// Failed to create file 
		return 1;
	}

	map = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 1024, "MMAPShmem");
	g_fpga2robot = (char *) MapViewOfFile (map, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); 
	*/
#else



 printf("buffer_size: %d\n\n", statbuf.st_size);
	
	int fd_i;
    char* fgpa2robot_FilePath;
    fgpa2robot_FilePath = strncat(homePath, "/prog/masterUser/src/fpga2robot.dat", 100);  //max number of characers to be concatinated :100
    if((fd_i = open(fgpa2robot_FilePath, O_RDWR)) == -1)
	{
        printf("Couldn't open 'fpga2robot.dat'\n");
   	}
   	g_fpga2robot = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd_i, 0);
    
    if (g_fpga2robot == MAP_FAILED) {
        close(fd_i);
        perror("Error mmapping the file");
        exit(EXIT_FAILURE);
    }
    
    int fd_o;
    if((fd_o = open("/home/eric/prog/masterUser/src/robot2fpga.dat", O_RDWR)) == -1)
    {
        printf("Couldn't open 'robot2fpga.dat'\n");
    }
    lseek(fd_o, 0, SEEK_SET);
    g_robot2fpga = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd_o, 0);
    
    if (g_robot2fpga == MAP_FAILED) {
        close(fd_o);
        perror("Error mmapping the file");
        exit(EXIT_FAILURE);
    }
#endif

    if(g_fpga2robot != NULL)
    {	
        printf("Wrapper has created a MMAP for file 'fpga2robot.dat'\n");
    }

    if(g_robot2fpga != NULL)
    {   
        printf("Wrapper has created a MMAP for file 'robot2fpga.dat'\n");
    }
    
    /* find size of input file */
    if (fstat (fd_i, &statbuf) < 0)
        err_sys ("fstat error");

	system("/home/eric/prog/masterUser/src/py/py_mmap.py &");
  //end code



  
  

  if (firsttime){
    firsttime = FALSE;
    freq = 0.1; // frequency
    amp  = 0.5; // amplitude
  }

  // prepare going to the default posture
  bzero((char *)&(target[1]),N_DOFS*sizeof(target[1]));
  for (i=1; i<=N_DOFS; i++)
//.........这里部分代码省略.........
开发者ID:wonjsohn,项目名称:sarcos,代码行数:101,代码来源:fpga_task.c

示例12: main

int main(int argc, char argv**)
{
	socklen_t len;
	int n, listenfd, connfd, char_in, count = 0;
	struct sockaddr_in  servaddr, cliaddr;
	char buff[40], wbuff[MAXLINE], rbuff[MAXLINE], cmd[16], path1[64]=".", path[64], vers[16];

	FILE * hFile;

	if(argc != 2)
	{
		err_quit("usage: a.out <Port>");
	}

	listenfd = Socket(AF_INET, SOCK_STREAM, 0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.sin_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(atoi(argv[1]));

	Bind(listenfd, (SA*) &servaddr, sizeof(servaddr));

	Listen(listenfd, LISTENQ);

	for( ; ; )
	{
		len = sizeof(cliaddr);

		connfd  = Accept(listenfd, (SA*) &cliaddr, &len);
		printf("\nConnection from %s, port %d\n", Inet_ntop(AF_INET, &cliaddr.sin_addr, buff, sizeof(buff)) ntohs(cliaddr.sin_port));

		while((n = read(connfd, rbuff, MAXLINE)) > 0)
		{
			rbuff[n] = 0;

			if(fputs(rbuff, stdout) == 0)
			{
				err_sys("fputs error");
			}

			if(strstr(rbuff,"\r\n\r\n") > 0)
			{
				break;
			}
		}

		if(n < 0)
		{
			err_sys("read error");
		}

		sscanf(rbuff, "%s %s %s", cmd, path, vers);
		strcat(path1, path);
		if(strcmp(path1, "./") == 0)
		{
			strcpy(path1, "./index.html");
		}

		hFile = fopen(path1, "r");
		if(hFile == NULL)
		{
			hFIle = fopen("error.html", "r");
		}

		strcpy(wbuff,"");

		while((char_in = fgetc(hFile)) != EOF)
		{
			wbuff(count) = char_in;
			count++;
		}

		wbuff(count) = 0;

		Write(connfd, wbuff, strlen(wbuff));

		count = 0;
		fclose(hFile);
		strcpy(path1,".");

		Close(connfd);
	}
}
开发者ID:adevlin121,项目名称:CSPE,代码行数:84,代码来源:complexHTTPserver.c

示例13: main

int main(int argc, char const *argv[])
{
	char line[MAXLINE];
	FILE *fpout, *fpin;

	if((fpout = popen("./kbfilter", "w")) == NULL)
			err_sys("popen error");
	//if((fpin = popen("./kbfilter", "r")) == NULL)
	//		err_sys("popen error");

	struct termios termios_struct;

  tcgetattr(STDIN_FILENO, &orig_termios_struct);
  tcgetattr(STDIN_FILENO, &termios_struct);
  // could be done like this also:
  // termios_struct = orig_termios_struct;

  termios_struct.c_lflag &= (~ICANON) & (~ECHO);
  termios_struct.c_cc[VTIME] = 0;
  termios_struct.c_cc[VMIN] = 1;
  tcsetattr(STDIN_FILENO, TCSANOW, &termios_struct);
  sleep(1);

  char c[2];
  //while((c = getchar()) != EOF)
  while((c[0] = getc(stdin)) != EOF)
	{   
		c[1] = 0;    
		//printf("%s\n", c);
		if(fputs(c,fpout) == EOF)
		{ 
  		tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios_struct);
			err_sys("fputs error to pipe");
		}
	}
  tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios_struct);
	if (ferror(fpout))
		//||ferror(fpin))
		err_sys("fputs error to pipe");
  if(pclose(fpout) == -1)
		err_sys("pclose fpout error");
  //if(pclose(fpin) == -1)
	//	err_sys("pclose fpin error");
/*
	if((fpin = popen("./kbfilter", "r")) == NULL)
			err_sys("popen error");
	for(;;)
	{
		//fputs("prompt> ", stdout);
		//fflush(stdout);
		if(fgets(line, MAXLINE, fpin) == NULL) // read from pipe
			break;
		if(fputs(line, stdout) == EOF)
			err_sys("fputs error to pipe");
	}
	if(pclose(fpin) == -1)
		err_sys("pclose error");

//	tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios_struct);
*/
	putchar('\n');
	exit(0);
}
开发者ID:chubbson,项目名称:zhaw_os_linux,代码行数:63,代码来源:kbpopen.c

示例14: receive_cmd


//.........这里部分代码省略.........
                int close_fd_errout = 1;
                
                if (i + 1 < cmdc) {
                    // If there's next command
                    Pipe(in_out_pipe);
                    fd_out = in_out_pipe[1];
                    fd_errout = in_out_pipe[1];
                } else {
                    // This is last one
                    fd_out = sockfd;
                    fd_errout = sockfd;
                    
                    int minus = 0;
                    
                    for (int q = 0; q < argc; q++) {
                        if (strcmp(argv[q], ">") == 0) {
                            fd_out = open(argv[q + 1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
                            argv[q] = '\0';
                            argc = q;
                            break;
                        } else if (argv[q][0] == '|' && argv[q][1] != '!') {
                            int dest_pipe = parse_number(&argv[q][1]) + line;
                            printf("dest_pipe std = %d\n", dest_pipe);
                            if (pipes[dest_pipe][1] == -1)
                                Pipe(pipes[dest_pipe]);
                            fd_out = pipes[dest_pipe][1];
                            close_fd_out = 0;
                            
                            argv[q] = '\0';
                            minus++;
                        } else if (argv[q][0] == '!' && argv[q][1] != '|') {

                            int dest_pipe = parse_number(&argv[q][1]) + line;
                            printf("dest_pipe err = %d\n", dest_pipe);
                            
                            if (pipes[dest_pipe][1] == -1)
                                Pipe(pipes[dest_pipe]);
                            fd_errout = pipes[dest_pipe][1];
                            close_fd_errout = 0;

                            argv[q] = '\0';
                            minus++;
                        } else if (
                                   (argv[q][0] == '!' && argv[q][1] == '|') ||
                                   (argv[q][0] == '|' && argv[q][1] == '!')) {

                            int dest_pipe = atoi(&argv[q][2]) + line;
                            printf("dest_pipe std+err = %d\n", dest_pipe);
                            
                            if (pipes[dest_pipe][1] == -1)
                                Pipe(pipes[dest_pipe]);

                            fd_out = pipes[dest_pipe][1];
                            fd_errout = pipes[dest_pipe][1];
                            
                            
                            argv[q] = '\0';
                            minus++;
                        }
                    }
                    argc -= minus;
                }
                
                printf("pipe[0]=%d\n", in_out_pipe[0]);
                printf("pipe[1]=%d\n", in_out_pipe[1]);
                
                char exit_code = fork_process(argv, fd_in, fd_out, fd_errout, sockfd);
                
                if (close_fd_out && fd_out != sockfd && fd_out != -1)
                    Close(fd_out);
                if (close_fd_errout && fd_errout != fd_out && fd_errout != sockfd && fd_errout != -1)
                    Close(fd_errout);

                if (exit_code == ERR_CMD_NOT_FOUND) {
                    dprintf(sockfd, "Unknown command: [%s].\n", argv[0]);
                    unknown_command = 1;
                    break;
                } else {
                    if (fd_in != -1)
                        Close(fd_in);
                    fd_in = in_out_pipe[0];
                }
                
            }

            showSymbol(sockfd);

            if (!unknown_command)
                line++;
        }
    }
    if (n < 0 && errno == EINTR) {
        pos += n;
        goto again;
    }
    else if (n < 0) {
        err_sys("str_echo: read error");
    }

}
开发者ID:Fonger,项目名称:Network-Programming-Homework,代码行数:101,代码来源:main.c

示例15: err_setout

void err_setout(int fd)
{
	if (dup2(fd, STDERR_FILENO) == -1)
		err_sys("liberr redirect stderr");
	_err_tty = isatty(STDERR_FILENO);
}
开发者ID:Bzcai,项目名称:baidudl,代码行数:6,代码来源:err_handler.c


注:本文中的err_sys函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。