/***************************************************
* Creat : 2001. 02. 10 (programed by Cori-Young)
* Site: http://www.byoneself.co.kr
* Update :
***************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <time.h>
static void do_msgctl();
extern void exit();
extern void perror();
static char warning_message[] = "If you remove read permissionfor yourself, this program will fail frequently!";
main()
{
struct msqid_ds buf;
int cmd;
int msqid;
(void) fprintf(stderr, "t0x... is interpreted as hexadecimal,n");
(void) fprintf(stderr, "t0... is interpreted as octal,n");
(void) fprintf(stderr, "totherwise, decimal.n");
/* Get the msqid and cmd arguments for the msgctl() call. */
(void) fprintf(stderr, "Please enter arguments for msgctls() as requested.");
(void) fprintf(stderr, "nEnter the msqid: ");
(void) scanf("%i", &msqid);
(void) fprintf(stderr, "tIPC_RMID = %dn", IPC_RMID);
(void) fprintf(stderr, "tIPC_SET = %dn", IPC_SET);
(void) fprintf(stderr, "tIPC_STAT = %dn", IPC_STAT);
(void) fprintf(stderr, "nEnter the value for the command: ");
(void) scanf("%i", &cmd);
switch (cmd) {
case IPC_SET:
/* Modify settings in the message queue control structure.*/
/* Get a copy of the current message queue control structure and show it to the user. */
do_msgctl(msqid, IPC_STAT, &buf);
(void) fprintf(stderr, "msg_perm.uid = %dn", buf.msg_perm.uid);
(void) fprintf(stderr, "msg_perm.gid = %dn", buf.msg_perm.gid);
(void) fprintf(stderr, "msg_perm.cuid = %dn", buf.msg_perm.cuid);
(void) fprintf(stderr, "msg_perm.cgid = %dn", buf.msg_perm.cgid);
(void) fprintf(stderr, "msg_perm.mode = %#o, ", buf.msg_perm.mode);
(void) fprintf(stderr, "access permissions = %#on", buf.msg_perm.mode & 0777);
(void) fprintf(stderr, "msg_cbytes = %dn", buf.msg_cbytes);
(void) fprintf(stderr, "msg_qbytes = %dn", buf.msg_qbytes);
(void) fprintf(stderr, "msg_qnum = %dn", buf.msg_qnum);
(void) fprintf(stderr, "msg_lspid = %dn", buf.msg_lspid);
(void) fprintf(stderr, "msg_lrpid = %dn", buf.msg_lrpid);
(void) fprintf(stderr, "msg_stime = %s", buf.msg_stime ? ctime(&buf.msg_stime) : "Not Setn");
(void) fprintf(stderr, "msg_rtime = %s", buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not Setn");
(void) fprintf(stderr, "msg_ctime = %s", ctime(&buf.msg_ctime));
if (cmd == IPC_STAT)
break;
/* Now continue with IPC_SET. */
(void) fprintf(stderr, "Enter msg_perm.uid: ");
(void) scanf ("%hi", &buf.msg_perm.uid);
(void) fprintf(stderr, "Enter msg_perm.gid: ");
(void) scanf("%hi", &buf.msg_perm.gid);
(void) fprintf(stderr, "%sn", warning_message);
(void) fprintf(stderr, "Enter msg_perm.mode: ");
(void) scanf("%hi", &buf.msg_perm.mode);
(void) fprintf(stderr, "Enter msg_qbytes: ");
(void) scanf("%hi", &buf.msg_qbytes);
do_msgctl(msqid, IPC_SET, &buf);
break;
case IPC_RMID:
default:
do_msgctl(msqid, cmd, (struct msqid_ds *)NULL);
break;
}
exit(0);
}
static void do_msgctl(msqid, cmd, buf)
struct msqid_ds *buf;
int cmd, msqid;
{
register int rtrn;
(void) fprintf(stderr, "nmsgctl: Calling msgctl(%d, %d,%s)n", msqid, cmd, buf ? "&buf" : "(struct msqid_ds *)NULL");
rtrn = msgctl(msqid, cmd, buf);
if (rtrn == -1) {
perror("msgctl: msgctl failed");
exit(1);
}
else {
(void) fprintf(stderr, "msgctl: msgctl returned %dn", rtrn);
}
} |
|