"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-sigpending.c" (15 Mar 2019, 2394 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-sigpending.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 /*
   28  *  stress_usr1_handler()
   29  *  SIGUSR1 signal handler
   30  */
   31 static void MLOCKED_TEXT stress_usr1_handler(int signum)
   32 {
   33     (void)signum;
   34 }
   35 
   36 /*
   37  *  stress_sigpending
   38  *  stress sigpending system call
   39  */
   40 static int stress_sigpending(const args_t *args)
   41 {
   42     sigset_t _sigset;
   43 
   44     if (stress_sighandler(args->name, SIGUSR1, stress_usr1_handler, NULL) < 0)
   45         return EXIT_FAILURE;
   46 
   47     do {
   48         (void)sigemptyset(&_sigset);
   49         (void)sigaddset(&_sigset, SIGUSR1);
   50         if (sigprocmask(SIG_SETMASK, &_sigset, NULL) < 0) {
   51             pr_fail_err("sigprocmask");
   52             return EXIT_FAILURE;
   53         }
   54 
   55         (void)kill(args->pid, SIGUSR1);
   56         if (sigpending(&_sigset) < 0) {
   57             pr_fail_err("sigpending");
   58             continue;
   59         }
   60         /* We should get a SIGUSR1 here */
   61         if (!sigismember(&_sigset, SIGUSR1)) {
   62             pr_fail_err("sigismember");
   63             continue;
   64         }
   65 
   66         /* Unmask signal, signal is handled */
   67         (void)sigemptyset(&_sigset);
   68         (void)sigprocmask(SIG_SETMASK, &_sigset, NULL);
   69 
   70         /* And it is no longer pending */
   71         if (sigpending(&_sigset) < 0) {
   72             pr_fail_err("sigpending");
   73             continue;
   74         }
   75         if (sigismember(&_sigset, SIGUSR1)) {
   76             pr_fail_err("sigismember");
   77             continue;
   78         }
   79 
   80         inc_counter(args);
   81     } while (keep_stressing());
   82 
   83     return EXIT_SUCCESS;
   84 }
   85 
   86 stressor_info_t stress_sigpending_info = {
   87     .stressor = stress_sigpending,
   88     .class = CLASS_INTERRUPT | CLASS_OS
   89 };