os_sup(3)

πŸ“¦
version 29.0.6 Β· 2 versions
, in nixos 26.05, nixpkgs unstable, ubuntu stonking

✨ os_sup β€” bestie's guide to the Erlang os_sup module ✨

okay so welcome to the os_sup page from the Erlang docs, manual section 3, and yes it's the interface to OS System Messages πŸ’Œ (that's literally what NAME says). grab a strawberry πŸ“ and let's go.


πŸŽ€ NAME πŸŽ€

os_sup β€” Interface to OS System Messages. that's it, that's the name, no notes πŸ’…


🌸 DESCRIPTION 🌸

so os_sup is a process, right? and what it does is provide a message passing service from the operating system over to the error logger in the Erlang runtime system 🫢. it's part of the OS_Mon application, go look at os_mon for the whole picture. available for Solaris and Windows, and no, not everywhere else, sorry bestie 😭.

when messages come in from the OS, that results in a user defined callback function getting called πŸ“ž. that function is yours, so it can do literally whatever filtering and formatting is necessary, and then deploy any type of logging that's suitable for your application. main character energy for your callback fr fr πŸ‘‘

β˜€οΈ Solaris Operation β˜€οΈ

the Solaris (SunOS 5.x) messages get retrieved from the syslog daemon, syslogd πŸ¦‹.

enabling the service includes actions that require root privileges, like changing ownership and file privileges of an executable binary file, and creating a modified copy of the configuration file for syslogd πŸ’€. and when os_sup is terminated, the service must be disabled, which means the original configuration must be restored, no skipping that step. enabling/disabling can be done either outside or inside os_sup β€” see Configuration down below πŸ’–.

⚠️ WARNING: this process cannot run in multiple instances on the same hardware. like, at all. OS_Mon must be configured to start os_sup on one node only if two or more Erlang nodes execute on the same machine. periodt πŸ™…β€β™€οΈ

the format of received events is not defined. yep. that's the whole sentence. iconic honestly ✨

πŸͺŸ Windows Operation πŸͺŸ

the Windows messages get retrieved from the eventlog file πŸ“.

the nteventlog module is what's used to implement os_sup. go see nteventlog. but important: the start functions of nteventlog do not need to be used, because in this case the process is started automatically as part of the OS_Mon supervision tree 🌈. so don't you dare call them, they're not needed.

OS messages are formatted as a tuple {Time, Category, Facility, Severity, Message} β€” let's break that down one by one:

  • Time = {MegaSecs, Secs, MicroSecs} β€” a time stamp as returned by the BIF now/0 ⏰
  • Category = string() β€” usually one of "System", "Application" or "Security". note that the NT eventlog viewer has another notion of category, which in most cases is totally meaningless and therefore not imported into Erlang πŸ™ˆ. what's called a category here is one of the main three types of events occurring in a normal NT system.
  • Facility = string() β€” the source of the message, usually the name of the application that generated it. this could be almost any string. when you're matching messages from certain applications, the version number of the application may have to be accounted for πŸ‘€. this is what the NT event viewer calls "source".
  • Severity = string() β€” one of "Error", "Warning", "Informational", "Audit_Success", "Audit_Faulure" or, in case of a currently unknown Windows NT version, "Severity_Unknown" πŸ’…
  • Message = string() β€” formatted exactly as it would be in the NT eventlog viewer. binary data is not imported into Erlang, so don't come looking for it 🧚

βš™οΈ Configuration βš™οΈ

  • os_sup_mfa = {Module, Function, Args} β€” the callback function to use. Module and Function are atoms and Args is a list of terms. when an OS message Msg is received, this function is called as apply(Module, Function, [Msg | Args]) πŸ’–. default is {os_sup, error_report, [Tag]} which will send the event to the error logger using error_logger:error_report(Tag, Msg). and Tag is the value of os_sup_errortag, see below πŸ‘‡
  • os_sup_errortag = atom() β€” this parameter defines the error report type used when messages are sent to error logger using the default callback function. default is std_error, which means the events are handled by the standard event handler 🌸
  • os_sup_enable = bool() β€” Solaris only. defines if the service should be enabled (and disabled) inside (true) or outside (false) os_sup. for backwards compatibility reasons, the default is true 😬. the recommended value is false, as the Erlang emulator should normally not be run with root privileges, as is required for enabling the service. so like... change it, bestie, we're begging πŸ™
  • os_sup_own = string() β€” Solaris only. defines the directory which contains the backup copy and the Erlang specific configuration files for syslogd, and a named pipe to receive the messages from syslogd πŸŽ€. default is "/etc".
  • os_sup_syslogconf = string() β€” Solaris only. defines the full name of the configuration file for syslogd. default is "/etc/syslog.conf" πŸ“„

πŸ‘€ See also πŸ‘€

error_logger, os_mon

syslogd(1M), syslog.conf(4) in the Solaris documentation πŸ¦‹


πŸ”₯ FUNCTIONS πŸ”₯

disable/2

disable(Dir, Conf) -> ok | {error, Res}
                 when Dir :: string(), Conf :: string(), Res :: string().

disables the os_sup service. needed on Solaris only 🫢

if the configuration parameter os_sup_enable is false, this function is called automatically by os_sup, using the same arguments as when enable/2 was called ✨

if os_sup_enable is true, this function must be called after OS_Mon/os_sup is stopped πŸ›‘. Dir defines the directory which contains the backup copy and the Erlang specific configuration files for syslogd, and a named pipe to receive the messages from syslogd. defaults to "/etc". Conf defines the full name of the configuration file for syslogd. default is "/etc/syslog.conf" πŸ’…

results in a OS call to:

<PRIVDIR>/bin/mod_syslog nootp Dir Conf

where <PRIVDIR> is the priv directory of OS_Mon, code:priv_dir(os_mon) 🌈

returns ok if this yields the expected result "0", and {error, Res} if it yields anything else 😀

NOTE: this function requires root privileges to succeed. like, actually requires it. no cap πŸ‘‘

enable/2

enable(Dir, Conf) -> ok | {error, Res}
                 when Dir :: string(), Conf :: string(), Res :: string().

enables the os_sup service. needed on Solaris only 🫢

if the configuration parameter os_sup_enable is false, this function is called automatically by os_sup, using the values of os_sup_own and os_sup_syslogconf as arguments ✨

if os_sup_enable is true, this function must be called before OS_Mon/os_sup is started πŸš€. Dir defines the directory which contains the backup copy and the Erlang specific configuration files for syslogd, and a named pipe to receive the messages from syslogd. defaults to "/etc". Conf defines the full name of the configuration file for syslogd. default is "/etc/syslog.conf" πŸ’…

results in a OS call to:

<PRIVDIR>/bin/mod_syslog otp Dir Conf

where <PRIVDIR> is the priv directory of OS_Mon, code:priv_dir(os_mon) 🌈

returns ok if this yields the expected result "0", and {error, Res} if it yields anything else 😀

NOTE: this function requires root privileges to succeed. yes, again. still true. still root. πŸ’€

and that's the whole page bestie, you ate that πŸ½οΈπŸ’– this came to you from Ericsson AB, and it's the os_mon version 2.12 release of os_sup(3) β€” go forth and read your system messages, you got this πŸ¦‹βœ¨πŸ‘‘

πŸ“¦ where this page comes from