]> Sergey Matveev's repositories - mmc.git/commitdiff
Do not delete FIFOs, why?
authorSergey Matveev <stargrave@stargrave.org>
Mon, 13 Mar 2023 16:15:05 +0000 (19:15 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 13 Mar 2023 16:15:05 +0000 (19:15 +0300)
cmd/mmc/main.go
cmd/start

index 159674709388922f2030b490877657ed2e744991..9748be35d202e49a8d8d206c60fb92d35d80acec 100644 (file)
@@ -58,6 +58,15 @@ func rewriteIfChanged(fn string, data string) {
        }
 }
 
+func mkFifo(pth string) {
+       if _, err := os.Stat(pth); err == nil {
+               return
+       }
+       if err := syscall.Mkfifo(pth, 0666); err != nil {
+               log.Fatalln(err)
+       }
+}
+
 func main() {
        entrypoint := flag.String("entrypoint", mmc.GetEntrypoint(), "Entrypoint")
        notifyCmd := flag.String("notify", "cmd/notify", "Path to notification handler")
@@ -68,11 +77,8 @@ func main() {
        UmaskCur = syscall.Umask(0)
        syscall.Umask(UmaskCur)
 
-       os.Remove("debug")
-       err := syscall.Mkfifo("debug", 0666)
-       if err != nil {
-               log.Fatalln(err)
-       }
+       mkFifo("debug")
+       var err error
        DebugFd, err = os.OpenFile(
                "debug", os.O_WRONLY|os.O_APPEND, os.FileMode(0666),
        )
@@ -150,10 +156,7 @@ func main() {
                }
 
                usersPth := path.Join(pth, "users")
-               os.Remove(usersPth)
-               if err := syscall.Mkfifo(usersPth, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(usersPth)
                go func(ch *model.Channel) {
                        for {
                                time.Sleep(mmc.SleepTime)
@@ -189,10 +192,7 @@ func main() {
                }(ch)
 
                pth = path.Join(pth, "in")
-               os.Remove(pth)
-               if err := syscall.Mkfifo(pth, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(pth)
                go func(ch *model.Channel) {
                        for {
                                fd, err := os.OpenFile(pth, os.O_RDONLY, os.FileMode(0666))
@@ -253,10 +253,7 @@ func main() {
                }
 
                statusPth := path.Join(pth, "status")
-               os.Remove(statusPth)
-               if err := syscall.Mkfifo(statusPth, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(statusPth)
                go func(u *model.User) {
                        for {
                                time.Sleep(mmc.SleepTime)
@@ -285,10 +282,7 @@ func main() {
                }(u)
 
                pth = path.Join(pth, "in")
-               os.Remove(pth)
-               if err := syscall.Mkfifo(pth, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(pth)
                go func(u *model.User) {
                        var dc *model.Channel
                        for {
@@ -327,10 +321,7 @@ func main() {
        var UserStatusM sync.RWMutex
        go func() {
                pth := path.Join("users", "status")
-               os.Remove(pth)
-               if err := syscall.Mkfifo(pth, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(pth)
                for {
                        time.Sleep(mmc.SleepTime)
                        fd, err := os.OpenFile(pth, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
@@ -368,15 +359,9 @@ func main() {
        go func() {
                os.MkdirAll("file", 0777)
                pthGet := path.Join("file", "get")
-               os.Remove(pthGet)
-               if err := syscall.Mkfifo(pthGet, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(pthGet)
                pthOut := path.Join("file", "out")
-               os.Remove(pthOut)
-               if err := syscall.Mkfifo(pthOut, 0666); err != nil {
-                       log.Fatalln(err)
-               }
+               mkFifo(pthOut)
                for {
                        time.Sleep(mmc.SleepTime)
                        fd, err := os.OpenFile(pthGet, os.O_RDONLY, os.FileMode(0666))
index 64648f0abcb6aa0df1fb8e4aa589a06425db47da..072509715d6789bb79bc10a6a8890dff946992f0 100755 (executable)
--- a/cmd/start
+++ b/cmd/start
@@ -4,12 +4,11 @@ cmd="$(dirname "$(realpath -- "$0")")"
 unset TMUX
 TMUX="tmux -S tmux.sock"
 $TMUX has-session -t mmc 2>/dev/null && exit
-find . -type p -delete
 [ -s tmux.conf ] || sed \
     -e "s#NEWWIN#$cmd/newwin#" \
     -e "s#CATFILE#$cmd/catfile#" \
     -e "s#DLPANE#$cmd/dlpane#" < "$cmd"/tmux.conf > tmux.conf
 $TMUX -f tmux.conf new-session -d -n ROOT -s mmc "while : ; do sleep 1 ; cat debug | tai64n | tai64nlocal ; done"
 $TMUX split-window -h 'while : ; do sleep 10 ; clear ; cat users/status | spc -e grn,"^online:.*" -e cya,"^away:.*" ; done'
-$TMUX split-window -v "while : ; do $cmd/mmc/mmc -newwin $cmd/newwin -notify $cmd/notify | tai64n | tai64nlocal ; printf \"\\a\" ; sleep 1 ; done"
+$TMUX split-window -v "while : ; do $cmd/mmc/mmc -newwin $cmd/newwin -notify $cmd/notify | tai64n | tai64nlocal ; printf \"\\a\" ; sleep 10 ; done"
 $TMUX attach-session