on Catalina, golang program cannot open /dev/stdout

Hi - I have a Golang program that runs successfully on OSX releases before Catalina, but in Catalina it cannot open /dev/stdout. I believe this may be related to the increased security features in Catalina.


Does anyone know of a work around?


(As background, this relates to the Blockchain Hyperledger Fabric and the program configtxlator)


Thanks

MacBook Pro 13”, macOS 10.15

Posted on Feb 13, 2020 2:40 PM

Reply
2 replies
Sort By: 

Feb 13, 2020 5:47 PM in response to Rick_Hull

Why are you using a file reference to /dev/stdout as opposed to just using the GoLang standard functions for writing to standard output?


https://github.com/sylabs/singularity/issues/3606


https://github.com/sylabs/singularity/issues/3606  

This bug mentions a problem with ioctl. Are you using pipes or redirects? The error appears to be "bash: [66338: 2] tcsetattr: Inappropriate ioctl for device"


https://www.unix.com/shell-programming-and-scripting/20812-inappropriate-ioctl-device.html


According to what I can understand, it appears that /dev/stdout and /dev/stderr are now explicitly defined as *not* being a TTY port but receiving a command that is only valid for TTY devices. If you write a Go program that only opens /dev/stdout/, sends a string, and then closes the device, what happens. What functions are you using to open and close the device and send data?

Reply

Feb 13, 2020 6:09 PM in response to Bradley Ross

Thank you for this response! The examples you point to confirm that the code I am trying to run is running into a known situation with OSX Catalina (and perhaps other versions)


Actually, I didn't write the code myself, and I am by no means a GO expert. Rather, the code is part of the release-1.4 of the Hyperledger Fabric (open source Blockchain codebase driven in large part by IBM).


Here are lines 44 to 52 of the file in hyperledger/fabric release-1.4 main.go file in common/tools/configtxlator (see https://github.com/hyperledger/fabric/blob/release-1.4/common/tools/configtxlator/main.go)

The 4th and 9th lines below appear to be the problematic ones.

=================

protoEncode = app.Command("proto_encode", "Converts a JSON document to protobuf.")

protoEncodeType = protoEncode.Flag("type", "The type of protobuf structure to encode to. For example, 'common.Config'.").Required().String()

protoEncodeSource = protoEncode.Flag("input", "A file containing the JSON document.").Default(os.Stdin.Name()).File()

protoEncodeDest = protoEncode.Flag("output", "A file to write the output to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)


protoDecode = app.Command("proto_decode", "Converts a proto message to JSON.")

protoDecodeType = protoDecode.Flag("type", "The type of protobuf structure to decode from. For example, 'common.Config'.").Required().String()

protoDecodeSource = protoDecode.Flag("input", "A file containing the proto message.").Default(os.Stdin.Name()).File()

protoDecodeDest = protoDecode.Flag("output", "A file to write the JSON document to.").Default(os.Stdout.Name()).OpenFile(os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)

=================


I believe that this works on most linux systems (e.g., ubuntu) and probably older versions of OSX. When I run the program on Catalina I get the error "configtxlator: error: open /dev/stdout: permission denied, try --help", which is being generated by the GO code somewhere. Also, a file is supposed to be written into a local directory, but when I run the code the file is created but ends up being empty.


I am supposing that the use of stdout is for some logging/feedback, and perhaps that is unimportant. I suppose I could rewrite the code to simply write to the target file and not bother with any logging, at least not any logging to /dev/stdout.


Thanks


Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

on Catalina, golang program cannot open /dev/stdout

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.