"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/test/test-mq-sysv.c" (15 Mar 2019, 2270 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test-mq-sysv.c": 0.09.49_vs_0.09.50.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #define _GNU_SOURCE
   26 
   27 #include <unistd.h>
   28 #include <stdio.h>
   29 #include <string.h>
   30 #include <sys/types.h>
   31 #include <sys/stat.h>
   32 
   33 #include <sys/ipc.h>
   34 #include <sys/msg.h>
   35 
   36 #if defined(__gnu_hurd__)
   37 #error msgsnd, msgrcv, msgget, msgctl are not implemented
   38 #endif
   39 
   40 #define MAX_SIZE        (8)
   41 
   42 typedef struct {
   43     long mtype;
   44     char msg[MAX_SIZE];
   45 } msg_t;
   46 
   47 int main(int argc, char **argv)
   48 {
   49     int msgq_id;
   50     msg_t msg;
   51     int ret;
   52     struct msqid_ds buf;
   53 #if defined(__linux__)
   54     struct msginfo info;
   55 #endif
   56 
   57     /*
   58      * This is not meant to be functionally
   59      * correct, it is just used to check we
   60      * can build minimal POSIX message queue
   61      * based code
   62      */
   63     msgq_id = msgget(IPC_PRIVATE, S_IRUSR | S_IWUSR | IPC_CREAT | IPC_EXCL);
   64     if (msgq_id < 0)
   65         return -1;
   66 
   67     (void)strcpy(msg.msg, "TESTMSG");
   68     msg.mtype = 1;
   69     ret = msgsnd(msgq_id, &msg, sizeof(msg.msg), 0);
   70     (void)ret;
   71     ret = msgrcv(msgq_id, &msg, sizeof(msg.msg), 0, 0);
   72     (void)ret;
   73     ret = msgctl(msgq_id, IPC_STAT, &buf);
   74     (void)ret;
   75     ret = msgctl(msgq_id, IPC_RMID, NULL);
   76     (void)ret;
   77 #if defined(__linux__)
   78     ret = msgctl(msgq_id, IPC_INFO, (struct msqid_ds *)&info);
   79     (void)ret;
   80     ret = msgctl(msgq_id, MSG_INFO, (struct msqid_ds *)&info);
   81     (void)ret;
   82 #endif
   83 
   84     return 0;
   85 }