"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-sigq.c" (15 Mar 2019, 2825 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. For more information about "stress-sigq.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.09.52_vs_0.09.54.

    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 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_SIGQUEUE) && \
   28     defined(HAVE_SIGWAITINFO)
   29 
   30 static void MLOCKED_TEXT stress_sigqhandler(int signum)
   31 {
   32     (void)signum;
   33 }
   34 
   35 /*
   36  *  stress_sigq
   37  *  stress by heavy sigqueue message sending
   38  */
   39 static int stress_sigq(const args_t *args)
   40 {
   41     pid_t pid;
   42 
   43     if (stress_sighandler(args->name, SIGUSR1, stress_sigqhandler, NULL) < 0)
   44         return EXIT_FAILURE;
   45 
   46 again:
   47     pid = fork();
   48     if (pid < 0) {
   49         if (g_keep_stressing_flag && (errno == EAGAIN))
   50             goto again;
   51         pr_fail_dbg("fork");
   52         return EXIT_FAILURE;
   53     } else if (pid == 0) {
   54         sigset_t mask;
   55 
   56         (void)setpgid(0, g_pgrp);
   57         stress_parent_died_alarm();
   58 
   59         (void)sigemptyset(&mask);
   60         (void)sigaddset(&mask, SIGUSR1);
   61 
   62         while (g_keep_stressing_flag) {
   63             siginfo_t info;
   64             if (sigwaitinfo(&mask, &info) < 0)
   65                 break;
   66             if (info.si_value.sival_int)
   67                 break;
   68         }
   69         pr_dbg("%s: child got termination notice\n", args->name);
   70         pr_dbg("%s: exited on pid [%d] (instance %" PRIu32 ")\n",
   71             args->name, (int)getpid(), args->instance);
   72         _exit(0);
   73     } else {
   74         /* Parent */
   75         union sigval s;
   76         int status;
   77 
   78         do {
   79             (void)memset(&s, 0, sizeof(s));
   80             s.sival_int = 0;
   81             (void)sigqueue(pid, SIGUSR1, s);
   82             inc_counter(args);
   83         } while (keep_stressing());
   84 
   85         pr_dbg("%s: parent sent termination notice\n", args->name);
   86         (void)memset(&s, 0, sizeof(s));
   87         s.sival_int = 1;
   88         (void)sigqueue(pid, SIGUSR1, s);
   89         (void)shim_usleep(250);
   90         /* And ensure child is really dead */
   91         (void)kill(pid, SIGKILL);
   92         (void)waitpid(pid, &status, 0);
   93     }
   94 
   95     return EXIT_SUCCESS;
   96 }
   97 
   98 stressor_info_t stress_sigq_info = {
   99     .stressor = stress_sigq,
  100     .class = CLASS_INTERRUPT | CLASS_OS
  101 };
  102 #else
  103 stressor_info_t stress_sigq_info = {
  104     .stressor = stress_not_implemented,
  105     .class = CLASS_INTERRUPT | CLASS_OS
  106 };
  107 #endif