Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github_28344065
scrcpy
提交
34550311
S
scrcpy
项目概览
github_28344065
/
scrcpy
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scrcpy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
34550311
编写于
9月 04, 2018
作者:
R
Romain Vimont
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'npes87184:dev' into dev (#236)
check adb runnable before starting scrcpy
上级
3b5e5427
55d33ddd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
93 addition
and
14 deletion
+93
-14
app/src/command.c
app/src/command.c
+22
-1
app/src/command.h
app/src/command.h
+7
-1
app/src/sys/unix/command.c
app/src/sys/unix/command.c
+57
-8
app/src/sys/win/command.c
app/src/sys/win/command.c
+7
-4
未找到文件。
app/src/command.c
浏览文件 @
34550311
...
...
@@ -18,9 +18,25 @@ static inline const char *get_adb_command() {
return
adb_command
;
}
static
void
show_adb_err_msg
(
enum
process_result
err
)
{
switch
(
err
)
{
case
PROCESS_ERROR_GENERIC
:
LOGE
(
"Failed to execute adb"
);
break
;
case
PROCESS_ERROR_MISSING_BINARY
:
LOGE
(
"'adb' command not found (make it accessible from your PATH "
"or define its full path in the ADB environment variable)"
);
break
;
case
PROCESS_SUCCESS
:
/* do nothing */
break
;
}
}
process_t
adb_execute
(
const
char
*
serial
,
const
char
*
const
adb_cmd
[],
int
len
)
{
const
char
*
cmd
[
len
+
4
];
int
i
;
process_t
process
;
cmd
[
0
]
=
get_adb_command
();
if
(
serial
)
{
cmd
[
1
]
=
"-s"
;
...
...
@@ -32,7 +48,12 @@ process_t adb_execute(const char *serial, const char *const adb_cmd[], int len)
memcpy
(
&
cmd
[
i
],
adb_cmd
,
len
*
sizeof
(
const
char
*
));
cmd
[
len
+
i
]
=
NULL
;
return
cmd_execute
(
cmd
[
0
],
cmd
);
enum
process_result
r
=
cmd_execute
(
cmd
[
0
],
cmd
,
&
process
);
if
(
r
!=
PROCESS_SUCCESS
)
{
show_adb_err_msg
(
r
);
return
PROCESS_NONE
;
}
return
process
;
}
process_t
adb_forward
(
const
char
*
serial
,
uint16_t
local_port
,
const
char
*
device_socket_name
)
{
...
...
app/src/command.h
浏览文件 @
34550311
...
...
@@ -32,7 +32,13 @@
#endif
# define NO_EXIT_CODE -1
process_t
cmd_execute
(
const
char
*
path
,
const
char
*
const
argv
[]);
enum
process_result
{
PROCESS_SUCCESS
,
PROCESS_ERROR_GENERIC
,
PROCESS_ERROR_MISSING_BINARY
,
};
enum
process_result
cmd_execute
(
const
char
*
path
,
const
char
*
const
argv
[],
process_t
*
process
);
SDL_bool
cmd_terminate
(
process_t
pid
);
SDL_bool
cmd_simple_wait
(
process_t
pid
,
exit_code_t
*
exit_code
);
...
...
app/src/sys/unix/command.c
浏览文件 @
34550311
#include "command.h"
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
...
...
@@ -7,18 +9,65 @@
#include <unistd.h>
#include "log.h"
pid_t
cmd_execute
(
const
char
*
path
,
const
char
*
const
argv
[])
{
pid_t
pid
=
fork
();
if
(
pid
==
-
1
)
{
enum
process_result
cmd_execute
(
const
char
*
path
,
const
char
*
const
argv
[],
pid_t
*
pid
)
{
int
fd
[
2
];
if
(
pipe
(
fd
)
==
-
1
)
{
perror
(
"pipe"
);
return
PROCESS_ERROR_GENERIC
;
}
enum
process_result
ret
=
PROCESS_SUCCESS
;
*
pid
=
fork
();
if
(
*
pid
==
-
1
)
{
perror
(
"fork"
);
return
-
1
;
ret
=
PROCESS_ERROR_GENERIC
;
goto
end
;
}
if
(
pid
==
0
)
{
execvp
(
path
,
(
char
*
const
*
)
argv
);
perror
(
"exec"
);
if
(
*
pid
>
0
)
{
// parent close write side
close
(
fd
[
1
]);
fd
[
1
]
=
-
1
;
// wait for EOF or receive errno from child
if
(
read
(
fd
[
0
],
&
ret
,
sizeof
(
ret
))
==
-
1
)
{
perror
(
"read"
);
ret
=
PROCESS_ERROR_GENERIC
;
goto
end
;
}
}
else
if
(
*
pid
==
0
)
{
// child close read side
close
(
fd
[
0
]);
if
(
fcntl
(
fd
[
1
],
F_SETFD
,
FD_CLOEXEC
)
==
0
)
{
execvp
(
path
,
(
char
*
const
*
)
argv
);
if
(
errno
==
ENOENT
)
{
ret
=
PROCESS_ERROR_MISSING_BINARY
;
}
else
{
ret
=
PROCESS_ERROR_GENERIC
;
}
perror
(
"exec"
);
}
else
{
perror
(
"fcntl"
);
ret
=
PROCESS_ERROR_GENERIC
;
}
// send ret to the parent
if
(
write
(
fd
[
1
],
&
ret
,
sizeof
(
ret
))
==
-
1
)
{
perror
(
"write"
);
}
// close write side before exiting
close
(
fd
[
1
]);
_exit
(
1
);
}
return
pid
;
end:
if
(
fd
[
0
]
!=
-
1
)
{
close
(
fd
[
0
]);
}
if
(
fd
[
1
]
!=
-
1
)
{
close
(
fd
[
1
]);
}
return
ret
;
}
SDL_bool
cmd_terminate
(
pid_t
pid
)
{
...
...
app/src/sys/win/command.c
浏览文件 @
34550311
...
...
@@ -4,7 +4,7 @@
#include "log.h"
#include "str_util.h"
HANDLE
cmd_execute
(
const
char
*
path
,
const
char
*
const
argv
[]
)
{
enum
process_result
cmd_execute
(
const
char
*
path
,
const
char
*
const
argv
[],
HANDLE
*
handle
)
{
STARTUPINFO
si
;
PROCESS_INFORMATION
pi
;
memset
(
&
si
,
0
,
sizeof
(
si
));
...
...
@@ -18,7 +18,8 @@ HANDLE cmd_execute(const char *path, const char *const argv[]) {
size_t
ret
=
xstrjoin
(
cmd
,
argv
,
' '
,
sizeof
(
cmd
));
if
(
ret
>=
sizeof
(
cmd
))
{
LOGE
(
"Command too long (%"
PRIsizet
" chars)"
,
sizeof
(
cmd
)
-
1
);
return
NULL
;
*
handle
=
NULL
;
return
PROCESS_ERROR_GENERIC
;
}
#ifdef WINDOWS_NOCONSOLE
...
...
@@ -27,10 +28,12 @@ HANDLE cmd_execute(const char *path, const char *const argv[]) {
int
flags
=
0
;
#endif
if
(
!
CreateProcess
(
NULL
,
cmd
,
NULL
,
NULL
,
FALSE
,
flags
,
NULL
,
NULL
,
&
si
,
&
pi
))
{
return
NULL
;
*
handle
=
NULL
;
return
PROCESS_ERROR_GENERIC
;
}
return
pi
.
hProcess
;
*
handle
=
pi
.
hProcess
;
return
PROCESS_SUCCESS
;
}
SDL_bool
cmd_terminate
(
HANDLE
handle
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录