Imported Upstream version 20080930
[ltp-debian.git] / testcases / audit-test / utils / bin / do_mq_open.c
bloba65a21ae91dfa08a729bba989c1d61907439a72e
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 <mqueue.h>
18 #include <selinux/selinux.h>
20 int main(int argc, char **argv)
22 int exitval, result;
23 int flags = 0;
25 if (argc < 3) {
26 fprintf(stderr, "Usage:\n%s <path> <create|read|write|rdwr> [context]\n",
27 argv[0]);
28 return 1;
31 if (!strcmp(argv[2], "create")) {
32 /* use O_EXCL on create to catch cleanup problems */
33 flags |= O_CREAT|O_EXCL;
34 } else if (!strcmp(argv[2], "read")) {
35 flags |= O_RDONLY;
36 } else if (!strcmp(argv[2], "write")) {
37 flags |= O_WRONLY;
38 } else if (!strcmp(argv[2], "rdwr")) {
39 flags |= O_RDWR;
40 } else {
41 fprintf(stderr, "Usage:\n%s <path> <create|read|write|rdwr> [context]\n",
42 argv[0]);
43 return 1;
46 if ((argc > 3) && (setfscreatecon(argv[3]) < 0)) {
47 perror("do_mq_open: setfscreatecon");
48 return 1;
51 errno = 0;
52 exitval = mq_open(argv[1], flags, S_IRWXU, NULL);
53 result = exitval < 0;
55 printf("%d %d %d\n", result, result ? errno : exitval, getpid());
56 return result;