gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/benchmarks/tcp/nsjoin.c (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  #ifndef _GNU_SOURCE
    16  #define _GNU_SOURCE
    17  #endif
    18  
    19  #include <errno.h>
    20  #include <fcntl.h>
    21  #include <sched.h>
    22  #include <stdio.h>
    23  #include <string.h>
    24  #include <sys/stat.h>
    25  #include <sys/types.h>
    26  #include <unistd.h>
    27  
    28  int main(int argc, char** argv) {
    29    if (argc <= 2) {
    30      fprintf(stderr, "error: must provide a namespace file.\n");
    31      fprintf(stderr, "usage: %s <file> [arguments...]\n", argv[0]);
    32      return 1;
    33    }
    34  
    35    int fd = open(argv[1], O_RDONLY);
    36    if (fd < 0) {
    37      fprintf(stderr, "error opening %s: %s\n", argv[1], strerror(errno));
    38      return 1;
    39    }
    40    if (setns(fd, 0) < 0) {
    41      fprintf(stderr, "error joining %s: %s\n", argv[1], strerror(errno));
    42      return 1;
    43    }
    44  
    45    execvp(argv[2], &argv[2]);
    46    return 1;
    47  }