"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-klog.c" (15 Mar 2019, 3244 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-klog.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 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 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_SYSLOG)
   28 
   29 #define SYSLOG_ACTION_CLOSE     (0)
   30 #define SYSLOG_ACTION_OPEN      (1)
   31 #define SYSLOG_ACTION_READ      (2)
   32 #define SYSLOG_ACTION_READ_ALL      (3)
   33 #define SYSLOG_ACTION_READ_CLEAR    (4)
   34 #define SYSLOG_ACTION_CLEAR     (5)
   35 #define SYSLOG_ACTION_CONSOLE_OFF   (6)
   36 #define SYSLOG_ACTION_CONSOLE_ON    (7)
   37 #define SYSLOG_ACTION_CONSOLE_LEVEL (8)
   38 #define SYSLOG_ACTION_SIZE_UNREAD   (9)
   39 #define SYSLOG_ACTION_SIZE_BUFFER   (10)
   40 
   41 /*
   42  *  stress_klog
   43  *  stress kernel logging interface
   44  */
   45 static int stress_klog(const args_t *args)
   46 {
   47     char *buffer;
   48     ssize_t len;
   49 
   50     len  = shim_syslog(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0);
   51     if (len < 0) {
   52         if (!args->instance)
   53             pr_err("%s: cannot determine syslog buffer "
   54                 "size: errno=%d (%s)\n",
   55                 args->name, errno, strerror(errno));
   56         return EXIT_NO_RESOURCE;
   57     }
   58     if (len == 0) {
   59         if (!args->instance)
   60             pr_err("%s: zero sized syslog buffer, aborting.\n", args->name);
   61         return EXIT_NO_RESOURCE;
   62     }
   63     if (len > (ssize_t)(4 * MB)) {
   64         if (!args->instance)
   65             pr_inf("%s: truncating syslog buffer to 4MB\n", args->name);
   66         len  = 4 * MB;
   67     }
   68     buffer = malloc((size_t)len);
   69     if (!buffer) {
   70         pr_err("%s: cannot allocate syslog buffer\n", args->name);
   71         return EXIT_NO_RESOURCE;
   72     }
   73 
   74     do {
   75         int ret, buflen = (mwc32() % len) + 1;
   76 
   77         ret = shim_syslog(SYSLOG_ACTION_READ_ALL, buffer, buflen);
   78         if (ret < 0)
   79             pr_fail_err("syslog ACTION_READ_ALL");
   80         if (ret > buflen)
   81             pr_fail("%s: syslog ACTION_READ_ALL returned more "
   82                 "data than was requested.\n", args->name);
   83 
   84         /* open, no-op, ignore failure */
   85         (void)shim_syslog(SYSLOG_ACTION_OPEN, NULL, 0);
   86 
   87         /* close, no-op, ignore failure */
   88         (void)shim_syslog(SYSLOG_ACTION_CLOSE, NULL, 0);
   89 
   90         /* get unread size, ignore failure */
   91         (void)shim_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0);
   92 
   93         /* get size of kernel buffer, ignore return */
   94         (void)shim_syslog(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0);
   95 
   96         inc_counter(args);
   97     } while (keep_stressing());
   98 
   99     free(buffer);
  100     return EXIT_SUCCESS;
  101 }
  102 
  103 stressor_info_t stress_klog_info = {
  104     .stressor = stress_klog,
  105     .class = CLASS_OS
  106 };
  107 #else
  108 stressor_info_t stress_klog_info = {
  109     .stressor = stress_not_implemented,
  110     .class = CLASS_OS
  111 };
  112 #endif