github.com/apptainer/singularity@v3.1.1+incompatible/cmd/starter/c/setns.c (about)

     1  /*
     2   * Copyright (c) 2017-2019, SyLabs, Inc. All rights reserved.
     3   * Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
     4   * 
     5   * See the COPYRIGHT.md file at the top-level directory of this distribution and at
     6   * https://github.com/sylabs/singularity/blob/master/COPYRIGHT.md.
     7   * 
     8   * This file is part of the Singularity Linux container project. It is subject to the license
     9   * terms in the LICENSE.md file found in the top-level directory of this distribution and
    10   * at https://github.com/sylabs/singularity/blob/master/LICENSE.md. No part
    11   * of Singularity, including this file, may be copied, modified, propagated, or distributed
    12   * except according to the terms contained in the LICENSE.md file.
    13   * 
    14  */
    15  
    16  
    17  #define _GNU_SOURCE
    18  
    19  #include <unistd.h>
    20  #include <errno.h>
    21  #include <sys/syscall.h>
    22  
    23  #include "include/message.h"
    24  
    25  #if defined (SINGULARITY_NO_SETNS) && defined (SINGULARITY_SETNS_SYSCALL)
    26  
    27  #include "include/setns.h"
    28  
    29  int setns(int fd, int nstype) {
    30      singularity_message(DEBUG, "Using syscall() wrapped __NR_setns\n");
    31      return syscall(__NR_setns, fd, nstype);
    32  }
    33  
    34  #elif defined (SINGULARITY_NO_SETNS) && !defined (SINGULARITY_SETNS_SYSCALL)
    35  
    36  int setns(int fd, int nstype) {
    37      (void)fd;
    38      (void)nstype;
    39      singularity_message(VERBOSE, "setns() not supported at compile time by kernel at time of building\n");
    40      errno = ENOSYS;
    41      return -1;
    42  }
    43  
    44  #endif /* SINGULARITY_NO_SETNS && SINGULARITY_SETNS_SYSCALL */