Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
18474f7d
Commit
18474f7d
authored
May 20, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
process: reader for stderr
Provide a mechanism for callers to read from stderr.
parent
ac07db3f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
11 deletions
+35
-11
src/util/process.h
+11
-0
src/util/unix/process.c
+24
-11
No files found.
src/util/process.h
View file @
18474f7d
...
...
@@ -106,6 +106,17 @@ extern int git_process_id(p_pid_t *out, git_process *process);
extern
ssize_t
git_process_read
(
git_process
*
process
,
void
*
buf
,
size_t
count
);
/**
* Read from the process's stderr. The process must have been created with
* `capture_err` set to true.
*
* @param process the process to read from
* @param buf the buf to read into
* @param count maximum number of bytes to read
* @return number of bytes read or an error code
*/
extern
ssize_t
git_process_read_err
(
git_process
*
process
,
void
*
buf
,
size_t
count
);
/**
* Write to the process's stdin. The process must have been created with
* `capture_in` set to true.
*
...
...
src/util/unix/process.c
View file @
18474f7d
...
...
@@ -152,7 +152,7 @@ int git_process_new(
fd = -1; \
}
static
int
try_read
(
size_t
*
out
,
int
fd
,
void
*
buf
,
size_t
len
)
static
int
try_read
_status
(
size_t
*
out
,
int
fd
,
void
*
buf
,
size_t
len
)
{
size_t
read_len
=
0
;
int
ret
=
-
1
;
...
...
@@ -179,7 +179,7 @@ static int read_status(int fd)
char
buffer
[
status_len
],
fn
[
128
];
int
error
,
fn_error
,
os_error
,
fn_len
=
0
;
if
((
error
=
try_read
(
&
read_len
,
fd
,
buffer
,
status_len
))
<
0
)
if
((
error
=
try_read
_status
(
&
read_len
,
fd
,
buffer
,
status_len
))
<
0
)
return
error
;
/* Immediate EOF indicates the exec succeeded. */
...
...
@@ -198,7 +198,7 @@ static int read_status(int fd)
if
(
fn_len
>
0
)
{
fn_len
=
min
(
fn_len
,
(
int
)(
ARRAY_SIZE
(
fn
)
-
1
));
if
((
error
=
try_read
(
&
read_len
,
fd
,
fn
,
fn_len
))
<
0
)
if
((
error
=
try_read
_status
(
&
read_len
,
fd
,
fn
,
fn_len
))
<
0
)
return
error
;
fn
[
fn_len
]
=
'\0'
;
...
...
@@ -214,7 +214,7 @@ static int read_status(int fd)
return
fn_error
;
}
static
bool
try_write
(
int
fd
,
const
void
*
buf
,
size_t
len
)
static
bool
try_write
_status
(
int
fd
,
const
void
*
buf
,
size_t
len
)
{
size_t
write_len
;
int
ret
;
...
...
@@ -246,11 +246,11 @@ static void write_status(int fd, const char *fn, int error, int os_error)
memcpy
(
&
buffer
[
sizeof
(
int
)
*
2
],
&
fn_len
,
sizeof
(
int
));
/* Do our best effort to write all the status. */
if
(
!
try_write
(
fd
,
buffer
,
status_len
))
if
(
!
try_write
_status
(
fd
,
buffer
,
status_len
))
return
;
if
(
fn_len
)
try_write
(
fd
,
fn
,
fn_len
);
try_write
_status
(
fd
,
fn
,
fn_len
);
}
int
git_process_start
(
git_process
*
process
)
...
...
@@ -370,17 +370,14 @@ int git_process_id(p_pid_t *out, git_process *process)
return
0
;
}
s
size_t
git_process_read
(
git_process
*
process
,
void
*
buf
,
size_t
count
)
s
tatic
ssize_t
process_read
(
int
fd
,
void
*
buf
,
size_t
count
)
{
ssize_t
ret
;
GIT_ASSERT_ARG
(
process
);
GIT_ASSERT
(
process
->
capture_out
);
if
(
count
>
SSIZE_MAX
)
count
=
SSIZE_MAX
;
if
((
ret
=
read
(
process
->
child_out
,
buf
,
count
))
<
0
)
{
if
((
ret
=
read
(
fd
,
buf
,
count
))
<
0
)
{
git_error_set
(
GIT_ERROR_OS
,
"could not read from child process"
);
return
-
1
;
}
...
...
@@ -388,6 +385,22 @@ ssize_t git_process_read(git_process *process, void *buf, size_t count)
return
ret
;
}
ssize_t
git_process_read
(
git_process
*
process
,
void
*
buf
,
size_t
count
)
{
GIT_ASSERT_ARG
(
process
);
GIT_ASSERT
(
process
->
capture_out
);
return
process_read
(
process
->
child_out
,
buf
,
count
);
}
ssize_t
git_process_read_err
(
git_process
*
process
,
void
*
buf
,
size_t
count
)
{
GIT_ASSERT_ARG
(
process
);
GIT_ASSERT
(
process
->
capture_err
);
return
process_read
(
process
->
child_err
,
buf
,
count
);
}
#ifdef GIT_THREADS
# define signal_state sigset_t
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment