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