Document struct sigevent in sigevent(7)
PATCH 1/1 Document struct sigevent in sigevent(7)
The sigevent structure is used as a common interface for several asynchronous pthreads functions; also, getaddrinfo_a() uses it and in the future, other library functions might.
Currently, it is completely non-descript in some cases, plus there are two competing descriptions in timer_create(2) and mq_notify(3) (the former appears to be based on the latter). This patch attempts to unify the descriptions in a single manual page and networks it to the rest, so that I do not have to add yet another description for the getaddrinfo_a(3) manual page (currently in the works).
P.S.: There are two unresolved issues with this patch - the timer_create(2) requirement of real-time signal requirements is somewhat confusing and it seems that SIGEV_THREAD_ID can be or'd with SIGEV_SIGNAL or not. I did not have time to research this so far, so I decided to rather send it in and see if someone knows about this off the top of their head.
man2/timer_create.2 +9 -79
@@ -88,92 +88,21 @@ or The .I evp argument points to a -.I sigevent +.IR sigevent (7) structure that specifies how the caller should be notified when the timer expires. -This structure is defined something like the following: - -.in +4n -.nf -union sigval { - int sival_int; - void *sival_ptr; -}; - -struct sigevent { - int sigev_notify; /* Notification method */ - int sigev_signo; /* Timer expiration signal */ - union sigval sigev_value; /* Value accompanying signal or - passed to thread function */ - void (*sigev_notify_function) (union sigval); - /* Function used for thread - notifications (SIGEV_THREAD) */ - void *sigev_notify_attributes; - /* Attributes for notification thread - (SIGEV_THREAD) */ - pid_t sigev_notify_thread_id; - /* ID of thread to signal (SIGEV_THREAD_ID) */ -}; -.fi -.in - -Some of these fields may be defined as part of a union: -a program should only employ those fields relevant -to the value specified in -.IR sigev_notify . -This field can have the following values: -.TP -.BR SIGEV_NONE -Don't asynchronously notify when the timer expires. -Progress of the timer can be monitored using +In case its +.I sigev_notify +field is set to +.BR SIGEV_NONE , +the progress of the timer can be monitored using .BR timer_gettime (2). -.TP +If the .BR SIGEV_SIGNAL -Upon timer expiration, generate the signal -.I sigev_signo -for the process. -If -.I sigev_signo -is a real-time signal, -then it will be accompanied by the data specified in -.IR sigev_value -(like the signal-accompanying data for -.BR sigqueue (2)). -At any point in time, +notification is used, at any point in time at most one signal is queued to the process for a given timer; see .BR timer_getoverrun (2) for more details. -.TP -.BR SIGEV_THREAD -Upon timer expiration, invoke -.I sigev_notify_function -as if it were the start function of a new thread. -(Among the implementation possibilities here are that -each timer notification could result in the creation of a new thread, -or that a single thread is created to receive all notifications.) -The function is invoked with -.I sigev_value -as its sole argument. -If -.I sigev_notify_attributes -is not NULL, it should point to a -.I pthread_attr_t -structure that defines attributes for the new thread (see -.BR pthread_attr_init (3). -.TP -.BR SIGEV_THREAD_ID " (Linux-specific)" -As for -.BR SIGEV_SIGNAL , -but the signal is targeted at the thread whose ID is given in -.IR sigev_notify_thread_id , -which must be a thread in the same process as the caller. -The -.IR sigev_notify_thread_id -field specifies a kernel thread ID, that is, the value returned by -.BR clone (2) -or -.BR gettid (2). -This flag is only intended for use by threading libraries. .PP Specifying .I evp
@@ -431,4 +360,5 @@ main(int argc, char *argv[]) .BR pthread_getcpuclockid (3), .BR pthreads (7), .BR signal (7), +.BR sigevent (7), .BR time (7)
man3/aio_fsync.3 +5 -2
@@ -58,7 +58,9 @@ the only field in the structure pointed to by .I aiocbp that is used by this call is the .I aio_sigevent -field (a \fIstruct sigevent\fP) that indicates the desired type of +field (pointer to a +.IR sigevent (7) +structure) that indicates the desired type of asynchronous notification at completion. All other fields are ignored. .SH "RETURN VALUE"
@@ -91,4 +93,5 @@ POSIX.1-2001. .BR aio_read (3), .BR aio_return (3), .BR aio_suspend (3), -.BR aio_write (3) +.BR aio_write (3), +.BR sigevent (7)
man3/mq_notify.3 +4 -81
98 lines not on this page · raw message
man7/sigevent.7 +137 -0
137 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 12 lines · Petr Baudis
The sigevent structure is used as a common interface for several asynchronous pthreads functions; also,
getaddrinfo_a()uses it and in the future, other library functions might.Currently, it is completely non-descript in some cases, plus there are two competing descriptions in
timer_create(2)andmq_notify(3)(the former appears to be based on the latter). This patch attempts to unify the descriptions in a single manual page and networks it to the rest, so that I do not have to add yet another description for thegetaddrinfo_a(3)manual page (currently in the works).
Quoted 8 lines
P.S.: There are two unresolved issues with this patch - thetimer_create(2)requirement of real-time signal requirements is somewhat confusing and it seems thatSIGEV_THREAD_IDcan be or'd withSIGEV_SIGNALor not. I did not have time to research this so far, so I decided to rather send it in and see if someone knows about this off the top of their head.Signed-off-by Petr Baudis <[email protected]>
Ping...
Petr "Pasky" Baudis
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 20 lines · Petr Baudis
Quoted 19 lines · Petr Baudis
The sigevent structure is used as a common interface for several asynchronous pthreads functions; also,
getaddrinfo_a()uses it and in the future, other library functions might.Currently, it is completely non-descript in some cases, plus there are two competing descriptions in
timer_create(2)andmq_notify(3)(the former appears to be based on the latter). This patch attempts to unify the descriptions in a single manual page and networks it to the rest, so that I do not have to add yet another description for thegetaddrinfo_a(3)manual page (currently in the works).
P.S.: There are two unresolved issues with this patch - thetimer_create(2)requirement of real-time signal requirements is somewhat confusing and it seems thatSIGEV_THREAD_IDcan be or'd withSIGEV_SIGNALor not. I did not have time to research this so far, so I decided to rather send it in and see if someone knows about this off the top of their head.
Quoted 3 lines
Quoted 1 line
Signed-off-by Petr Baudis <[email protected]>Ping...
Ping... :-)
P.S.: I'm sorry that I have not been of any help with maintaining manpages contrary to what I promised - it turns out I'm currently way too swamped by other stuff.. :-(
Signature · 7 lines
Petr "Pasky" Baudis A great many people think they are thinking when they are merely rearranging their prejudices. -- William James -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello Petr,
First of all, my apologies for the enormous delay on following up on this patch.
Quoted 12 lines · Petr Baudis
The sigevent structure is used as a common interface for several asynchronous pthreads functions; also,
getaddrinfo_a()uses it and in the future, other library functions might.Currently, it is completely non-descript in some cases, plus there are two competing descriptions in
timer_create(2)andmq_notify(3)(the former appears to be based on the latter). This patch attempts to unify the descriptions in a single manual page and networks it to the rest, so that I do not have to add yet another description for thegetaddrinfo_a(3)manual page (currently in the works).
Quoted 6 lines
P.S.: There are two unresolved issues with this patch - thetimer_create(2)requirement of real-time signal requirements is somewhat confusing and it seems thatSIGEV_THREAD_IDcan be or'd withSIGEV_SIGNALor not. I did not have time to research this so far, so I decided to rather send it in and see if someone knows about this off the top of their head.
I understand your motivations for writing this patch, in terms of eliminating redundancy, and possible out-of-syncness in various pages. However, this patch suffers from several of the problems that I aimed to avoid when I added the timer_create.2 page:
* By the nature of the APIs, the descriptions need to add some API-specific content for the various 'notification' values. Your patch partially addresses that, but in unifying the content, it loses some per-API information.
* The patch introduces incorrect information. E.g., for SIGEV_SIGNAL, not all APIs set si_uid and si_pid. Message queues do, but POSIX timers don't (it makes no sense)
* Not all 'notification' values are valid for all APIS. As far as I know, SIGEV_THREAD_ID is valid only for POSIX timers.
Like I say, when I wrote the timer_create.2 page, I ran into the same problems, which is why I partially duplicated content, rather than writing a separate page. Of course, this solution doesn't scale well, as you highlight. So I think your idea is the right way to go, but it needs tweaking. I propose to add the version below. Comments welcome.
Thanks,
Michael
.\" Copyright (C) 2006, 2010 Michael Kerrisk <[email protected]> .\" Copyright (C) 2009 Petr Baudis <[email protected]>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.TH SIGEVENT 7 2010-09-19 "GNU" "Linux Programmer's Manual"
.SH NAME
struct sigevent \- structure for notification from asynchronous routines
.SH SYNOPSIS
.nf
union sigval { /* Data passed with notification */
int sival_int; /* Integer value */
void *sival_ptr; /* Pointer value */
};
struct sigevent {
int sigev_notify; /* Notification method */
int sigev_signo; /* Notification signal */
union sigval sigev_value; /* Data passed with
notification */
void (*sigev_notify_function) (union sigval);
/* Function used for thread
notification (SIGEV_THREAD) */
void *sigev_notify_attributes;
/* Attributes for notification thread
(SIGEV_THREAD) */
pid_t sigev_notify_thread_id;
/* ID of thread to signal (SIGEV_THREAD_ID) */
};.fi
.SH DESCRIPTION
.PP
The
.I sigevent
structure is used by various APIs
to describe the way a process is to be notified about an event (e.g., completion of an asynchronous request, expiration of a timer, or the arrival of a message).
.PP
The definition shown in the SYNOPSIS is approximate:
some of the fields in the
.I sigevent
structure may be defined as part of a union.
Programs should only employ those fields relevant
to the value specified in
.IR sigev_notify .
.PP
The
.I sigev_notify
field specifies how notification is to be performed.
This field can have one of the following values:
.TP 8
.BR SIGEV_NONE
A "null" notification: don't do anything when the event occurs. .TP
.BR SIGEV_SIGNAL
Notify the process by sending the signal specified in
.IR sigev_signo .
.IP
If the signal is caught with a signal handler that was registered using the .BR sigaction (2)
.B SA_SIGINFO
flag, then the following fields are set in the
.I siginfo_t
structure that is passed as the second argument of the handler:
.RS 8
.TP 10
.I si_code
This field is set to a value that depends on the API
delivering the notification.
.TP
.I si_signo
This field is set to the signal number (i.e., the same value as in .IR sigev_signo ).
.TP
.I si_value
This field is set to the value specified in
.IR sigev_value .
.RE
.IP
Depending on the API, other fields may also be set in the
.I siginfo_t
structure.
.IP
The same information is also available if the signal is accepted using .BR sigwaitinfo (2).
.TP
.BR SIGEV_THREAD
Notify the process by invoking
.I sigev_notify_function
"as if" it were the start function of a new thread.
(Among the implementation possibilities here are that
each timer notification could result in the creation of a new thread, or that a single thread is created to receive all notifications.) The function is invoked with
.I sigev_value
as its sole argument.
If
.I sigev_notify_attributes
is not NULL, it should point to a
.I pthread_attr_t
structure that defines attributes for the new thread (see
.BR pthread_attr_init (3)).
.TP
.BR SIGEV_THREAD_ID " (Linux-specific)"
.\" | SIGEV_SIGNAL vs not?
Currently used only by POSIX timers; see
.BR timer_create (2).
.SH CONFORMING TO
POSIX.1-2001.
.SH "SEE ALSO"
.BR timer_create (2),
.BR aio_fsync (3),
.\" .BR lio_listio (3),
.\" FIXME This page will be added later .BR getaddrinfo_a (3), .BR mq_notify (3),
.BR pthreads (7)
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): AANLkTin1o4JQ98zmsox6Qg9R5oaPCswieATTd98rCSjY-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hello Petr,
The corresponding patch elsewhere in the set would then be as below. Again, comments welcome.
Cheers,
Michael
man2/timer_create.2 +19 -50
@@ -20,7 +20,7 @@ .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. -.TH TIMER_CREATE 2 2009-02-20 Linux "Linux Programmer's Manual" +.TH TIMER_CREATE 2 2010-09-19 Linux "Linux Programmer's Manual" .SH NAME timer_create \- create a POSIX per-process timer .SH SYNOPSIS
@@ -90,37 +90,12 @@ argument points to a .I sigevent structure that specifies how the caller should be notified when the timer expires. -This structure is defined something like the following: +For the definition and general details of this structure, see +.BR sigevent (7). -.in +4n -.nf -union sigval { - int sival_int; - void *sival_ptr; -}; - -struct sigevent { - int sigev_notify; /* Notification method */ - int sigev_signo; /* Timer expiration signal */ - union sigval sigev_value; /* Value accompanying signal or - passed to thread function */ - void (*sigev_notify_function) (union sigval); - /* Function used for thread - notifications (SIGEV_THREAD) */ - void *sigev_notify_attributes; - /* Attributes for notification thread - (SIGEV_THREAD) */ - pid_t sigev_notify_thread_id; - /* ID of thread to signal (SIGEV_THREAD_ID) */ -}; -.fi -.in - -Some of these fields may be defined as part of a union: -a program should only employ those fields relevant -to the value specified in -.IR sigev_notify . -This field can have the following values: +The +.I evp.sigev_notify +field can have the following values: .TP .BR SIGEV_NONE Don't asynchronously notify when the timer expires.
@@ -131,13 +106,15 @@ Progress of the timer can be monitored using Upon timer expiration, generate the signal .I sigev_signo for the process. -If -.I sigev_signo -is a real-time signal, -then it will be accompanied by the data specified in -.IR sigev_value -(like the signal-accompanying data for -.BR sigqueue (2)). +See +.BR sigevent (7) +for general details. +The +.I si_code +field of the +.I siginfo_t +structure will be set to +.BR SI_TIMER . At any point in time, at most one signal is queued to the process for a given timer; see .BR timer_getoverrun (2)
@@ -147,18 +124,9 @@ for more details. Upon timer expiration, invoke .I sigev_notify_function as if it were the start function of a new thread. -(Among the implementation possibilities here are that -each timer notification could result in the creation of a new thread, -or that a single thread is created to receive all notifications.) -The function is invoked with -.I sigev_value -as its sole argument. -If -.I sigev_notify_attributes -is not NULL, it should point to a -.I pthread_attr_t -structure that defines attributes for the new thread (see -.BR pthread_attr_init (3)). +See +.BR sigevent (7) +for details. .TP .BR SIGEV_THREAD_ID " (Linux-specific)" As for
@@ -430,5 +398,6 @@ main(int argc, char *argv[]) .BR clock_getcpuclockid (3), .BR pthread_getcpuclockid (3), .BR pthreads (7), +.BR sigevent (7), .BR signal (7), .BR time (7)
man3/aio_fsync.3 +9 -4
@@ -20,7 +20,7 @@ .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. .\" -.TH AIO_FSYNC 3 2003-11-14 "" "Linux Programmer's Manual" +.TH AIO_FSYNC 3 2010-09-19 "" "Linux Programmer's Manual" .SH NAME aio_fsync \- asynchronous file synchronization .SH SYNOPSIS
@@ -58,8 +58,12 @@ the only field in the structure pointed to by .I aiocbp that is used by this call is the .I aio_sigevent -field (a \fIstruct sigevent\fP) that indicates the desired type of -asynchronous notification at completion. +field (a +.I sigevent +structure, described in +.BR sigevent (7)), +which indicates the desired type of asynchronous notification at completion. +,\" FIXME more sigevent details are probably needed here. All other fields are ignored. .SH "RETURN VALUE" On success (the sync request was successfully queued)
@@ -91,4 +95,5 @@ POSIX.1-2001. .BR aio_read (3), .BR aio_return (3), .BR aio_suspend (3), -.BR aio_write (3) +.BR aio_write (3), +.BR sigevent (7)
man3/mq_notify.3 +5 -24
@@ -23,7 +23,7 @@ .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" -.TH MQ_NOTIFY 3 2010-08-29 "Linux" "Linux Programmer's Manual" +.TH MQ_NOTIFY 3 2010-09-19 "Linux" "Linux Programmer's Manual" .SH NAME mq_notify \- register for notification when a message is available .SH SYNOPSIS
@@ -45,28 +45,9 @@ The .I notification argument is a pointer to a .I sigevent -structure that is defined something like the following: -.in +4n -.nf - -union sigval { /* Data passed with notification */ - int sival_int; /* Integer value */ - void *sival_ptr; /* Pointer value */ -}; - -struct sigevent { - int sigev_notify; /* Notification method */ - int sigev_signo; /* Notification signal */ - union sigval sigev_value; /* Data passed with - notification */ - void (*sigev_notify_function) (union sigval); - /* Function for thread - notification */ - void *sigev_notify_attributes; - /* Thread function attributes */ -}; -.fi -.in +structure. +For the definition and general details of this structure, see +.BR sigevent (7). .PP If .I notification
@@ -77,7 +58,7 @@ The .I sigev_notify field of the .I sigevent -to which +structure to which .I notification points specifies how notification is to be performed. This field has one of the following values:
@@ -90,43 +71,30 @@ for notification, but when a message arrives, no
notification is sent.
.B SIGEV_SIGNAL
Notify the process by sending the signal specified in .IR sigev_signo .
-If the signal is caught with a signal handler that -was registered using the
-.BR sigaction (2)
-.B SA_SIGINFO
-flag, then the following fields are set in the
-.I siginfo_t
-structure that is passed as the second argument of the handler:
+See
+.BR sigevent (7)
+for general details.
+The
.I si_code
-is set to
-.BR SI_MESGQ ;
-.I si_signo
-is set to the signal number;
-.I si_value
-is set to the value specified in
-.IR notification\->sigev_value ;
+field of the
+.I siginfo_t
+structure will be set to
+.BR SI_MESGQ .
+In addition,
.\" I don't know of other implementations that set
.\" si_pid and si_uid -- MTK
.I si_pid
-is set to the PID of the process that sent the message; and +will be set to the PID of the process that sent the message, and
.I si_uid
-is set to the real user ID of the sending process. -The same information is available if the signal is accepted using -.BR sigwaitinfo (2).
+will be set to the real user ID of the sending process.
.TP
.B SIGEV_THREAD
-Deliver notification by invoking
-.I notification\->sigev_notify_function
-as the start function of a new thread.
-The function is invoked with
-.I notification\->sigev_value
-as its sole argument.
-If
-.I notification\->sigev_notify_attributes
-is not NULL, then it should point to a
-.I pthread_attr_t
-structure that defines attributes for the thread (see -.BR pthread_attr_init (3)).
+Upon message delivery, invoke
+.I sigev_notify_function
+as if it were the start function of a new thread.
+See
+.BR sigevent (7)
+for details.
.PP
Only one process can be registered to receive notification from a message queue.
@@ -279,4 +247,5 @@ main(int argc, char *argv[])
.BR mq_receive (3),
.BR mq_send (3),
.BR mq_unlink (3),
-.BR mq_overview (7)
+.BR mq_overview (7),
+.BR sigevent (7)
man7/signal.7 +3 -2
@@ -41,7 +41,7 @@ .\" Added section on stop/cont signals interrupting syscalls. .\" 2008-10-05, mtk: various additions .\" -.TH SIGNAL 7 2010-06-12 "Linux" "Linux Programmer's Manual" +.TH SIGNAL 7 2010-09-19 "Linux" "Linux Programmer's Manual" .SH NAME signal \- overview of signals .SH DESCRIPTION
@@ -873,4 +873,5 @@ signal 29 is .BR sysv_signal (3), .BR core (5), .BR proc (5), -.BR pthreads (7) +.BR pthreads (7), +.BR sigevent (7)
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi!
Quoted 5 lines · Michael Kerrisk
Like I say, when I wrote the timer_create.2 page, I ran into the same problems, which is why I partially duplicated content, rather than writing a separate page. Of course, this solution doesn't scale well, as you highlight. So I think your idea is the right way to go, but it needs tweaking. I propose to add the version below. Comments welcome.
Hmm, what you write makes a lot of sense, the new versions looks good
to me!
Thanks for looking into it,
Signature · 7 lines
Petr "Pasky" Baudis The true meaning of life is to plant a tree under whose shade you will never sit. -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html