io.WriteString(c, fmt.Sprintf("channel send #%d\n", <-ch));
}
+// exec a program, redirecting output
+func DateServer(c *http.Conn, req *http.Request) {
+ c.SetHeader("content-type", "text/plain; charset=utf-8");
+ r, w, err := os.Pipe();
+ if err != nil {
+ fmt.Fprintf(c, "pipe: %s\n", err);
+ return;
+ }
+ pid, err := os.ForkExec("/bin/date", []string{"date"}, os.Environ(), "", []*os.File{nil, w, w});
+ defer r.Close();
+ w.Close();
+ if err != nil {
+ fmt.Fprintf(c, "fork/exec: %s\n", err);
+ return;
+ }
+ io.Copy(r, c);
+ wait, err := os.Wait(pid, 0);
+ if err != nil {
+ fmt.Fprintf(c, "wait: %s\n", err);
+ return;
+ }
+ if !wait.Exited() || wait.ExitStatus() != 0 {
+ fmt.Fprintf(c, "date: %v\n", wait);
+ return;
+ }
+}
+
func main() {
flag.Parse();
http.Handle("/args", http.HandlerFunc(ArgServer));
http.Handle("/go/hello", http.HandlerFunc(HelloServer));
http.Handle("/chan", ChanCreate());
+ http.Handle("/date", http.HandlerFunc(DateServer));
err := http.ListenAndServe(":12345", nil);
if err != nil {
log.Crash("ListenAndServe: ", err)
Tmach_semdestroy = 3419,
Rmach_semdestroy = Tmach_semdestroy + Reply,
+
+ KERN_ABORTED = 14,
};
typedef struct Tmach_semcreateMsg Tmach_semcreateMsg;
m.tx.policy = 0; // 0 = SYNC_POLICY_FIFO
m.tx.value = 0;
- if((r = machcall(&m.tx.h, sizeof m, sizeof(m.rx))) != 0)
+ while((r = machcall(&m.tx.h, sizeof m, sizeof(m.rx))) != 0){
+ if(r == KERN_ABORTED) // interrupted
+ continue;
macherror(r, "semaphore_create");
+ }
if(m.rx.body.msgh_descriptor_count != 1)
unimplemented("mach_semcreate desc count");
return m.rx.semaphore.name;
m.tx.semaphore.disposition = MACH_MSG_TYPE_MOVE_SEND;
m.tx.semaphore.type = 0;
- if((r = machcall(&m.tx.h, sizeof m, 0)) != 0)
+ while((r = machcall(&m.tx.h, sizeof m, 0)) != 0){
macherror(r, "semaphore_destroy");
+ }
}
// The other calls have simple system call traps in sys.s
{
int32 r;
- if((r = mach_semaphore_wait(sem)) != 0)
+ while((r = mach_semaphore_wait(sem)) != 0) {
+ if(r == KERN_ABORTED) // interrupted
+ continue;
macherror(r, "semaphore_wait");
+ }
}
void
{
int32 r;
- if((r = mach_semaphore_signal(sem)) != 0)
+ while((r = mach_semaphore_signal(sem)) != 0) {
+ if(r == KERN_ABORTED) // interrupted
+ continue;
macherror(r, "semaphore_signal");
+ }
}