6
6
#include "archive.h"
7
7
#include "pkt-line.h"
8
8
#include "sideband.h"
9
+ #include "run-command.h"
9
10
10
11
static const char upload_archive_usage [] =
11
12
"git upload-archive <repo>" ;
12
13
13
14
static const char deadchild [] =
14
15
"git upload-archive: archiver died with error" ;
15
16
16
- static const char lostchild [] =
17
- "git upload-archive: archiver process was lost" ;
18
-
19
17
#define MAX_ARGS (64)
20
18
21
- static int run_upload_archive (int argc , const char * * argv , const char * prefix )
19
+ int cmd_upload_archive_writer (int argc , const char * * argv , const char * prefix )
22
20
{
23
21
const char * sent_argv [MAX_ARGS ];
24
22
const char * arg_cmd = "argument " ;
@@ -96,48 +94,33 @@ static ssize_t process_input(int child_fd, int band)
96
94
97
95
int cmd_upload_archive (int argc , const char * * argv , const char * prefix )
98
96
{
99
- pid_t writer ;
100
- int fd1 [ 2 ], fd2 [ 2 ];
97
+ struct child_process writer = { argv } ;
98
+
101
99
/*
102
100
* Set up sideband subprocess.
103
101
*
104
102
* We (parent) monitor and read from child, sending its fd#1 and fd#2
105
103
* multiplexed out to our fd#1. If the child dies, we tell the other
106
104
* end over channel #3.
107
105
*/
108
- if (pipe (fd1 ) < 0 || pipe (fd2 ) < 0 ) {
109
- int err = errno ;
110
- packet_write (1 , "NACK pipe failed on the remote side\n" );
111
- die ("upload-archive: %s" , strerror (err ));
112
- }
113
- writer = fork ();
114
- if (writer < 0 ) {
106
+ argv [0 ] = "upload-archive--writer" ;
107
+ writer .out = writer .err = -1 ;
108
+ writer .git_cmd = 1 ;
109
+ if (start_command (& writer )) {
115
110
int err = errno ;
116
- packet_write (1 , "NACK fork failed on the remote side \n" );
111
+ packet_write (1 , "NACK unable to spawn subprocess \n" );
117
112
die ("upload-archive: %s" , strerror (err ));
118
113
}
119
- if (!writer ) {
120
- /* child - connect fd#1 and fd#2 to the pipe */
121
- dup2 (fd1 [1 ], 1 );
122
- dup2 (fd2 [1 ], 2 );
123
- close (fd1 [1 ]); close (fd2 [1 ]);
124
- close (fd1 [0 ]); close (fd2 [0 ]); /* we do not read from pipe */
125
-
126
- exit (run_upload_archive (argc , argv , prefix ));
127
- }
128
114
129
- /* parent - read from child, multiplex and send out to fd#1 */
130
- close (fd1 [1 ]); close (fd2 [1 ]); /* we do not write to pipe */
131
115
packet_write (1 , "ACK\n" );
132
116
packet_flush (1 );
133
117
134
118
while (1 ) {
135
119
struct pollfd pfd [2 ];
136
- int status ;
137
120
138
- pfd [0 ].fd = fd1 [ 0 ] ;
121
+ pfd [0 ].fd = writer . out ;
139
122
pfd [0 ].events = POLLIN ;
140
- pfd [1 ].fd = fd2 [ 0 ] ;
123
+ pfd [1 ].fd = writer . err ;
141
124
pfd [1 ].events = POLLIN ;
142
125
if (poll (pfd , 2 , -1 ) < 0 ) {
143
126
if (errno != EINTR ) {
@@ -156,9 +139,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
156
139
if (process_input (pfd [0 ].fd , 1 ))
157
140
continue ;
158
141
159
- if (waitpid (writer , & status , 0 ) < 0 )
160
- error_clnt ("%s" , lostchild );
161
- else if (!WIFEXITED (status ) || WEXITSTATUS (status ) > 0 )
142
+ if (finish_command (& writer ))
162
143
error_clnt ("%s" , deadchild );
163
144
packet_flush (1 );
164
145
break ;
0 commit comments