skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

tryposixspawnchdir.c (612B)


      1 /* ISC license. */
      2 
      3 #undef _POSIX_C_SOURCE
      4 #undef _XOPEN_SOURCE
      5 
      6 #ifndef _XPG4_2
      7 #define _XPG4_2
      8 #endif
      9 
     10 #ifndef _GNU_SOURCE
     11 #define _GNU_SOURCE
     12 #endif
     13 
     14 #ifndef _DEFAULT_SOURCE
     15 #define _DEFAULT_SOURCE
     16 #endif
     17 
     18 #include <spawn.h>
     19 
     20 int main (void)
     21 {
     22   pid_t pid ;
     23   posix_spawn_file_actions_t actions ;
     24   posix_spawnattr_t attr ;
     25   char *const argv[2] = { "/bin/true", 0 } ;
     26   char *const envp[1] = { 0 } ;
     27   posix_spawn_file_actions_init(&actions) ;
     28   posix_spawn_file_actions_addchdir(&actions, "/") ;
     29   posix_spawn_file_actions_addfchdir(&actions, -1) ;
     30   return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ;
     31 }