github.com/roboticscm/goman@v0.0.0-20210203095141-87c07b4a0a55/src/lib9/run_unix.c (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 7 #include <u.h> 8 #include <errno.h> 9 #include <sys/wait.h> 10 #define NOPLAN9DEFINES 11 #include <libc.h> 12 13 int 14 runcmd(char **argv) 15 { 16 int pid, pid1, status; 17 18 switch(pid = fork()) { 19 case -1: 20 return -1; 21 case 0: 22 execvp(argv[0], argv); 23 fprint(2, "exec %s: %r\n", argv[0]); 24 _exit(1); 25 } 26 27 while((pid1 = wait(&status)) < 0) { 28 if(errno != EINTR) { 29 werrstr("waitpid: %r"); 30 return -1; 31 } 32 } 33 if(pid1 != pid) { 34 werrstr("unexpected pid in wait"); 35 return -1; 36 } 37 if(!WIFEXITED(status) || WEXITSTATUS(status) != 0) { 38 werrstr("unsuccessful exit status %#x", status); 39 return -1; 40 } 41 return 0; 42 } 43