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_quartus_stp/] [pipe.c] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 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
 
36
pid_t do_fork(void);
37
 
38
void exit_cleanup(int value) {
39
        exit(value);
40
}
41
 
42
/* this is taken from CVS */
43
int piped_child(char **command,int *f_in,int *f_out)
44
{
45
  int pid;
46
  int to_child_pipe[2];
47
  int from_child_pipe[2];
48
 
49
  if (pipe(to_child_pipe) < 0 ||
50
      pipe(from_child_pipe) < 0) {
51
    fprintf(stderr,"pipe: %s\n",strerror(errno));
52
    exit_cleanup(1);
53
  }
54
 
55
 
56
  pid = do_fork();
57
  if (pid < 0) {
58
    fprintf(stderr,"fork: %s\n",strerror(errno));
59
    exit_cleanup(1);
60
  }
61
 
62
  if (pid == 0)
63
    {
64
      if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||
65
          close(to_child_pipe[1]) < 0 ||
66
          close(from_child_pipe[0]) < 0 ||
67
          dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
68
        fprintf(stderr,"Failed to dup/close : %s\n",strerror(errno));
69
        exit_cleanup(1);
70
      }
71
      if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]);
72
      if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]);
73
      execvp(command[0], command);
74
      fprintf(stderr,"Failed to exec %s : %s\n",
75
              command[0],strerror(errno));
76
      exit_cleanup(1);
77
    }
78
 
79
  if (close(from_child_pipe[1]) < 0 ||
80
      close(to_child_pipe[0]) < 0) {
81
    fprintf(stderr,"Failed to close : %s\n",strerror(errno));
82
    exit_cleanup(1);
83
  }
84
 
85
  *f_in = from_child_pipe[0];
86
  *f_out = to_child_pipe[1];
87
 
88
  return pid;
89
}
90
 
91
 
92
static pid_t all_pids[10];
93
static int num_pids;
94
 
95
/* fork and record the pid of the child */
96
pid_t do_fork(void)
97
{
98
        pid_t newpid = fork();
99
 
100
        if (newpid) {
101
                all_pids[num_pids++] = newpid;
102
        }
103
        return newpid;
104
}
105
 
106
/* kill all children
107
 
108
void kill_all(int sig)
109
{
110
        int i;
111
        for (i=0;i<num_pids;i++) {
112
                if (all_pids[i] != getpid())
113
                        kill(all_pids[i], sig);
114
        }
115
}
116
* */
117
#endif

powered by: WebSVN 2.1.0

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