MESG(1POSIX)

πŸ’¬ MESG(1POSIX) β€” the POSIX Programmer's Manual page, bestie edition

okay so first things first: this is MESG(1POSIX), part of the POSIX Programmer's Manual, and it lives in the POSIX Programmer's Manual section 1. slay.


🌸 PROLOG 🌸

bestie, quick heads up before we even start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for details of Linux behavior), or honestly the interface may not be implemented on Linux at all. it's giving "read the fine print" energy. πŸ’…


✨ NAME ✨

mesg β€” permit or deny messages


πŸŽ€ SYNOPSIS πŸŽ€

mesg [y|n]

πŸ¦‹ DESCRIPTION πŸ¦‹

so the mesg utility shall control whether other users are allowed to send messages via write, talk, or other utilities to a terminal device.

The terminal device affected shall be determined by searching for the first terminal in the sequence of devices associated with standard input, standard output, and standard error, respectively. (so it's checking stdin, then stdout, then stderr, in that order, and whoever's a terminal first wins. main character energy.)

With no arguments, mesg shall report the current state without changing it. no touchy, just looky. πŸ™ˆ

Processes with appropriate privileges may be able to send messages to the terminal independent of the current state. so like, privileged processes don't care about your vibe check. iconic but also scary.


πŸ’… OPTIONS πŸ’…

None. literally none. no flags. no options. we're doing this the old-fashioned way, periodt.


πŸ“ OPERANDS πŸ“

The following operands shall be supported in the POSIX locale:

  • y β€” Grant permission to other users to send messages to the terminal device.
  • n β€” Deny permission to other users to send messages to the terminal device.

🌈 STDIN 🌈

Not used. nope. not reading from it. it's not the moment.


πŸ“ INPUT FILES πŸ“

None. zero. nada. nothing to see here.


πŸ’œ ENVIRONMENT VARIABLES πŸ’œ

The following environment variables shall affect the execution of mesg:

  • LANG β€” Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1‐2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
  • LC_ALL β€” If set to a non-empty string value, override the values of all the other internationalization variables. she's the boss of everyone else, lowkey.
  • LC_CTYPE β€” Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
  • LC_MESSAGES β€” Determine the locale that should be used to affect the format and contents of diagnostic messages written (by mesg) to standard error.
  • NLSPATH β€” Determine the location of message catalogs for the processing of LC_MESSAGES.

⚑ ASYNCHRONOUS EVENTS ⚑

Default. we're keeping it standard, no cap.


🫢 STDOUT 🫢

If no operand is specified, mesg shall display the current terminal state in an unspecified format. unspecified format fr fr β€” don't come for the formatting, it's not specified, that's just how it is. 😭


πŸ’€ STDERR πŸ’€

The standard error shall be used only for diagnostic messages. that's its whole job. that's its purpose. we respect it.


πŸ“‚ OUTPUT FILES πŸ“‚

None. still nothing. the filesystem is untouched, bestie.


🧚 EXTENDED DESCRIPTION 🧚

None. no extended lore. the description you got is the description you get.


πŸ‘‘ EXIT STATUS πŸ‘‘

The following exit values shall be returned:

  • 0 β€” Receiving messages is allowed.
  • 1 β€” Receiving messages is not allowed.
  • >1 β€” An error occurred.

so if you're scripting this, 0 and 1 are both answers, not errors. >1 is when something actually went wrong. iykyk. 🌟


πŸŽ€ CONSEQUENCES OF ERRORS πŸŽ€

Default.

The following sections are informative. (yes, that's the actual dividing line β€” everything after this is commentary, not spec. keep that in mind, bestie.)


πŸ”₯ APPLICATION USAGE πŸ”₯

okay so this is the juicy part. The mechanism by which the message status of the terminal is changed is unspecified. Therefore, unspecified actions may cause the status of the terminal to change after mesg has successfully completed.

These actions may include, but are not limited to:

  • another invocation of the mesg utility,
  • login procedures;
  • invocation of the stty utility,
  • invocation of the chmod utility or chmod() function,
  • and so on.

so like… you set it, and then other stuff might un-set it. that's not a bug, that's just the spec being like "we're not promising anything." πŸ’…


🌸 EXAMPLES 🌸

None. no examples. we're all just vibing with the description.


πŸ¦‹ RATIONALE πŸ¦‹

okay so the why behind all of this:

The terminal changed by mesg is that associated with the standard input, output, or error, rather than the controlling terminal for the session. This is because users logged in more than once should be able to change any of their login terminals without having to stop the job running in those sessions. This is not a security problem involving the terminals of other users because appropriate privileges would be required to affect the terminal of another user.

The method of checking each of the first three file descriptors in sequence until a terminal is found was adopted from System V.

The file /dev/tty is not specified for the terminal device because it was thought to be too restrictive. Typical environment changes for the n operand are that write permissions are removed for others and group from the appropriate device. It was decided to leave the actual description of what is done as unspecified because of potential differences between implementations.

The format for standard output is unspecified because of differences between historical implementations. This output is generally not useful to shell scripts (they can use the exit status), so exact parsing of the output is unnecessary.

tl;dr β€” the weird design choices are all on purpose, and yes, you should be using the exit status. periodt. πŸ‘‘


⭐ FUTURE DIRECTIONS ⭐

None. she's done evolving, she's perfect as she is. πŸ’…


🫢 SEE ALSO 🫢

talk, write

The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment Variables


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! πŸŽ€ this beauty came to you courtesy of IEEE/The Open Group, dated 2017 β€” so go forth and mesg responsibly. mwah. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from