Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
e6e67c4b
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e6e67c4b
编写于
8月 17, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 17, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4561 Remove `strerror()` function and check string size before use `substr()`.
Merge pull request !4561 from ZhangQinghua/master1
上级
b5df3b97
42218a1d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
12 deletion
+27
-12
mindspore/ccsrc/backend/session/kernel_build_client.h
mindspore/ccsrc/backend/session/kernel_build_client.h
+21
-6
mindspore/ccsrc/common/duplex_pipe.cc
mindspore/ccsrc/common/duplex_pipe.cc
+6
-6
未找到文件。
mindspore/ccsrc/backend/session/kernel_build_client.h
浏览文件 @
e6e67c4b
...
@@ -90,11 +90,18 @@ class KernelBuildClient {
...
@@ -90,11 +90,18 @@ class KernelBuildClient {
std
::
string
res
;
std
::
string
res
;
*
dp_
>>
res
;
*
dp_
>>
res
;
// Filter out the interference
// Filter out the interference
if
(
res
.
empty
())
{
MS_LOG
(
EXCEPTION
)
<<
"Response is empty"
;
}
auto
start
=
res
.
find
(
kTag
);
auto
start
=
res
.
find
(
kTag
);
if
(
start
==
std
::
string
::
npos
)
{
if
(
start
==
std
::
string
::
npos
)
{
MS_LOG
(
EXCEPTION
)
<<
"Response seems incorrect, res: "
<<
res
;
MS_LOG
(
EXCEPTION
)
<<
"Response seems incorrect, res: "
<<
res
;
}
}
res
=
res
.
substr
(
start
+
std
::
strlen
(
kTag
),
res
.
size
()
-
start
);
auto
pos
=
start
+
std
::
strlen
(
kTag
);
if
(
pos
>
res
.
size
())
{
// Safe check for codedex
MS_LOG
(
EXCEPTION
)
<<
"Response seems incorrect, res("
<<
res
.
size
()
<<
"): {"
<<
res
<<
"}, start: "
<<
start
;
}
res
=
res
.
substr
(
pos
);
// Revert the line feed and space
// Revert the line feed and space
if
(
res
!=
kSuccess
&&
res
!=
kAck
&&
res
!=
kErr
&&
res
!=
kTrue
)
{
if
(
res
!=
kSuccess
&&
res
!=
kAck
&&
res
!=
kErr
&&
res
!=
kTrue
)
{
ReplaceStr
(
&
res
,
kLF
,
'\n'
);
ReplaceStr
(
&
res
,
kLF
,
'\n'
);
...
@@ -113,25 +120,30 @@ class KernelBuildClient {
...
@@ -113,25 +120,30 @@ class KernelBuildClient {
std
::
shared_ptr
<
DuplexPipe
>
dp_
;
std
::
shared_ptr
<
DuplexPipe
>
dp_
;
};
};
static
inline
std
::
string
GetScriptFilePath
(
const
std
::
string
cmd_env
,
const
std
::
string
&
cmd_script
)
{
static
std
::
string
GetScriptFilePath
(
const
std
::
string
cmd_env
,
const
std
::
string
&
cmd_script
)
{
std
::
string
cmd
=
cmd_env
;
std
::
string
cmd
=
cmd_env
;
(
void
)
cmd
.
append
(
1
,
' '
).
append
(
cmd_script
);
(
void
)
cmd
.
append
(
1
,
' '
).
append
(
cmd_script
);
FILE
*
fpipe
=
popen
(
cmd
.
c_str
(),
"r"
);
FILE
*
fpipe
=
popen
(
cmd
.
c_str
(),
"r"
);
if
(
fpipe
==
nullptr
)
{
if
(
fpipe
==
nullptr
)
{
MS_LOG
(
EXCEPTION
)
<<
"popen failed,
"
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
MS_LOG
(
EXCEPTION
)
<<
"popen failed,
errno: "
<<
errno
;
}
}
bool
start
=
false
;
bool
start
=
false
;
std
::
string
result
;
std
::
string
result
;
char
buf
[
kBufferSize
];
char
buf
[
kBufferSize
];
while
(
std
::
fgets
(
buf
,
sizeof
(
buf
),
fpipe
)
!=
nullptr
)
{
while
(
std
::
fgets
(
buf
,
sizeof
(
buf
),
fpipe
)
!=
nullptr
)
{
auto
len
=
std
::
strlen
(
buf
);
if
(
len
==
0
||
len
>=
kBufferSize
)
{
// Safe check for codedex
// Should never reach here
MS_LOG
(
EXCEPTION
)
<<
"fgets() failed, len: "
<<
len
<<
", errno: "
<<
errno
;
}
if
(
std
::
strncmp
(
buf
,
kTag
,
std
::
strlen
(
kTag
))
==
0
)
{
if
(
std
::
strncmp
(
buf
,
kTag
,
std
::
strlen
(
kTag
))
==
0
)
{
start
=
true
;
start
=
true
;
}
}
// Filter with 'kTAG' and '\n'
// Filter with 'kTAG' and '\n'
if
(
start
)
{
if
(
start
)
{
auto
size
=
std
::
strlen
(
buf
);
bool
line_end
=
buf
[
len
-
1
]
==
'\n'
;
bool
line_end
=
buf
[
size
-
1
]
==
'\n'
;
result
.
append
(
buf
,
line_end
?
len
-
1
:
len
);
result
.
append
(
buf
,
line_end
?
size
-
1
:
size
);
if
(
line_end
)
{
if
(
line_end
)
{
break
;
break
;
}
}
...
@@ -142,6 +154,9 @@ static inline std::string GetScriptFilePath(const std::string cmd_env, const std
...
@@ -142,6 +154,9 @@ static inline std::string GetScriptFilePath(const std::string cmd_env, const std
if
(
result
.
empty
()
||
result
.
rfind
(
py_suffix
)
!=
(
result
.
length
()
-
py_suffix
.
length
()))
{
if
(
result
.
empty
()
||
result
.
rfind
(
py_suffix
)
!=
(
result
.
length
()
-
py_suffix
.
length
()))
{
MS_LOG
(
EXCEPTION
)
<<
"py file seems incorrect, result: {"
<<
result
<<
"}"
;
MS_LOG
(
EXCEPTION
)
<<
"py file seems incorrect, result: {"
<<
result
<<
"}"
;
}
}
if
(
strlen
(
kTag
)
>
result
.
size
())
{
// Safe check for codedex
MS_LOG
(
EXCEPTION
)
<<
"result size seems incorrect, result("
<<
result
.
size
()
<<
"): {"
<<
result
<<
"}"
;
}
result
=
result
.
substr
(
strlen
(
kTag
));
result
=
result
.
substr
(
strlen
(
kTag
));
MS_LOG
(
DEBUG
)
<<
"result: "
<<
result
;
MS_LOG
(
DEBUG
)
<<
"result: "
<<
result
;
return
result
;
return
result
;
...
...
mindspore/ccsrc/common/duplex_pipe.cc
浏览文件 @
e6e67c4b
...
@@ -24,12 +24,12 @@
...
@@ -24,12 +24,12 @@
namespace
mindspore
{
namespace
mindspore
{
int
DuplexPipe
::
Open
(
std
::
initializer_list
<
std
::
string
>
arg_list
,
bool
append_fds
)
{
int
DuplexPipe
::
Open
(
std
::
initializer_list
<
std
::
string
>
arg_list
,
bool
append_fds
)
{
if
(
pipe
(
fd1_
)
==
-
1
)
{
if
(
pipe
(
fd1_
)
==
-
1
)
{
DP_EXCEPTION
<<
"pipe 1 failed,
"
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
DP_EXCEPTION
<<
"pipe 1 failed,
errno: "
<<
errno
;
}
}
if
(
pipe
(
fd2_
)
==
-
1
)
{
if
(
pipe
(
fd2_
)
==
-
1
)
{
close
(
fd1_
[
0
]);
close
(
fd1_
[
0
]);
close
(
fd1_
[
1
]);
close
(
fd1_
[
1
]);
DP_EXCEPTION
<<
"pipe 2 failed,
"
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
DP_EXCEPTION
<<
"pipe 2 failed,
errno: "
<<
errno
;
}
}
pid_
=
fork
();
pid_
=
fork
();
...
@@ -38,7 +38,7 @@ int DuplexPipe::Open(std::initializer_list<std::string> arg_list, bool append_fd
...
@@ -38,7 +38,7 @@ int DuplexPipe::Open(std::initializer_list<std::string> arg_list, bool append_fd
close
(
fd1_
[
1
]);
close
(
fd1_
[
1
]);
close
(
fd2_
[
0
]);
close
(
fd2_
[
0
]);
close
(
fd2_
[
1
]);
close
(
fd2_
[
1
]);
DP_EXCEPTION
<<
"fork failed,
"
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
DP_EXCEPTION
<<
"fork failed,
errno: "
<<
errno
;
}
else
if
(
pid_
==
0
)
{
// Remote process
}
else
if
(
pid_
==
0
)
{
// Remote process
DP_INFO
<<
"Remote process, pid: "
<<
getpid
()
<<
", "
<<
fd1_
[
0
]
<<
"/"
<<
fd2_
[
1
];
DP_INFO
<<
"Remote process, pid: "
<<
getpid
()
<<
", "
<<
fd1_
[
0
]
<<
"/"
<<
fd2_
[
1
];
remote_stdout_
=
dup
(
STDOUT_FILENO
);
remote_stdout_
=
dup
(
STDOUT_FILENO
);
...
@@ -61,7 +61,7 @@ int DuplexPipe::Open(std::initializer_list<std::string> arg_list, bool append_fd
...
@@ -61,7 +61,7 @@ int DuplexPipe::Open(std::initializer_list<std::string> arg_list, bool append_fd
}
}
args
.
emplace_back
(
nullptr
);
args
.
emplace_back
(
nullptr
);
if
(
execvp
(
args
[
0
],
const_cast
<
char
*
const
*>
(
&
args
[
0
]))
==
-
1
)
{
if
(
execvp
(
args
[
0
],
const_cast
<
char
*
const
*>
(
&
args
[
0
]))
==
-
1
)
{
DP_EXCEPTION
<<
"execute "
<<
args
[
0
]
<<
" failed,
"
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
DP_EXCEPTION
<<
"execute "
<<
args
[
0
]
<<
" failed,
errno: "
<<
errno
;
}
}
}
else
{
// Local process
}
else
{
// Local process
DP_INFO
<<
"Local process, id: "
<<
getpid
()
<<
", "
<<
fd2_
[
0
]
<<
"/"
<<
fd1_
[
1
];
DP_INFO
<<
"Local process, id: "
<<
getpid
()
<<
", "
<<
fd2_
[
0
]
<<
"/"
<<
fd1_
[
1
];
...
@@ -77,13 +77,13 @@ int DuplexPipe::Open(std::initializer_list<std::string> arg_list, bool append_fd
...
@@ -77,13 +77,13 @@ int DuplexPipe::Open(std::initializer_list<std::string> arg_list, bool append_fd
void
DuplexPipe
::
Write
(
const
std
::
string
&
buf
,
bool
flush
)
{
void
DuplexPipe
::
Write
(
const
std
::
string
&
buf
,
bool
flush
)
{
// Write the string into pipe
// Write the string into pipe
if
(
write
(
fd1_
[
1
],
buf
.
data
(),
buf
.
size
())
==
-
1
)
{
if
(
write
(
fd1_
[
1
],
buf
.
data
(),
buf
.
size
())
==
-
1
)
{
DP_ERROR
<<
"write failed, err
or: "
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
DP_ERROR
<<
"write failed, err
no: "
<<
errno
;
return
;
return
;
}
}
if
(
flush
)
{
if
(
flush
)
{
// Flush into the pipe
// Flush into the pipe
if
(
write
(
fd1_
[
1
],
"
\n
"
,
1
)
==
-
1
)
{
if
(
write
(
fd1_
[
1
],
"
\n
"
,
1
)
==
-
1
)
{
DP_ERROR
<<
"write failed, err
or: "
<<
strerror
(
errno
)
<<
"("
<<
errno
<<
")"
;
DP_ERROR
<<
"write failed, err
no: "
<<
errno
;
return
;
return
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录