OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_c/] [jtag/] [jtag_xilinx_xsct/] [pipe.c] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/*
2
   Copyright (C) Andrew Tridgell 1996
3
   Copyright (C) Paul Mackerras 1996
4
 
5
   This program is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 2 of the License, or
8
   (at your option) any later version.
9
 
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, write to the Free Software
17
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*/
19
 
20
/*
21
  Utilities used in rsync
22
 
23
  tridge, June 1996
24
  */
25
 
26
#ifndef _PIPE_H_
27
#define _PIPE_H_
28
 
29
#include <stdio.h>
30
#include <stdlib.h>
31
#include <errno.h>
32
 
33
#define STDIN_FILENO    0
34
#define STDOUT_FILENO   1
35
#define STDERR_FILENO   2
36
 
37
 
38
 
39
 
40
pid_t do_fork(void);
41
 
42
void exit_cleanup(int value) {
43
        exit(value);
44
}
45
 
46
/* this is taken from CVS */
47
int piped_child(char **command,int *f_in,int *f_out)
48
{
49
  int pid;
50
  int to_child_pipe[2];
51
  int from_child_pipe[2];
52
 
53
  if (pipe(to_child_pipe) < 0 ||
54
      pipe(from_child_pipe) < 0) {
55
    fprintf(stderr,"pipe: %s\n",strerror(errno));
56
    exit_cleanup(1);
57
  }
58
 
59
 
60
  pid = do_fork();
61
  if (pid < 0) {
62
    fprintf(stderr,"fork: %s\n",strerror(errno));
63
    exit_cleanup(1);
64
  }
65
 
66
  if (pid == 0)
67
    {
68
      if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||
69
          close(to_child_pipe[1]) < 0 ||
70
          close(from_child_pipe[0]) < 0 ||
71
// collect both stdout and stderr to the one pipe
72
          dup2(from_child_pipe[1], STDERR_FILENO) < 0 ||
73
          dup2(from_child_pipe[1], STDOUT_FILENO) < 0
74
           ) {
75
        fprintf(stderr,"Failed to dup/close : %s\n",strerror(errno));
76
        exit_cleanup(1);
77
      }
78
 
79
 
80
      if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]);
81
      if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]);
82
      execvp(command[0], command);
83
      fprintf(stderr,"Failed to exec %s : %s\n",
84
              command[0],strerror(errno));
85
      exit_cleanup(1);
86
    }
87
 
88
  if (close(from_child_pipe[1]) < 0 ||
89
      close(to_child_pipe[0]) < 0) {
90
    fprintf(stderr,"Failed to close : %s\n",strerror(errno));
91
    exit_cleanup(1);
92
  }
93
 
94
  *f_in = from_child_pipe[0];
95
  *f_out = to_child_pipe[1];
96
 
97
  return pid;
98
}
99
 
100
 
101
static pid_t all_pids[10];
102
static int num_pids;
103
 
104
/* fork and record the pid of the child */
105
pid_t do_fork(void)
106
{
107
        pid_t newpid = fork();
108
 
109
        if (newpid) {
110
                all_pids[num_pids++] = newpid;
111
        }
112
        return newpid;
113
}
114
 
115
/* kill all children
116
 
117
void kill_all(int sig)
118
{
119
        int i;
120
        for (i=0;i<num_pids;i++) {
121
                if (all_pids[i] != getpid())
122
                        kill(all_pids[i], sig);
123
        }
124
}
125
* */
126
 
127
 
128
 
129
 
130
 
131
 
132
 
133
 
134
 
135
 
136
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.