Bug 250405 - su -c: inaccurate manpage
Summary: su -c: inaccurate manpage
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.1-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Mateusz Piotrowski
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-16 20:04 UTC by Zsolt Udvari
Modified: 2020-10-25 12:32 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zsolt Udvari 2020-10-16 20:04:51 UTC
The su(1) writes:
  The options are as	follows:

     -c	class
	     Use the settings of the specified login class.  The login class
	     must be defined in	login.conf(5).	Only allowed for the super-
	     user.


But in the examples:
     su -m operator -c poweroff
            Starts a shell as user operator, and runs the command poweroff.

So the "-c" doesn't specify the login class instead with it can run a command as an another user.
Comment 1 Bob Bishop 2020-10-16 20:28:46 UTC
Not a bug. In the example you quote, the -c is not an option to su but an arg to the invoked shell. The third example should make this clear.
Comment 2 Steve Wills freebsd_committer 2020-10-16 20:30:58 UTC
I've made this mistake reading the man page too. I wonder how we could improve the wording to make it more clear or perhaps change the syntax? It is confusing.
Comment 3 Bob Bishop 2020-10-16 21:05:03 UTC
(In reply to Steve Wills from comment #2)

Since you can run any command as an arg to (the shell invoked by) su, it's unfortunately impossible to make the sets of options disjoint. Consider eg the contrived:

su -c staff fred -c "ls -c"

which has three option spaces.
Comment 4 Zsolt Udvari 2020-10-17 08:36:49 UTC
(In reply to Bob Bishop from comment #1)
Indeed. And the description of example describes it too (but I didn't read it).

As Steve wrote it's confusing. Maybe one sentence in the "-c class" section in manpage would be clear.

Sorry for unnecessary report.
Comment 5 Ed Maste freebsd_committer 2020-10-19 16:57:13 UTC

*** This bug has been marked as a duplicate of bug 6859 ***
Comment 6 Ed Maste freebsd_committer 2020-10-19 16:58:40 UTC
The examples in the man page try to make the distinction clear:

> In this example, -c is passed to the shell of the user "operator", and is not interpreted as an argument to su.

> (Most shells expect the argument to -c to be a single word).

> Note: in this example, the first -c option applies to su while the second is an argument to the shell being invoked.
Comment 7 Ed Maste freebsd_committer 2020-10-19 17:04:50 UTC
I'll accept that there's clearly still an opportunity for confusion here (as demonstrated by the existence of this PR). That said, the issue is described in each of the three examples that have a `-c` argument and I'm not quite sure how to make this more clear. I'm happy to update the man page if we can come up with good suggestions.
Comment 8 Zsolt Udvari 2020-10-19 20:00:37 UTC
I was inattentive when didn't read (the perfect) explanation in examples.

Maybe only one sentence in "-c":
Note it's possible to run a command inside invoked shell usually with shell(!) option "-c". See more in EXAMPLES section.
(Sorry for incorrect english - I hope it's clear)
Comment 9 Mateusz Piotrowski freebsd_committer 2020-10-20 07:15:45 UTC
(In reply to Ed Maste from comment #7)
I'm sitting on a patch for the su(1) manual to improve the description a bit. I'll post it soon when I polish it a bit.
Comment 10 Ed Maste freebsd_committer 2020-10-21 14:26:10 UTC
Reopen as 0mp is working on a patch.
Comment 11 Mateusz Piotrowski freebsd_committer 2020-10-25 12:32:44 UTC
I've posted a draft to phabricator so that the patch does not get lost on my disk.

https://reviews.freebsd.org/D26941