ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/ipcmsgct.htm

433 lines
12 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>msgctl()--Perform Message Control Operations</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- Direct1 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- Edited by Kersten Jan 02 -->
<!-- This file has undergone error condition cleanup on 05/01/02 by JET -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!--End Header Records -->
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>msgctl()--Perform Message Control Operations</h2>
<div class="box" style="width: 80%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/msg.h&gt;
int msgctl(int <em>msqid</em>, int <em>cmd</em>, struct msqid_ds <em>*buf</em>);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0ZUSHR<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>msgctl()</strong> function allows the caller to control
the message queue specified by the <em>msqid</em> parameter.</p>
<p>A message queue is controlled by setting the <em>cmd</em> parameter to one of the following values:</p>
<dl>
<dt><strong>IPC_RMID (0x00000000)</strong></dt>
<dd>Remove the message queue identifier <em>msqid</em> from the system and destroy
any messages on the message queue.
Any threads that are waiting in <strong>msgsnd()</strong> or <strong>msgrcv()</strong>
are woken up and <strong>msgsnd()</strong> or <strong>msgrcv()</strong> returns with a
return value of -1 and <em>errno</em> set to EIDRM.
<p>The IPC_RMID command can be run only by a thread with appropriate privileges
or one that has an effective user ID equal to the user ID of the owner or the user ID
of the creator of the message queue. The
structure pointed to by <em>*buf</em> is ignored and can be NULL.</p>
</dd>
<dt><strong>IPC_SET (0x00000001)</strong></dt>
<dd>Set the user ID of the owner, the group ID of the owner, the permissions, and the
maximum number of bytes for the message queue to the values in the
<samp>msg_perm.uid</samp>, <samp>msg_perm.gid</samp>,
<samp>msg_perm.mode</samp>, and <samp>msg_qbytes</samp> members of the
<samp>msqid_ds</samp> data structure pointed to by <em>*buf</em>.
<p>The IPC_SET command can be run only by a thread with appropriate privileges or one that
has an effective user ID equal to the user ID of the owner or the user ID
of the creator of the message queue.</p>
<p>In addition, only a thread with appropriate privileges can
increase the maximum number of bytes for the message queue.</p>
</dd>
<dt><strong>IPC_STAT (0x00000002)</strong></dt>
<dd>Store the current value of each member of the
<samp>msqid_ds</samp> data structure into the
structure pointed to by <em>*buf</em>. The IPC_STAT command requires
read permission to the message queue.</dd>
</dl>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>msqid</strong></dt>
<dd>(Input) Message queue identifier, a positive integer. It is returned by the
<a href="ipcmsggt.htm">msgget()</a> function and used to identify the message queue on
which to perform the control operation.
</dd>
<dt><strong>cmd</strong></dt>
<dd>(Input) Command, the control operation to perform on the message queue.
Valid values are listed above.</dd>
<dt><strong>buf</strong></dt>
<dd>(I/O) Pointer to the message queue data structure to be used to get or set
message queue information.
<p>The members of the <samp>msqid_ds</samp> structure are as follows:</p>
<table cellpadding="5">
<!-- cols="15 85" -->
<tr>
<td align="left" valign="top"><em>struct ipc_perm msg_perm</em> </td>
<td align="left" valign="top">The members of the <samp>ipc_perm</samp> structure
are as follows:
<table cellpadding="5">
<tr>
<td align="left" valign="top"><em>uid_t uid</em> </td>
<td align="left" valign="top">The user ID of the owner of the message queue.</td>
</tr>
<tr>
<td align="left" valign="top"><em>gid_t gid</em> </td>
<td align="left" valign="top">The group ID of the owner of the message queue.</td>
</tr>
<tr>
<td align="left" valign="top"><em>uid_t cuid</em> </td>
<td align="left" valign="top">The user ID of the creator of the message queue.</td>
</tr>
<tr>
<td align="left" valign="top"><em>gid_t cgid</em> </td>
<td align="left" valign="top">The group ID of the creator of the message queue.</td>
</tr>
<tr>
<td align="left" valign="top"><em>mode_t mode</em> </td>
<td align="left" valign="top">The permissions for the message queue.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>msgnum_t msg_qnum</em> </td>
<td align="left" valign="top">The number of messages currently on the message queue.</td>
</tr>
<tr>
<td align="left" valign="top"><em>msglen_t msg_qbytes</em> </td>
<td align="left" valign="top">The maximum number of bytes allowed on the message queue.</td>
</tr>
<tr>
<td align="left" valign="top"><em>pid_t msg_lspid</em> </td>
<td align="left" valign="top">The process ID of the last job to send a message
using <strong>msgsnd()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>pid_t msg_lrpid</em> </td>
<td align="left" valign="top">The process ID of the last job to receive a message
using <strong>msgrcv()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>time_t msg_stime</em> </td>
<td align="left" valign="top">The time the last job sent a message to the message queue
using <strong>msgsnd()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>time_t msg_rtime</em> </td>
<td align="left" valign="top">The time the last job received a message from the message queue
using <strong>msgrcv()</strong>.</td>
</tr>
<tr>
<td align="left" valign="top"><em>time_t msg_ctime</em> </td>
<td align="left" valign="top">The time the last job changed the message queue using
<strong>msgctl()</strong>.</td>
</tr>
</table></dd>
</dl>
<h3>Authorities</h3>
<p><strong><a name="TBLAMCTL1">Authorization Required for
msgctl()</a></strong></p>
<table border cellpadding="5">
<!-- cols="60 20 20" -->
<tr>
<th align="left" valign="bottom">Object Referred to</th>
<th align="left" valign="bottom">Authority Required</th>
<th align="left" valign="bottom">errno</th>
</tr>
<tr>
<td align="left" valign="top">Message queue for which state information is
retrieved (<em>cmd</em> = IPC_STAT)</td>
<td align="left" valign="top">Read</td>
<td align="left" valign="top">EACCES</td>
</tr>
<tr>
<td align="left" valign="top">Message queue for which state information is set
(<em>cmd</em> = IPC_SET)</td>
<td align="left" valign="top">See Note</td>
<td align="left" valign="top">EPERM</td>
</tr>
<tr>
<td align="left" valign="top">Message queue to be removed (<em>cmd</em> =
IPC_RMID)</td>
<td align="left" valign="top">See Note</td>
<td align="left" valign="top">EPERM</td>
</tr>
</table>
<p><strong>Note:</strong> To set message queue information or to remove a
message queue, the thread must be the owner or creator of the queue, or have
appropriate privileges. To increase the maximum number of bytes for the message queue,
a thread must have appropriate privileges.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="5 95" -->
<tr>
<td align="left" valign="top"><em>0</em></td>
<td align="left" valign="top"><strong>msgctl()</strong> was successful.</td>
</tr>
<tr>
<td align="left" valign="top" nowrap><em>-1</em></td>
<td align="left" valign="top"><strong>msgctl()</strong> was not successful. The
<em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>msgctl()</strong> is not successful, <em>errno</em> usually
indicates one of the following errors. Under some conditions, <em>errno</em>
could indicate an error other than those listed here.</p>
<dl>
<dt><em>[EACCES]</em></dt>
<dd>
<p>Permission denied.</p>
<p>An attempt was made to access an object in a way forbidden by its object
access permissions.</p>
<p>The thread does not have access to the specified file, directory, component,
or path.</p>
<p>The <em>cmd</em> parameter is IPC_STAT and the calling thread does not have
read permission.</p>
</dd>
<dt><em>[EDAMAGE]</em></dt>
<dd>
<p>A damaged object was encountered.</p>
<p>A referenced object is damaged. The object cannot be used.</p>
<p>The message queue has been damaged by a previous message queue
operation.</p>
</dd>
<dt><em>[EFAULT]</em></dt>
<dd>
<p>The address used for an argument is not correct.</p>
<p>In attempting to use an argument in a call, the system detected an address
that is not valid.</p>
<p>While attempting to access a parameter passed to this function, the system
detected an address that is not valid.</p>
</dd>
<dt><em>[EINVAL]</em></dt>
<dd>
<p>The value specified for the argument is not correct.</p>
<p>A function was passed incorrect argument values, or an operation was
attempted on an object and the operation specified is not supported for that
type of object.</p>
<p>An argument value is not valid, out of range, or NULL.</p>
<p>One of the following has occurred:</p>
<ul>
<li>The <em>msqid</em> parameter is not a valid message queue identifier.</li>
<li>The <em>cmd</em> parameter is not a valid command.</li>
<li>The <em>cmd</em> parameter is IPC_SET and the value of <samp>
msg_qbytes</samp> exceeds the system limit.</li>
</ul>
<br>
</dd>
<dt><em>[EPERM]</em></dt>
<dd>
<p>Operation not permitted.</p>
<p>You must have appropriate privileges or be the owner of the object or other
resource to do the requested operation.</p>
<p>The <em>cmd</em> parameter is equal to IPC_RMID or IPC_SET and both of the
following are true:</p>
<ul>
<li>the caller does not have the appropriate privileges.</li>
<li>the effective user ID of the caller is not equal to the user ID of the owner
or the user ID of the creator of the message queue.</li>
</ul>
<p>The <em>cmd</em> parameter is IPC_SET and an attempt is being made to
increase the maximum number of bytes for the message queue, but the the caller does not have
appropriate privileges.</p>
</dd>
<dt><em>[EUNKNOWN]</em></dt>
<dd>
<p>Unknown system state.</p>
<p>The operation failed because of an unknown system state. See any messages in
the job log and correct any errors that are indicated, then retry the
operation.</p>
</dd>
</dl>
<br>
<h3>Error Messages</h3>
<p>None.</p>
<br>
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
<ol>
<li>&quot;Appropriate privileges&quot; is defined to be *ALLOBJ special authority. If the
user profile under which the thread is running does not have *ALLOBJ special
authority, the caller does not have appropriate privileges.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>sys/msg.h</strong>&gt; file (see <a href="unix13.htm">
Header Files for UNIX-Type Functions</a>)<br>
<br>
</li>
<li><a href="unix3a.htm#messagequeue">Message Queues</a> for the current system limits.
<br><br></li>
<li><a href="ipcmsggt.htm">msgget()</a>--Get Message Queue<br>
<br>
</li>
<li><a href="ipcmsgrc.htm">msgrcv()</a>--Receive Message Operation<br>
<br>
</li>
<li><a href="ipcmsgsn.htm">msgsnd()</a>--Send Message Operation</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example performs a control operation on a message queue:</p>
<pre>
#include &lt;sys/msg.h&gt;
main() {
int msqid = 2;
int rc;
struct msqid_ds buf;
rc = msgctl(msqid, IPC_STAT, &amp;buf);
}
</pre>
<br>
<hr>
API introduced: V3R6
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>