cmake找不到sudo

时间:2018-05-17 18:49:04

标签: linux cmake sudo

我正在尝试通过sudo运行一些测试,因为它们需要网络管理员权限,我不能使用setcap,因为我们在valgrind下运行了几个这些测试,这些测试无法在setcap可执行文件上运行。由于某种原因,没有找到sudo。当从bash终端或C应用程序中的system()调用调用时,sudo按预期工作。

示例CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)

enable_testing()

add_test(NAME dummy_test
    COMMAND sudo ls
)

输出:

$ make test
Running tests...
Test project /home/cmorgan/projects/test/build
    Start 1: dummy_test
Could not find executable sudo
Looked in the following places:
sudo
sudo
Release/sudo
Release/sudo
Debug/sudo
Debug/sudo
MinSizeRel/sudo
MinSizeRel/sudo
RelWithDebInfo/sudo
RelWithDebInfo/sudo
Deployment/sudo
Deployment/sudo
Development/sudo
Development/sudo
Unable to find executable: sudo
1/1 Test #1: dummy_test .......................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.00 sec

The following tests FAILED:
      1 - dummy_test (Not Run)
Errors while running CTest
make: *** [Makefile:73: test] Error 8

我尝试使用sudo的绝对路径,/ usr / bin / sudo也有同样的问题。

这看起来可能与sudo是一个setuid应用程序有关,但我不确定如何继续。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,这是由sudo二进制文件没有read权限引起的。如果运行它,则可以,但是cmake会变得聪明,因此会失败。解决方法:

sudo chmod +r /usr/bin/sudo

Centos 6是sudo不具有read权限的此类系统的示例。