gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/syscalls/linux/exec_proc_exe_workload.cc (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <stdlib.h> 16 #include <unistd.h> 17 18 #include <iostream> 19 20 #include "test/util/fs_util.h" 21 #include "test/util/posix_error.h" 22 23 int main(int argc, char** argv, char** envp) { 24 // This is annoying. Because remote build systems may put these binaries 25 // in a content-addressable-store, you may wind up with /proc/self/exe 26 // pointing to some random path (but with a sensible argv[0]). 27 // 28 // Therefore, this test simply checks that the /proc/self/exe 29 // is absolute and *doesn't* match argv[1]. 30 std::string exe = 31 gvisor::testing::ProcessExePath(getpid()).ValueOrDie(); 32 if (exe[0] != '/') { 33 std::cerr << "relative path: " << exe << std::endl; 34 exit(1); 35 } 36 if (exe.find(argv[1]) != std::string::npos) { 37 std::cerr << "matching path: " << exe << std::endl; 38 exit(1); 39 } 40 41 return 0; 42 }