github.com/rohankumardubey/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/lib9/run_plan9.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 #include <u.h> 6 #include <libc.h> 7 8 int 9 runcmd(char **argv) 10 { 11 int pid; 12 Waitmsg *w; 13 14 switch(pid = fork()) { 15 case -1: 16 return -1; 17 case 0: 18 exec(argv[0], argv); 19 fprint(2, "exec %s: %r\n", argv[0]); 20 exits("exec"); 21 } 22 23 w = wait(); 24 if(w == nil) 25 return -1; 26 if(w->pid != pid) { 27 werrstr("unexpected pid in wait"); 28 free(w); 29 return -1; 30 } 31 if(w->msg[0]) { 32 werrstr("unsuccessful exit status: %s", w->msg); 33 free(w); 34 return -1; 35 } 36 free(w); 37 return 0; 38 }