Compare commits

...

4 Commits

Author SHA1 Message Date
Michael Kerrisk 44a16bcb61 pthread_setname_np.3: EXAMPLES: remove a bug by simplify the code
From an email conversation with Alexis:

Hello Alexis,

On 8/6/21 7:06 PM, Alexis Wilke wrote:
> Hi guys,
>
> The pthread_setname_np(3) manual page has an example where the second
> argument is used to get a size of the thread name.
>
> https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html#EXAMPLES
>
> The current code:
>
>            rc = pthread_getname_np(thread, thread_name,
>                                    (argc > 2) ? atoi(argv[1]) : NAMELEN);
>
> The suggested code:
>
>            rc = pthread_getname_np(thread, thread_name,
>                                    (argc > 2) ? atoi(argv[2]) : NAMELEN);

I agree that there's a problem, but I think we could go even simpler:

     rc = pthread_getname_np(thread, thread_name, NAMELEN);

> I'm thinking that maybe the author meant to compute the length like so:
>
>            rc = pthread_getname_np(thread, thread_name,
>                                    (argc > 2) ? strlen(argv[1]) + 1 :
> NAMELEN);
>
> But I think that the atoi() points to using argv[2] as a number
> representing the length.
>
> (Of course, it should be tested against NAMELEN as a maximum, but I
> understand that examples do not always show how to verify each possible
> error).

I imagine that the author's intention was to allow the user to do
experiments where argv[2] specified a number less than NAMELEN,
in order to see the resulting ERANGE error. But, that experiment
is of limited value, and complicates the code unnecessarily, IMO,
so that's why I made the change above.

--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

Reported-by: Alexis Wilke <alexis@m2osw.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2021-08-10 11:11:40 +02:00
Michael Kerrisk d27bcddc11 mount_setattr.2: Rework the discussion of MOUNT_ATTR__ATIME
Phrases such as "In the new mount API" will date fast. Remove it.
Also:
* Make it clear that MOUNT_ATTR__ATIME expresses a bit field.
* Replace 'enum' with 'enumeration'.
* Clarify what is meant by "partially" set MOUNT_ATTR__ATIME.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2021-08-10 10:45:18 +02:00
Michael Kerrisk 705bf534bb mount_setattr.2: Remove description of propagation types
These types are already well described in mount_namespaces(7);
indeed, much of the text from that page seems to have just been
cut and pasted into this page! Simply referring the reader to
mount_namespaces(7) is sufficient.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2021-08-10 09:23:08 +02:00
Michael Kerrisk 29fdc88d6e mount_setattr.2: Reword the description of the 'propagation field'
Point out that this field can have the value zero, meaning
no change. And avoid discussions of 'enum', and simply say
that otherwise the field has one of the MS_* values.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2021-08-10 09:13:56 +02:00
2 changed files with 20 additions and 36 deletions

View File

@ -270,8 +270,11 @@ and is implied by the noatime setting.
All other access-time settings are mutually exclusive.
.TP
.BR MOUNT_ATTR__ATIME " - changing access-time settings"
In the new mount API, the access-time values are an enum starting from 0.
Even though they are an enum (in contrast to the other mount flags such as
The access-time values listed below are an enumeration that
includes the value zero, expressed in the bits defined by the mask
.BR MOUNT_ATTR__ATIME .
Even though these bits are an enumeration
(in contrast to the other mount flags such as
.BR MOUNT_ATTR_NOEXEC ),
they are nonetheless passed in
.I attr_set
@ -282,12 +285,11 @@ for consistency with
which introduced this behavior.
.IP
Note that,
since access times are an enum
not a bit map,
users wanting to transition to a different access-time setting cannot simply
specify the access-time setting in
.I attr_set
but must also set
since the access-time values are an enumeration rather than bit values,
a caller wanting to transition to a different access-time setting
cannot simply specify the access-time setting in
.IR attr_set ,
but must also include
.B MOUNT_ATTR__ATIME
in the
.I attr_clr
@ -295,8 +297,10 @@ field.
The kernel will verify that
.B MOUNT_ATTR__ATIME
isn't partially set in
.IR attr_clr ,
and that
.IR attr_clr
(i.e., either all bits in the
.B MOUNT_ATTR__ATIME
bit field are either set or clear), and that
.I attr_set
doesn't have any access-time bits set if
.B MOUNT_ATTR__ATIME
@ -368,42 +372,23 @@ For further details, see the subsection "ID-mapped mounts" under NOTES.
The
.I propagation
field is used to specify the propagation type of the mount or mount tree.
Mount propagation options are mutually exclusive;
that is,
the propagation values behave like an enum.
The supported mount propagation types are:
This field either has the value zero,
meaning leave the propagation type unchanged, or it has one of
the following values:
.TP
.B MS_PRIVATE
Turn all mounts into private mounts.
Mount and unmount events do not propagate into or out of this mount point.
.TP
.B MS_SHARED
Turn all mounts into shared mounts.
Mount points share events with members of a peer group.
Mount and unmount events immediately under this mount point
will propagate to the other mount points that are members of the peer group.
Propagation here means that the same mount or unmount will automatically occur
under all of the other mount points in the peer group.
Conversely,
mount and unmount events that take place under peer mount points
will propagate to this mount point.
.TP
.B MS_SLAVE
Turn all mounts into dependent mounts.
Mount and unmount events propagate into this mount point
from a shared peer group.
Mount and unmount events under this mount point do not propagate to any peer.
.TP
.B MS_UNBINDABLE
This is like a private mount,
and in addition this mount can't be bind mounted.
Attempts to bind mount this mount will fail.
When a recursive bind mount is performed on a directory subtree,
any bind mounts within the subtree are automatically pruned
(i.e., not replicated)
when replicating that subtree to produce the target subtree.
Turn all mounts into unbindable mounts.
.PP
For further details on propagation types, see
For further details on the above propagation types, see
.BR mount_namespaces (7).
.SH RETURN VALUE
On success,

View File

@ -201,8 +201,7 @@ main(int argc, char *argv[])
sleep(2);
rc = pthread_getname_np(thread, thread_name,
(argc > 2) ? atoi(argv[1]) : NAMELEN);
rc = pthread_getname_np(thread, thread_name, NAMELEN);
if (rc != 0)
errExitEN(rc, "pthread_getname_np");
printf("The thread name after setting it is %s.\en", thread_name);