Imported Upstream version 20081130
[ltp-debian.git] / testcases / audit-test / utils / bin / do_ipc.c
blobe01a0933528e7d0650abf0aca17afc7c82ddb4e6
1 /* (c) Copyright Hewlett-Packard Development Company, L.P., 2007
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of version 2 the GNU General Public License as
5 * published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #include "includes.h"
17 #include <sys/ipc.h>
18 #include <asm-generic/ipc.h>
20 #include "ipc_common.c"
22 int main(int argc, char **argv)
24 int exitval, result;
25 int op, flags = 0;
27 if (argc < 1) {
28 fprintf(stderr, "%s: you must specify an ipc operation\n", argv[0]);
29 return 1;
32 if (check_ipc_usage(argv[1], argc - 1))
33 return 1;
35 if (translate_ipc_op(argv[1], &op))
36 return 1;
38 switch (op) {
39 case MSGCTL:
40 case MSGGET:
41 case SEMCTL:
42 case SEMGET:
43 case SHMCTL:
44 case SHMGET:
45 if (translate_ipc_flags(argv[3], &flags))
46 return 1;
47 break;
48 case SEMOP:
49 case SEMTIMEDOP:
50 if (translate_sem_flags(argv[3], &flags))
51 return 1;
52 break;
53 case SHMAT:
54 if (translate_shm_flags(argv[3], &flags))
55 return 1;
56 break;
59 errno = 0;
60 switch (op) {
61 case MSGCTL:
62 exitval = do_msgctl(atoi(argv[2]), flags);
63 break;
64 case MSGGET:
65 exitval = do_msgget(atoi(argv[2]), flags);
66 break;
67 case MSGRCV:
68 exitval = do_msgrcv(atoi(argv[2]), atoi(argv[3]));
69 break;
70 case MSGSND:
71 exitval = do_msgsnd(atoi(argv[2]), atoi(argv[3]), argv[4]);
72 break;
73 case SEMCTL:
74 exitval = do_semctl(atoi(argv[2]), flags);
75 break;
76 case SEMGET:
77 exitval = do_semget(atoi(argv[2]), flags);
78 break;
79 case SEMOP:
80 exitval = do_semop(atoi(argv[2]), flags);
81 break;
82 case SEMTIMEDOP:
83 exitval = do_semtimedop(atoi(argv[2]), flags);
84 break;
85 case SHMCTL:
86 exitval = do_shmctl(atoi(argv[2]), flags);
87 break;
88 case SHMGET:
89 exitval = do_shmget(atoi(argv[2]), flags);
90 break;
91 case SHMAT:
92 exitval = do_shmat(atoi(argv[2]), flags);
93 break;
94 default:
95 fprintf(stderr, "%s: %d is not a supported ipc operation\n", argv[0], op);
96 return 1;
99 switch(op) {
100 case SHMAT:
101 result = exitval == -1;
102 break;
103 default:
104 result = exitval < 0;
107 printf("%d %d %d\n", result, result ? errno : exitval, getpid());
108 return result;