summaryrefslogtreecommitdiff
path: root/src/sysdeps/tryposixspawnchdir.c
blob: 7c08346fe63eefc22f9431772065fe21cab2b483 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ISC license. */

#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE

#ifndef _XPG4_2
#define _XPG4_2
#endif

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#endif

#include <spawn.h>

int main (void)
{
  pid_t pid ;
  posix_spawn_file_actions_t actions ;
  posix_spawnattr_t attr ;
  char *const argv[2] = { "/bin/true", 0 } ;
  char *const envp[1] = { 0 } ;
  posix_spawn_file_actions_init(&actions) ;
  posix_spawn_file_actions_addchdir(&actions, "/") ;
  posix_spawn_file_actions_addfchdir(&actions, -1) ;
  return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ;
}