]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/toss.go
More errors checking
[nncp.git] / src / toss.go
index a7cb4570da5238586ec94647b076eb5d0f3e84dc..c0aa7bfed2fb3210c42dcff4d71e8494ffcd3ab3 100644 (file)
@@ -89,8 +89,7 @@ func (ctx *Ctx) Toss(
                        continue
                }
                pipeR, pipeW := io.Pipe()
-               errs := make(chan error, 1)
-               go func(job Job) {
+               go func(job Job) error {
                        pipeWB := bufio.NewWriter(pipeW)
                        _, _, err := PktEncRead(
                                ctx.Self,
@@ -98,13 +97,16 @@ func (ctx *Ctx) Toss(
                                bufio.NewReader(job.Fd),
                                pipeWB,
                        )
-                       errs <- err
-                       pipeWB.Flush()
-                       pipeW.Close()
-                       job.Fd.Close()
+                       job.Fd.Close() // #nosec G104
                        if err != nil {
                                ctx.LogE("rx", sds, err, "decryption")
+                               return pipeW.CloseWithError(err)
                        }
+                       if err = pipeWB.Flush(); err != nil {
+                               ctx.LogE("rx", sds, err, "decryption flush")
+                               return pipeW.CloseWithError(err)
+                       }
+                       return pipeW.Close()
                }(job)
                var pkt Pkt
                var err error
@@ -180,7 +182,9 @@ func (ctx *Ctx) Toss(
                                                cmd.Stdin = newNotification(notify, fmt.Sprintf(
                                                        "Exec from %s: %s", sender.Name, argsStr,
                                                ), output)
-                                               cmd.Run()
+                                               if err = cmd.Run(); err != nil {
+                                                       ctx.LogE("rx", sds, err, "notify")
+                                               }
                                        }
                                }
                        }
@@ -250,7 +254,11 @@ func (ctx *Ctx) Toss(
                                        isBad = true
                                        goto Closing
                                }
-                               tmp.Close()
+                               if err = tmp.Close(); err != nil {
+                                       ctx.LogE("rx", sds, err, "copy")
+                                       isBad = true
+                                       goto Closing
+                               }
                                dstPathOrig := filepath.Join(*incoming, dst)
                                dstPath := dstPathOrig
                                dstPathCtr := 0
@@ -298,7 +306,9 @@ func (ctx *Ctx) Toss(
                                                dst,
                                                humanize.IBytes(uint64(pktSize)),
                                        ), nil)
-                                       cmd.Run()
+                                       if err = cmd.Run(); err != nil {
+                                               ctx.LogE("rx", sds, err, "notify")
+                                       }
                                }
                        }
                case PktTypeFreq:
@@ -362,7 +372,9 @@ func (ctx *Ctx) Toss(
                                        cmd.Stdin = newNotification(ctx.NotifyFreq, fmt.Sprintf(
                                                "Freq from %s: %s", sender.Name, src,
                                        ), nil)
-                                       cmd.Run()
+                                       if err = cmd.Run(); err != nil {
+                                               ctx.LogE("rx", sds, err, "notify")
+                                       }
                                }
                        }
                case PktTypeTrns: