github.com/iDigitalFlame/xmt@v0.5.4/com/pipe/xy_nix_no_crypt.go (about) 1 //go:build !windows && !crypt 2 // +build !windows,!crypt 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package pipe 21 22 import "os" 23 24 // PermEveryone is the Linux permission string used in sockets to allow anyone to write and read 25 // to the listening socket. This can be used for socket communication between privilege boundaries. 26 // This can be applied to the ListenPerm function. 27 var PermEveryone = "0766" 28 29 // Format will ensure the path for this Pipe socket fits the proper OS based pathname. Valid path names will be 30 // returned without any changes. 31 func Format(s string) string { 32 if len(s) > 0 && s[0] != '/' { 33 var ( 34 p = "/var/run/" + s 35 f, err = os.OpenFile(p, 0x242, 0600) 36 // 0x242 - CREATE | TRUNCATE | RDWR 37 ) 38 if err != nil { 39 return "/tmp/" + s 40 } 41 f.Close() 42 os.Remove(p) 43 return p 44 } 45 return s 46 }