├── .github └── workflows │ ├── c-cpp.yml │ └── codeql-analysis.yml ├── Makefile.am ├── README.rst ├── common.am ├── configure.ac ├── getversion ├── gpl-2.0.txt ├── gpl-3.0.txt ├── m4 └── attributes.m4 ├── src ├── node │ ├── Makefile.am │ ├── README │ ├── inetd.c │ ├── munin-node-c.pod │ └── node.c └── plugins │ ├── Makefile.am │ ├── README │ ├── common.c │ ├── common.h │ ├── main.c │ ├── munin-plugins-c.pod │ ├── p │ ├── cpu.c │ ├── df.c │ ├── entropy.c │ ├── external_.c │ ├── forks.c │ ├── fw_packets.c │ ├── if_.c │ ├── if_err_.c │ ├── interrupts.c │ ├── iostat.c │ ├── load.c │ ├── memory.c │ ├── open_files.c │ ├── open_inodes.c │ ├── processes.c │ ├── swap.c │ ├── threads.c │ └── uptime.c │ └── plugins.h ├── systemd ├── munin-node-c.socket ├── munin-node-c@.service └── munin-node-daemon.service ├── t.conf └── env.conf └── t ├── Makefile.am ├── common.c ├── common.h ├── node_list ├── p ├── nb_env.c └── ok_plugin.c └── plugin_list /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: install indent 21 | run: sudo apt-get -y install indent 22 | 23 | - name: enforce code style 24 | run: find . -iname "*.[ch]" -exec indent -kr -i8 {} \; 25 | 26 | - name: check code style 27 | run: git diff --exit-code 28 | 29 | - name: autoconf 30 | run: autoreconf -i -I m4 31 | 32 | - name: configure 33 | run: ./configure 34 | 35 | - name: make 36 | run: make 37 | 38 | - name: make check 39 | run: make check 40 | 41 | - name: make distcheck 42 | run: make distcheck 43 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | 21 | jobs: 22 | analyze: 23 | name: Analyze 24 | runs-on: ubuntu-latest 25 | 26 | strategy: 27 | fail-fast: false 28 | matrix: 29 | language: [ 'cpp' ] 30 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 31 | # Learn more: 32 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 33 | 34 | steps: 35 | - name: Checkout repository 36 | uses: actions/checkout@v2 37 | 38 | # Initializes the CodeQL tools for scanning. 39 | - name: Initialize CodeQL 40 | uses: github/codeql-action/init@v1 41 | with: 42 | languages: ${{ matrix.language }} 43 | # If you wish to specify custom queries, you can do so here or in a config file. 44 | # By default, queries listed here will override any specified in a config file. 45 | # Prefix the list here with "+" to use these queries and those in the config file. 46 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 47 | 48 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 49 | # If this step fails, then you should remove it and run the build manually (see below) 50 | - name: Autobuild 51 | uses: github/codeql-action/autobuild@v1 52 | 53 | # ℹ️ Command-line programs to run using the OS shell. 54 | # 📚 https://git.io/JvXDl 55 | 56 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 57 | # and modify them (or add more) to build your code if your project 58 | # uses a compiled language 59 | 60 | #- run: | 61 | # make bootstrap 62 | # make release 63 | 64 | - name: Perform CodeQL Analysis 65 | uses: github/codeql-action/analyze@v1 66 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 Helmut Grohne - All rights reserved. 3 | # Copyright (C) 2013 Steve Schnepp - All rights reserved. 4 | # Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | # 6 | # This copyrighted material is made available to anyone wishing to use, 7 | # modify, copy, or redistribute it subject to the terms and conditions 8 | # of the GNU General Public License v.2 or v.3. 9 | # 10 | 11 | pkglibexecdir = $(libexecdir)/$(PACKAGE) 12 | 13 | ACLOCAL_AMFLAGS = -I m4 14 | 15 | SUBDIRS = src/node src/plugins t 16 | 17 | dist_doc_DATA = gpl-2.0.txt gpl-3.0.txt 18 | EXTRA_DIST = README.rst getversion t/plugin_list t/node_list 19 | 20 | TESTS = t/plugin_list t/node_list 21 | 22 | clean-local: 23 | rm -rf plugins 24 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | munin-c 2 | ======= 3 | 4 | C rewrite of munin node components. It currently consists on a light-weight 5 | node, and some plugins. These are designed to be very light on resources, 6 | and compatible with the stock ones. 7 | 8 | Compatibility 9 | ------------- 10 | 11 | A main design feature is that munin-c components are drop-ins to stock ones. 12 | Therefore the munin-c node can run the stock plugins, and the plugins can be 13 | run by the stock node. There are still some missing parts in the node, mostly 14 | about the permission, and the environnements. 15 | 16 | The config file has also the same syntax. 17 | 18 | 3rd-party plugins should also work unmodified. 19 | 20 | Compiling 21 | ========= 22 | This project has been ported to autotools. You have to use:: 23 | 24 | autoreconf -i -I m4 && ./configure && make 25 | 26 | 27 | 28 | Contribute and coding style 29 | =========================== 30 | Contribute by open an issue or pull-request at 31 | https://github.com/munin-monitoring/munin-c 32 | 33 | When contributing code please follow the kernel coding style. 34 | Use GNU indent with the parameters to follow the Kernighan & Ritchie coding 35 | style and set the indention level to 8 spaces:: 36 | 37 | find . -iname "*.c" -exec indent -kr -i8 {} \; 38 | 39 | License 40 | ======= 41 | munin-c is licensed as gpl-2 or gpl-3 at your choice. 42 | -------------------------------------------------------------------------------- /common.am: -------------------------------------------------------------------------------- 1 | MANCENTER="Munin C Documentation" 2 | 3 | %.1:%.pod 4 | $(AM_V_GEN)pod2man --section=1 --release=$(VERSION) --center=$(MANCENTER) $< > $@ 5 | sed -i -e 's#@@pkglibexecdir@@#$(pkglibexecdir)#' -e 's#@@CONFDIR@@#$(sysconfdir)#' $@ 6 | 7 | 8 | # vim:ft=make 9 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 Helmut Grohne - All rights reserved. 3 | # Copyright (C) 2013-2022 Steve Schnepp - All rights reserved. 4 | # Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | # 6 | # This copyrighted material is made available to anyone wishing to use, 7 | # modify, copy, or redistribute it subject to the terms and conditions 8 | # of the GNU General Public License v.2 or v.3. 9 | # 10 | 11 | AC_INIT([munin-c], [m4_esyscmd_s([./getversion])], [https://github.com/munin-monitoring/munin-c/issues], , [https://github.com/munin-monitoring/munin-c]) 12 | AC_CONFIG_AUX_DIR([build]) 13 | 14 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 15 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 16 | AM_MAINTAINER_MODE([enable]) 17 | 18 | AC_PROG_CC 19 | AC_PROG_CC_C_O 20 | 21 | AC_PROG_LN_S 22 | 23 | AC_CHECK_DECLS([environ]) 24 | 25 | AC_FUNC_FORK 26 | CC_CHECK_CFLAGS_APPEND([-Wall -Wextra -Werror -pedantic -Wno-format]) 27 | 28 | AC_MSG_CHECKING([whether to enable LTO]) 29 | AC_ARG_WITH(lto, 30 | [ --with-lto enable LTO) @<:@no@:>@], 31 | with_lto=$withval, 32 | with_lto=no) 33 | AC_MSG_RESULT($with_lto) 34 | if test "$with_lto" = "yes"; then 35 | CC_CHECK_CFLAGS_APPEND([-flto]) 36 | CC_CHECK_LDFLAGS_APPEND([-flto]) 37 | fi 38 | 39 | AC_MSG_CHECKING([whether to optimize for size]) 40 | AC_ARG_WITH(optimize_size, 41 | [ --with-optimize-size enable -Os) @<:@no@:>@], 42 | with_optimize_size=$withval, 43 | with_optimize_size=no) 44 | AC_MSG_RESULT($with_optimize_size) 45 | if test "$with_optimize_size" = "yes"; then 46 | CC_CHECK_CFLAGS_APPEND([-Os]) 47 | fi 48 | 49 | AC_CHECK_HEADERS([mntent.h sys/vfs.h]) 50 | 51 | AC_MSG_CHECKING([whether to enable legacy "fetch"]) 52 | AC_ARG_WITH(legacy_fetch, 53 | [ --with-legacy-fetch enable legacy fetch which does not add the "fetch" argument on plugin execution) @<:@yes@:>@], 54 | with_legacy_fetch=$withval, 55 | with_legacy_fetch=yes) 56 | AC_MSG_RESULT($with_legacy_fetch) 57 | if test "$with_legacy_fetch" = "yes"; then 58 | AC_DEFINE(LEGACY_FETCH) 59 | fi 60 | 61 | AC_MSG_CHECKING([whether to exit on vfork errors]) 62 | AC_ARG_WITH(exit_vfork_error, 63 | [ --with-exit-vfork-error exit on vfork errors @<:@no@:>@], 64 | with_exit_vfork_error=$withval, 65 | with_exit_vfork_error=no) 66 | AC_MSG_RESULT($with_exit_vfork_error) 67 | if test "$with_exit_vfork_error" = "yes"; then 68 | AC_DEFINE(INETD_EXIT_VFORK_ERROR) 69 | fi 70 | 71 | AC_CONFIG_FILES([Makefile src/node/Makefile src/plugins/Makefile t/Makefile]) 72 | AC_OUTPUT 73 | -------------------------------------------------------------------------------- /getversion: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Generate a version string for use when building. 4 | # 5 | # * If in a git repository use "git describe" 6 | # * If building from tarball extract the version from the directory name or 7 | # try to get the version fronm the packaging. 8 | 9 | 10 | generate_version_string_from_dir() { 11 | basename $(pwd) | grep -e '^munin-c' | cut -c9- 12 | } 13 | 14 | generate_version_string_from_packaging() { 15 | if [ -d debian ]; then 16 | dpkg-parsechangelog -SVersion 2> /dev/null 17 | fi 18 | } 19 | 20 | if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then 21 | git describe --always 22 | elif [ ! -z "$(generate_version_string_from_dir)" ]; then 23 | generate_version_string_from_dir 24 | elif [ ! -z "$(generate_version_string_from_packaging)" ]; then 25 | generate_version_string_from_packaging 26 | else 27 | echo "unknown" 28 | fi 29 | 30 | -------------------------------------------------------------------------------- /gpl-2.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /gpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /m4/attributes.m4: -------------------------------------------------------------------------------- 1 | dnl Macros to check the presence of generic (non-typed) symbols. 2 | dnl Copyright (c) 2006-2007 Diego Pettenò 3 | dnl Copyright (c) 2006-2007 xine project 4 | dnl 5 | dnl This program is free software; you can redistribute it and/or modify 6 | dnl it under the terms of the GNU General Public License as published by 7 | dnl the Free Software Foundation; either version 2, or (at your option) 8 | dnl any later version. 9 | dnl 10 | dnl This program is distributed in the hope that it will be useful, 11 | dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | dnl GNU General Public License for more details. 14 | dnl 15 | dnl You should have received a copy of the GNU General Public License 16 | dnl along with this program; if not, write to the Free Software 17 | dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 | dnl 02110-1301, USA. 19 | dnl 20 | dnl As a special exception, the copyright owners of the 21 | dnl macro gives unlimited permission to copy, distribute and modify the 22 | dnl configure scripts that are the output of Autoconf when processing the 23 | dnl Macro. You need not follow the terms of the GNU General Public 24 | dnl License when using or distributing such scripts, even though portions 25 | dnl of the text of the Macro appear in them. The GNU General Public 26 | dnl License (GPL) does govern all other use of the material that 27 | dnl constitutes the Autoconf Macro. 28 | dnl 29 | dnl This special exception to the GPL applies to versions of the 30 | dnl Autoconf Macro released by this project. When you make and 31 | dnl distribute a modified version of the Autoconf Macro, you may extend 32 | dnl this special exception to the GPL to apply to your modified version as 33 | dnl well. 34 | 35 | dnl Check if the flag is supported by compiler 36 | dnl CC_CHECK_CFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 37 | 38 | AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [ 39 | AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]), 40 | [ac_save_CFLAGS="$CFLAGS" 41 | CFLAGS="$CFLAGS $1" 42 | AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])], 43 | [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"], 44 | [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"]) 45 | CFLAGS="$ac_save_CFLAGS" 46 | ]) 47 | 48 | AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], 49 | [$2], [$3]) 50 | ]) 51 | 52 | dnl Check if the flag is supported by compiler (cacheable) 53 | dnl CC_CHECK_CFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 54 | 55 | AC_DEFUN([CC_CHECK_CFLAGS], [ 56 | AC_CACHE_CHECK([if $CC supports $1 flag], 57 | AS_TR_SH([cc_cv_cflags_$1]), 58 | CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here! 59 | ) 60 | 61 | AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], 62 | [$2], [$3]) 63 | ]) 64 | 65 | dnl CC_CHECK_CFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found]) 66 | dnl Check for CFLAG and appends them to CFLAGS if supported 67 | AC_DEFUN([CC_CHECK_CFLAG_APPEND], [ 68 | AC_CACHE_CHECK([if $CC supports $1 flag], 69 | AS_TR_SH([cc_cv_cflags_$1]), 70 | CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here! 71 | ) 72 | 73 | AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], 74 | [CFLAGS="$CFLAGS $1"; $2], [$3]) 75 | ]) 76 | 77 | dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not]) 78 | AC_DEFUN([CC_CHECK_CFLAGS_APPEND], [ 79 | for flag in $1; do 80 | CC_CHECK_CFLAG_APPEND($flag, [$2], [$3]) 81 | done 82 | ]) 83 | 84 | dnl Check if the flag is supported by compiler 85 | dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 86 | 87 | AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [ 88 | AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]), 89 | [ac_save_LDFLAGS="$LDFLAGS" 90 | LDFLAGS="$LDFLAGS $1" 91 | AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])], 92 | [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], 93 | [eval "AS_TR_SH([cc_cv_ldflags_$1])='no'"]) 94 | LDFLAGS="$ac_save_LDFLAGS" 95 | ]) 96 | 97 | AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], 98 | [$2], [$3]) 99 | ]) 100 | 101 | dnl Check if the flag is supported by linker (cacheable) 102 | dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 103 | 104 | AC_DEFUN([CC_CHECK_LDFLAGS], [ 105 | AC_CACHE_CHECK([if $CC supports $1 flag], 106 | AS_TR_SH([cc_cv_ldflags_$1]), 107 | [ac_save_LDFLAGS="$LDFLAGS" 108 | LDFLAGS="$LDFLAGS $1" 109 | AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])], 110 | [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], 111 | [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) 112 | LDFLAGS="$ac_save_LDFLAGS" 113 | ]) 114 | 115 | AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], 116 | [$2], [$3]) 117 | ]) 118 | 119 | dnl CC_CHECK_LDFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found]) 120 | dnl Check for LDFLAG and appends them to LDFLAGS if supported 121 | AC_DEFUN([CC_CHECK_LDFLAG_APPEND], [ 122 | AC_CACHE_CHECK([if $CC supports $1 flag], 123 | AS_TR_SH([cc_cv_ldflags_$1]), 124 | CC_CHECK_LDFLAGS_SILENT([$1]) dnl Don't execute actions here! 125 | ) 126 | 127 | AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], 128 | [LDFLAGS="$LDFLAGS $1"; $2], [$3]) 129 | ]) 130 | 131 | dnl CC_CHECK_LDFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not]) 132 | AC_DEFUN([CC_CHECK_LDFLAGS_APPEND], [ 133 | for flag in $1; do 134 | CC_CHECK_LDFLAG_APPEND($flag, [$2], [$3]) 135 | done 136 | ]) 137 | 138 | 139 | dnl Check for a -Werror flag or equivalent. -Werror is the GCC 140 | dnl and ICC flag that tells the compiler to treat all the warnings 141 | dnl as fatal. We usually need this option to make sure that some 142 | dnl constructs (like attributes) are not simply ignored. 143 | dnl 144 | dnl Other compilers don't support -Werror per se, but they support 145 | dnl an equivalent flag: 146 | dnl - Sun Studio compiler supports -errwarn=%all 147 | AC_DEFUN([CC_CHECK_WERROR], [ 148 | AC_CACHE_CHECK( 149 | [for $CC way to treat warnings as errors], 150 | [cc_cv_werror], 151 | [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror], 152 | [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])]) 153 | ]) 154 | ]) 155 | 156 | AC_DEFUN([CC_CHECK_ATTRIBUTE], [ 157 | AC_REQUIRE([CC_CHECK_WERROR]) 158 | AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))], 159 | AS_TR_SH([cc_cv_attribute_$1]), 160 | [ac_save_CFLAGS="$CFLAGS" 161 | CFLAGS="$CFLAGS $cc_cv_werror" 162 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], 163 | [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"], 164 | [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"]) 165 | CFLAGS="$ac_save_CFLAGS" 166 | ]) 167 | 168 | AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes], 169 | [AC_DEFINE( 170 | AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1, 171 | [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))] 172 | ) 173 | $4], 174 | [$5]) 175 | ]) 176 | 177 | AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ 178 | CC_CHECK_ATTRIBUTE( 179 | [constructor],, 180 | [extern void foo(); 181 | void __attribute__((constructor)) ctor() { foo(); }], 182 | [$1], [$2]) 183 | ]) 184 | 185 | AC_DEFUN([CC_ATTRIBUTE_DESTRUCTOR], [ 186 | CC_CHECK_ATTRIBUTE( 187 | [destructor],, 188 | [extern void foo(); 189 | void __attribute__((destructor)) dtor() { foo(); }], 190 | [$1], [$2]) 191 | ]) 192 | 193 | AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ 194 | CC_CHECK_ATTRIBUTE( 195 | [format], [format(printf, n, n)], 196 | [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }], 197 | [$1], [$2]) 198 | ]) 199 | 200 | AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [ 201 | CC_CHECK_ATTRIBUTE( 202 | [format_arg], [format_arg(printf)], 203 | [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }], 204 | [$1], [$2]) 205 | ]) 206 | 207 | AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ 208 | CC_CHECK_ATTRIBUTE( 209 | [visibility_$1], [visibility("$1")], 210 | [void __attribute__((visibility("$1"))) $1_function() { }], 211 | [$2], [$3]) 212 | ]) 213 | 214 | AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ 215 | CC_CHECK_ATTRIBUTE( 216 | [nonnull], [nonnull()], 217 | [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }], 218 | [$1], [$2]) 219 | ]) 220 | 221 | AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ 222 | CC_CHECK_ATTRIBUTE( 223 | [unused], , 224 | [void some_function(void *foo, __attribute__((unused)) void *bar);], 225 | [$1], [$2]) 226 | ]) 227 | 228 | AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [ 229 | CC_CHECK_ATTRIBUTE( 230 | [sentinel], , 231 | [void some_function(void *foo, ...) __attribute__((sentinel));], 232 | [$1], [$2]) 233 | ]) 234 | 235 | AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [ 236 | CC_CHECK_ATTRIBUTE( 237 | [deprecated], , 238 | [void some_function(void *foo, ...) __attribute__((deprecated));], 239 | [$1], [$2]) 240 | ]) 241 | 242 | AC_DEFUN([CC_ATTRIBUTE_ALIAS], [ 243 | CC_CHECK_ATTRIBUTE( 244 | [alias], [weak, alias], 245 | [void other_function(void *foo) { } 246 | void some_function(void *foo) __attribute__((weak, alias("other_function")));], 247 | [$1], [$2]) 248 | ]) 249 | 250 | AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ 251 | CC_CHECK_ATTRIBUTE( 252 | [malloc], , 253 | [void * __attribute__((malloc)) my_alloc(int n);], 254 | [$1], [$2]) 255 | ]) 256 | 257 | AC_DEFUN([CC_ATTRIBUTE_PACKED], [ 258 | CC_CHECK_ATTRIBUTE( 259 | [packed], , 260 | [struct astructure { char a; int b; long c; void *d; } __attribute__((packed)); 261 | char assert@<:@(sizeof(struct astructure) == (sizeof(char)+sizeof(int)+sizeof(long)+sizeof(void*)))-1@:>@;], 262 | [$1], [$2]) 263 | ]) 264 | 265 | AC_DEFUN([CC_ATTRIBUTE_CONST], [ 266 | CC_CHECK_ATTRIBUTE( 267 | [const], , 268 | [int __attribute__((const)) twopow(int n) { return 1 << n; } ], 269 | [$1], [$2]) 270 | ]) 271 | 272 | AC_DEFUN([CC_FLAG_VISIBILITY], [ 273 | AC_REQUIRE([CC_CHECK_WERROR]) 274 | AC_CACHE_CHECK([if $CC supports -fvisibility=hidden], 275 | [cc_cv_flag_visibility], 276 | [cc_flag_visibility_save_CFLAGS="$CFLAGS" 277 | CFLAGS="$CFLAGS $cc_cv_werror" 278 | CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden], 279 | cc_cv_flag_visibility='yes', 280 | cc_cv_flag_visibility='no') 281 | CFLAGS="$cc_flag_visibility_save_CFLAGS"]) 282 | 283 | AS_IF([test "x$cc_cv_flag_visibility" = "xyes"], 284 | [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1, 285 | [Define this if the compiler supports the -fvisibility flag]) 286 | $1], 287 | [$2]) 288 | ]) 289 | 290 | AC_DEFUN([CC_FUNC_EXPECT], [ 291 | AC_REQUIRE([CC_CHECK_WERROR]) 292 | AC_CACHE_CHECK([if compiler has __builtin_expect function], 293 | [cc_cv_func_expect], 294 | [ac_save_CFLAGS="$CFLAGS" 295 | CFLAGS="$CFLAGS $cc_cv_werror" 296 | AC_COMPILE_IFELSE( 297 | [int some_function() { 298 | int a = 3; 299 | return (int)__builtin_expect(a, 3); 300 | }], 301 | [cc_cv_func_expect=yes], 302 | [cc_cv_func_expect=no]) 303 | CFLAGS="$ac_save_CFLAGS" 304 | ]) 305 | 306 | AS_IF([test "x$cc_cv_func_expect" = "xyes"], 307 | [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1, 308 | [Define this if the compiler supports __builtin_expect() function]) 309 | $1], 310 | [$2]) 311 | ]) 312 | 313 | AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ 314 | AC_REQUIRE([CC_CHECK_WERROR]) 315 | AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported], 316 | [cc_cv_attribute_aligned], 317 | [ac_save_CFLAGS="$CFLAGS" 318 | CFLAGS="$CFLAGS $cc_cv_werror" 319 | for cc_attribute_align_try in 64 32 16 8 4 2; do 320 | AC_COMPILE_IFELSE([ 321 | int main() { 322 | static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0; 323 | return c; 324 | }], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) 325 | done 326 | CFLAGS="$ac_save_CFLAGS" 327 | ]) 328 | 329 | if test "x$cc_cv_attribute_aligned" != "x"; then 330 | AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned], 331 | [Define the highest alignment supported]) 332 | fi 333 | ]) 334 | -------------------------------------------------------------------------------- /src/node/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 Helmut Grohne - All rights reserved. 3 | # Copyright (C) 2013 Steve Schnepp - All rights reserved. 4 | # Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | # 6 | # This copyrighted material is made available to anyone wishing to use, 7 | # modify, copy, or redistribute it subject to the terms and conditions 8 | # of the GNU General Public License v.2 or v.3. 9 | # 10 | 11 | include $(top_srcdir)/common.am 12 | 13 | sbin_PROGRAMS = munin-node-c munin-inetd-c 14 | AM_CPPFLAGS = -DPLUGINDIR=\"$(sysconfdir)/munin/plugins\" \ 15 | -DPLUGINCONFDIR=\"$(sysconfdir)/munin/plugin-conf.d\" 16 | munin_node_c_SOURCES = node.c 17 | munin_inetd_c_SOURCES = inetd.c 18 | man_MANS = munin-node-c.1 19 | CLEANFILES = $(man_MANS) 20 | EXTRA_DIST = munin-node-c.pod 21 | -------------------------------------------------------------------------------- /src/node/README: -------------------------------------------------------------------------------- 1 | This is a rewrite of munin node in C. 2 | 3 | Pro: 4 | ---- 5 | 6 | The purpose is multiple: 7 | 8 | * reducing resource usage for embedded plateforms, specially when paired 9 | with the C rewrite of the core plugins. 10 | 11 | * no need for Perl 12 | 13 | * Everything runs from inetd. 14 | 15 | Cons: 16 | ----- 17 | 18 | * You lose flexibility 19 | 20 | It is compiled code, so you have to create binaries. Even one for each 21 | architecture. 22 | 23 | * Not all the features are implemented 24 | 25 | - root uid is not supported. All plugins are run with a single user, usually nobody. 26 | - no socket is opened. Everything runs from inetd. 27 | -------------------------------------------------------------------------------- /src/node/inetd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Steve Schnepp - All rights reserved. 3 | * Copyright (C) 2013 Helmut Grohne - All rights reserved. 4 | * Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | * 6 | * This copyrighted material is made available to anyone wishing to use, 7 | * modify, copy, or redistribute it subject to the terms and conditions 8 | * of the GNU General Public License v.2 or v.3. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #if !(defined(HAVE_WORKING_VFORK) || defined(S_SPLINT_S)) 23 | #define vfork fork 24 | #endif 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | static const int yes = 1; 29 | char *s; 30 | struct sockaddr_in server; 31 | unsigned int port; 32 | int sock_listen, sock_accept; 33 | pid_t pid; 34 | 35 | if (argc < 3) { 36 | fprintf(stderr, "usage: %s [ipaddr:]port program " 37 | "[argv0 argv1 ...]\n", argv[0]); 38 | return 1; 39 | } 40 | 41 | memset(&server, 0, sizeof(server)); 42 | server.sin_family = AF_INET; 43 | assert(argv[1] != NULL); 44 | s = strchr(argv[1], ':'); 45 | if (NULL == s) 46 | s = argv[1]; 47 | else { 48 | *s++ = '\0'; 49 | if (0 == inet_aton(argv[1], &server.sin_addr)) { 50 | fprintf(stderr, "not an ip address: %s\n", 51 | argv[1]); 52 | return 1; 53 | } 54 | } 55 | if ((1 != sscanf(s, "%u", &port)) || 56 | port != (unsigned int) (uint16_t) port) { 57 | fprintf(stderr, "not a valid port: %s\n", s); 58 | return 1; 59 | } 60 | server.sin_port = htons(port); 61 | if ((sock_listen = socket(AF_INET, SOCK_STREAM, 0)) < 0) { 62 | perror("socket creation failed"); 63 | return 1; 64 | } 65 | if (setsockopt 66 | (sock_listen, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) 67 | == -1) { 68 | perror("failed to set SO_REUSEADDR on socket"); 69 | } 70 | if (bind(sock_listen, (struct sockaddr *) &server, sizeof(server)) 71 | < 0) { 72 | perror("failed to bind socket"); 73 | close(sock_listen); 74 | return 1; 75 | } 76 | if (listen(sock_listen, 5) != 0) { 77 | perror("failed to listen on the socket"); 78 | close(sock_listen); 79 | return 1; 80 | } 81 | 82 | /* We do *not* care about childs */ 83 | signal(SIGCHLD, SIG_IGN); 84 | 85 | while ((sock_accept = accept(sock_listen, NULL, NULL)) != -1) { 86 | if (0 == (pid = vfork())) { 87 | /* we are in the child */ 88 | close(sock_listen); 89 | dup2(sock_accept, 0); 90 | dup2(sock_accept, 1); 91 | close(sock_accept); 92 | execvp(argv[2], argv + 3); 93 | /* according to vfork(2) we must use _exit */ 94 | _exit(1); 95 | } else { 96 | /* we are in the parent */ 97 | close(sock_accept); 98 | 99 | /* we didn't manage to fork */ 100 | if (pid == -1) { 101 | perror("vfork failed in " __FILE__); 102 | #ifdef INETD_EXIT_VFORK_ERROR 103 | return 1; 104 | #endif // INETD_EXIT_VFORK_ERROR 105 | } 106 | } 107 | } 108 | perror("accept failed in " __FILE__); 109 | close(sock_listen); 110 | return 1; 111 | } 112 | -------------------------------------------------------------------------------- /src/node/munin-node-c.pod: -------------------------------------------------------------------------------- 1 | =pod 2 | 3 | =head1 NAME 4 | 5 | munin-node-c - a single binary implementing the node functionality 6 | 7 | =head1 DESCRIPTION 8 | 9 | The munin-node-c binary can handle a single connection to a Munin node on stdin and stdout. 10 | It is usually run from an inetd like superserver. 11 | 12 | =head1 OPTIONS 13 | 14 | =over 15 | 16 | =item B<-d> I 17 | 18 | Specify the directory used to look up plugins. 19 | This directory usually contains symbolic links to installed plugins and executable scripts. 20 | The plugins are executed on request by the client to retrieve statistics about the system. 21 | 22 | =item B<-e> 23 | 24 | Enable extension stripping. 25 | When this option is given, filename extensions in plugins are ignored. 26 | This option is mainly useful on operating systems where extensions are relevant for execution. 27 | 28 | =item B<-H> I 29 | 30 | Specify the hostname with which the node should greet clients. 31 | 32 | =back 33 | 34 | =head1 AUTHORS 35 | 36 | Helmut Grohne, Steve Schnepp 37 | 38 | =cut 39 | -------------------------------------------------------------------------------- /src/node/node.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Steve Schnepp - All rights reserved. 3 | * Copyright (C) 2013 Helmut Grohne - All rights reserved. 4 | * Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | * 6 | * This copyrighted material is made available to anyone wishing to use, 7 | * modify, copy, or redistribute it subject to the terms and conditions 8 | * of the GNU General Public License v.2 or v.3. 9 | */ 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifndef HOST_NAME_MAX 31 | #define HOST_NAME_MAX 256 32 | #endif 33 | 34 | #ifndef LINE_MAX 35 | #define LINE_MAX 2048 36 | #endif 37 | 38 | extern char **environ; 39 | 40 | static const int yes = 1; 41 | static const int no = 0; 42 | 43 | static int is_acquire = 0; 44 | static int verbose = 0; 45 | static bool extension_stripping = false; 46 | 47 | static char *host = ""; 48 | static char *plugin_dir = PLUGINDIR; 49 | static char *spoolfetch_dir = ""; 50 | static char *client_ip = "-"; 51 | static char *pluginconf_dir = PLUGINCONFDIR; 52 | 53 | static int handle_connection(); 54 | 55 | #define xisspace(x) isspace((int)(unsigned char) x) 56 | #define xisdigit(x) isdigit((int)(unsigned char) x) 57 | 58 | static /*@noreturn@ */ void oom_handler() 59 | { 60 | static const char *OOM_MSG = "Out of memory\n"; 61 | 62 | if (write(STDERR_FILENO, OOM_MSG, sizeof(OOM_MSG) - 1) < 0) { 63 | /* Do nothing on write failure, we are torched anyway */ 64 | } 65 | 66 | /* OOM triggers abort() since it's better to fail fast */ 67 | abort(); 68 | } 69 | 70 | /* an allocation bigger than MAX_ALLOC_SIZE is bogus */ 71 | #define MAX_ALLOC_SIZE (16 * 1024 * 1024) 72 | static 73 | /*@only@ */ 74 | /*@out@ */ 75 | void *xmalloc(size_t size) 76 | { 77 | void *ptr; 78 | 79 | assert(size < MAX_ALLOC_SIZE); 80 | 81 | ptr = malloc(size); 82 | if (ptr == NULL) 83 | oom_handler(); 84 | return ptr; 85 | } 86 | 87 | static /*@only@ */ char *xstrdup(const char *s) 88 | { 89 | char *new_str; 90 | 91 | assert(s != NULL); 92 | assert(strlen(s) < MAX_ALLOC_SIZE); 93 | new_str = strdup(s); 94 | if (new_str == NULL) 95 | oom_handler(); 96 | return new_str; 97 | } 98 | 99 | static int xsetenv(const char *envname, const char *envval, int overwrite) 100 | { 101 | if (verbose) 102 | printf("# Setting env %s = %s %s overwriting\n", envname, 103 | envval, overwrite ? "with" : "without"); 104 | return setenv(envname, envval, overwrite); 105 | } 106 | 107 | static int find_plugin_with_basename( /*@out@ */ char *cmdline, 108 | const char *plugin_dir, 109 | const char *plugin_basename) 110 | { 111 | DIR *dirp = opendir(plugin_dir); 112 | struct dirent *dp; 113 | int found = 0; 114 | size_t plugin_basename_len = strlen(plugin_basename); 115 | 116 | if (dirp == NULL) { 117 | perror("Cannot open plugin dir in " __FILE__); 118 | return (found); 119 | } 120 | 121 | /* Empty cmdline */ 122 | cmdline[0] = '\0'; 123 | 124 | while ((dp = readdir(dirp)) != NULL) { 125 | char *plugin_filename = dp->d_name; 126 | 127 | if (plugin_filename[0] == '.') { 128 | /* No dotted plugin */ 129 | continue; 130 | } 131 | 132 | if (strncmp 133 | (plugin_filename, plugin_basename, 134 | plugin_basename_len) != 0) { 135 | /* Does not start with base */ 136 | continue; 137 | } 138 | 139 | if (plugin_filename[plugin_basename_len] != '\0' 140 | && plugin_filename[plugin_basename_len] != '.') { 141 | /* Does not end the string or start an extension */ 142 | continue; 143 | } 144 | 145 | snprintf(cmdline, LINE_MAX, "%s/%s", plugin_dir, 146 | plugin_filename); 147 | if (access(cmdline, X_OK) == 0) { 148 | /* Found it */ 149 | found++; 150 | break; 151 | } 152 | } 153 | closedir(dirp); 154 | 155 | return found; 156 | } 157 | 158 | 159 | int acquire_all(); 160 | static void setenvvars_system(void); 161 | 162 | int main(int argc, char *argv[]) 163 | { 164 | 165 | int optch; 166 | 167 | char format[] = "aevd:D:H:s:"; 168 | 169 | struct sockaddr_in client; 170 | 171 | socklen_t client_len = sizeof(client); 172 | 173 | opterr = 1; 174 | 175 | while ((optch = getopt(argc, argv, format)) != -1) 176 | switch (optch) { 177 | case 'a': 178 | is_acquire = true; 179 | break; 180 | case 'e': 181 | extension_stripping = true; 182 | break; 183 | case 'v': 184 | verbose++; 185 | break; 186 | case 'd': 187 | plugin_dir = xstrdup(optarg); 188 | break; 189 | case 'D': 190 | pluginconf_dir = xstrdup(optarg); 191 | break; 192 | case 'H': 193 | host = xstrdup(optarg); 194 | break; 195 | case 's': 196 | spoolfetch_dir = xstrdup(optarg); 197 | break; 198 | } 199 | 200 | /* get default hostname if not precised */ 201 | if ('\0' == *host) { 202 | int idx; 203 | 204 | host = xmalloc(HOST_NAME_MAX + 1); 205 | gethostname(host, HOST_NAME_MAX); 206 | 207 | /* going to lowercase */ 208 | for (idx = 0; host[idx] != '\0'; idx++) { 209 | host[idx] = tolower((int) host[idx]); 210 | } 211 | } 212 | 213 | /* Prepare static plugin env vars once for all */ 214 | setenvvars_system(); 215 | 216 | /* Asked to acquire */ 217 | if (is_acquire) 218 | return acquire_all(); 219 | 220 | /* use a 1-shot stdin/stdout */ 221 | if (0 == getpeername(STDIN_FILENO, (struct sockaddr *) &client, 222 | &client_len)) 223 | if (client.sin_family == AF_INET) 224 | client_ip = inet_ntoa(client.sin_addr); 225 | return handle_connection(); 226 | } 227 | 228 | /* Setting munin specific vars */ 229 | static void setenvvars_system() 230 | { 231 | /* Some locales use "," as decimal separator. 232 | * This can mess up a lot of plugins. */ 233 | xsetenv("LC_ALL", "C", yes); 234 | 235 | /* LC_ALL should be enough, but some plugins don't 236 | * follow specs (#1014) */ 237 | xsetenv("LANG", "C", yes); 238 | 239 | /* PATH should be *very* sane by default. Can be 240 | * overrided via config file if needed 241 | * (Closes #863 and #1128). */ 242 | xsetenv("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", yes); 243 | } 244 | 245 | /* Setting munin specific vars */ 246 | static void setenvvars_munin() 247 | { 248 | /* munin-node will override this with the IP of the 249 | * connecting master */ 250 | if (client_ip != NULL && client_ip[0] != '\0') { 251 | xsetenv("MUNIN_MASTER_IP", client_ip, no); 252 | } 253 | 254 | /* Tell plugins about supported capabilities */ 255 | xsetenv("MUNIN_CAP_MULTIGRAPH", "1", no); 256 | 257 | /* We only have one user, so using a fixed path */ 258 | xsetenv("MUNIN_PLUGSTATE", "/var/tmp", no); 259 | xsetenv("MUNIN_STATEFILE", "/dev/null", no); 260 | 261 | /* That's where plugins should live */ 262 | xsetenv("MUNIN_LIBDIR", "/usr/share/munin", no); 263 | } 264 | 265 | /* in-place */ 266 | static 267 | /*@null@ */ 268 | /*@exposed@ */ 269 | char *ltrim( /*@null@ */ char *s) 270 | { 271 | if (s == NULL || *s == '\0') { 272 | /* Empty string, returns unmodified */ 273 | return s; 274 | } 275 | 276 | while (xisspace(*s)) { 277 | s++; 278 | } 279 | 280 | return s; 281 | } 282 | 283 | /* in-place, but returns string for convenience */ 284 | static 285 | /*@null@ */ 286 | /*@exposed@ */ 287 | char *rtrim( /*@null@ */ char *s) 288 | { 289 | char *end; 290 | 291 | if (s == NULL || *s == '\0') { 292 | /* Empty string, returns unmodified */ 293 | return s; 294 | } 295 | 296 | end = s + strlen(s) - 1; 297 | while (end > s && xisspace(*end)) { 298 | /* Back from the end */ 299 | end--; 300 | } 301 | 302 | /* null-terminate new string */ 303 | end[1] = '\0'; 304 | 305 | return s; 306 | } 307 | 308 | /* in-place */ 309 | static 310 | /*@null@ */ 311 | /*@exposed@ */ 312 | char *trim( /*@null@ */ char *s) 313 | { 314 | s = ltrim(s); 315 | s = rtrim(s); 316 | 317 | return s; 318 | } 319 | 320 | #define MAX_ENV_BUF_SZ 256 321 | struct s_env { 322 | /* buffer will hold a C string : "KEY=VALUE", use the key_len to know where the "=" is */ 323 | size_t key_len; 324 | char buffer[MAX_ENV_BUF_SZ]; 325 | }; 326 | 327 | #define MAX_ENV_NB 256 328 | struct s_plugin_conf { 329 | char user[MAX_ENV_BUF_SZ]; 330 | char group[MAX_ENV_BUF_SZ]; 331 | 332 | /* pointer to array of env vars */ 333 | size_t size; 334 | size_t used; 335 | struct s_env *env; 336 | }; 337 | 338 | static void set_value(struct s_plugin_conf *conf, const char *key, 339 | const char *value) 340 | { 341 | size_t i; 342 | size_t key_len = strlen(key); 343 | 344 | if (key_len + strlen(value) + 1 >= MAX_ENV_BUF_SZ) { 345 | fprintf(stderr, "env var key+value too long: %.30s...\n", 346 | key); 347 | abort(); 348 | } 349 | 350 | struct s_env *dst_env = NULL; 351 | /* Search for the corresponding env */ 352 | for (i = 0; i < conf->used; i++) { 353 | struct s_env *env = conf->env + i; 354 | 355 | if (key_len != env->key_len) 356 | continue; 357 | 358 | /* this cmp works since keys have the same length */ 359 | if (memcmp(key, env->buffer, env->key_len) != 0) 360 | continue; 361 | 362 | /* Found the key */ 363 | dst_env = env; 364 | } 365 | 366 | if (dst_env == NULL) { 367 | /* Allocate one */ 368 | if (conf->used == MAX_ENV_NB) { 369 | fprintf(stderr, "ran out of internal env space\n"); 370 | abort(); 371 | } 372 | if (conf->used == conf->size) { 373 | conf->size = conf->size * 3 / 2; 374 | if (conf->size == 0) 375 | conf->size = 4; 376 | if (conf->size > MAX_ENV_NB) 377 | conf->size = MAX_ENV_NB; 378 | 379 | conf->env = 380 | realloc(conf->env, 381 | sizeof(struct s_env) * conf->size); 382 | if (conf->env == NULL) 383 | oom_handler(); 384 | } 385 | 386 | /* ptr arithmetic is done with int, not with size_t */ 387 | dst_env = conf->env + (int) conf->used; 388 | conf->used++; 389 | } 390 | 391 | /* Save the environment in setenv() format */ 392 | dst_env->key_len = key_len; 393 | snprintf(dst_env->buffer, MAX_ENV_BUF_SZ, "%s=%s", key, value); 394 | } 395 | 396 | static void end_before_first(char *s, char c) 397 | { 398 | s = strchr(s, c); 399 | if (s != NULL) 400 | *s = '\0'; 401 | } 402 | 403 | static struct s_plugin_conf *parse_plugin_conf(FILE * f, 404 | const char *plugin, 405 | struct s_plugin_conf *conf) 406 | { 407 | /* read from file */ 408 | char line[LINE_MAX]; 409 | bool is_relevant = false; 410 | 411 | while (fgets(line, LINE_MAX, f) != NULL) { 412 | char *line_trimmed = trim(line); 413 | assert(line_trimmed != NULL); 414 | if (line_trimmed[0] != '[' && !is_relevant) { 415 | /* Ignore the line */ 416 | continue; 417 | } 418 | 419 | if (line_trimmed[0] == '[') { 420 | line_trimmed++; 421 | end_before_first(line_trimmed, ']'); 422 | 423 | /* Try the key */ 424 | { 425 | int fnmatch_flags = 426 | FNM_NOESCAPE | FNM_PATHNAME; 427 | int res = fnmatch(line_trimmed, plugin, 428 | fnmatch_flags); 429 | if (res == 0) { 430 | is_relevant = true; 431 | } else if (res == FNM_NOMATCH) { 432 | is_relevant = false; 433 | } else { 434 | perror("fnmatch() error"); 435 | abort(); 436 | } 437 | } 438 | 439 | /* Next line */ 440 | continue; 441 | } 442 | 443 | { 444 | /* Parse the line, and add it to the current conf */ 445 | char *key = trim(strtok(line_trimmed, " ")); 446 | char *value; 447 | 448 | /* No key found, skip the line */ 449 | if (key == NULL) 450 | continue; 451 | 452 | /* Everything after the first " " is value */ 453 | value = trim(key + strlen(key) + 1); 454 | assert(value != NULL); 455 | 456 | if (0 == strcmp(key, "user")) { 457 | if (strlen(value) >= sizeof(conf->user)) { 458 | fprintf(stderr, 459 | "user name too long (%d >= %d)\n", 460 | (int) strlen(value), 461 | (int) sizeof(conf->user)); 462 | abort(); 463 | } 464 | strcpy(conf->user, value); 465 | } else if (0 == strcmp(key, "group")) { 466 | if (strlen(value) >= sizeof(conf->group)) { 467 | fprintf(stderr, 468 | "group name too long (%d >= %d)\n", 469 | (int) strlen(value), 470 | (int) sizeof(conf->group)); 471 | abort(); 472 | } 473 | strcpy(conf->group, value); 474 | } else if (0 == 475 | strncmp(key, "env.", strlen("env."))) { 476 | char *env_key = key + strlen("env."); 477 | set_value(conf, env_key, value); 478 | } 479 | } 480 | } 481 | 482 | return conf; 483 | } 484 | 485 | /* Setting user configured vars */ 486 | static void setenvvars_conf(char *current_plugin_name) 487 | { 488 | struct s_plugin_conf pconf; 489 | pconf.size = 0; 490 | pconf.used = 0; 491 | pconf.env = NULL; 492 | /* default is nobody:nogroup */ 493 | strcpy(pconf.user, "nobody"); 494 | strcpy(pconf.group, "nogroup"); 495 | 496 | /* TODO - add plugin conf parsing */ 497 | DIR *dirp = opendir(pluginconf_dir); 498 | if (dirp == NULL) { 499 | printf("# Cannot open plugin config dir '%s'\n", 500 | pluginconf_dir); 501 | } else { 502 | struct dirent *dp; 503 | while ((dp = readdir(dirp)) != NULL) { 504 | char cmdline[LINE_MAX]; 505 | char *plugin_filename = dp->d_name;; 506 | 507 | if (plugin_filename[0] == '.') { 508 | /* No dotted plugin */ 509 | continue; 510 | } 511 | 512 | snprintf(cmdline, LINE_MAX, "%s/%s", 513 | pluginconf_dir, plugin_filename); 514 | { 515 | FILE *f = fopen(cmdline, "r"); 516 | if (f == NULL) { 517 | /* Ignore open failures */ 518 | continue; 519 | } 520 | 521 | parse_plugin_conf(f, 522 | current_plugin_name, 523 | &pconf); 524 | 525 | fclose(f); 526 | } 527 | } 528 | 529 | closedir(dirp); 530 | } 531 | 532 | /* Set env after whole parsing */ 533 | { 534 | size_t i; 535 | for (i = 0; i < pconf.used; i++) { 536 | struct s_env *env = pconf.env + i; 537 | putenv(env->buffer); 538 | } 539 | /* Cannot free pconf.env array because putenv() keeps references to it */ 540 | } 541 | 542 | /* setuid/gid */ 543 | if (geteuid() == 0) { 544 | /* We *are* root */ 545 | int ret_val; 546 | struct group *grp; 547 | struct passwd *pswd; 548 | 549 | pswd = getpwnam(pconf.user); 550 | if (pswd == NULL) { 551 | perror("getpwnam() error"); 552 | abort(); 553 | } 554 | grp = getgrnam(pconf.group); 555 | if (grp == NULL) { 556 | perror("getgrnam() error"); 557 | abort(); 558 | } 559 | 560 | ret_val = setgid(grp->gr_gid); 561 | if ((ret_val != 0) 562 | || (getgid() != grp->gr_gid)) { 563 | perror("gid not changed by setgid"); 564 | abort(); 565 | } 566 | 567 | /* Change UID *after* GID, otherwise cannot change anymore */ 568 | ret_val = setuid(pswd->pw_uid); 569 | if ((ret_val != 0) 570 | || (getuid() != pswd->pw_uid)) { 571 | perror("uid not changed by setuid"); 572 | abort(); 573 | } 574 | } 575 | } 576 | 577 | static int handle_connection() 578 | { 579 | char line[LINE_MAX]; 580 | 581 | /* Prepare per connection plugin env vars */ 582 | setenvvars_munin(); 583 | 584 | printf("# munin node at %s\n", host); 585 | while (fflush(stdout), fgets(line, LINE_MAX, stdin) != NULL) { 586 | char *cmd; 587 | char *arg; 588 | 589 | cmd = strtok(line, " \t\n\r"); 590 | if (cmd == NULL) 591 | arg = NULL; 592 | else 593 | arg = strtok(NULL, " \t\n\r"); 594 | 595 | if (!cmd || strlen(cmd) == 0) { 596 | printf("# empty cmd\n"); 597 | } else if (strcmp(cmd, "version") == 0) { 598 | printf("munin c node version: %s\n", VERSION); 599 | } else if (strcmp(cmd, "nodes") == 0) { 600 | printf("%s\n", host); 601 | printf(".\n"); 602 | } else if (strcmp(cmd, "quit") == 0) { 603 | return (0); 604 | } else if (strcmp(cmd, "list") == 0) { 605 | DIR *dirp = opendir(plugin_dir); 606 | if (dirp == NULL) { 607 | printf("# Cannot open plugin dir\n"); 608 | return (0); 609 | } 610 | { 611 | struct dirent *dp; 612 | while ((dp = readdir(dirp)) != NULL) { 613 | char cmdline[LINE_MAX]; 614 | char *plugin_filename = 615 | dp->d_name;; 616 | 617 | if (plugin_filename[0] == '.') { 618 | /* No dotted plugin */ 619 | continue; 620 | } 621 | 622 | snprintf(cmdline, LINE_MAX, 623 | "%s/%s", plugin_dir, 624 | plugin_filename); 625 | if (access(cmdline, X_OK) == 0) { 626 | if (extension_stripping) { 627 | /* Strip after the last . */ 628 | char *last_dot_idx 629 | = 630 | strrchr 631 | (plugin_filename, 632 | '.'); 633 | if (last_dot_idx != 634 | NULL) { 635 | *last_dot_idx 636 | = '\0'; 637 | } 638 | } 639 | printf("%s ", 640 | plugin_filename); 641 | } 642 | } 643 | closedir(dirp); 644 | } 645 | putchar('\n'); 646 | } else if (strcmp(cmd, "config") == 0 || 647 | strcmp(cmd, "fetch") == 0) { 648 | char cmdline[LINE_MAX]; 649 | pid_t pid; 650 | if (arg == NULL) { 651 | printf("# no plugin given\n"); 652 | continue; 653 | } 654 | if (arg[0] == '.' || strchr(arg, '/') != NULL) { 655 | printf("# invalid plugin character\n"); 656 | continue; 657 | } 658 | if (!extension_stripping 659 | || find_plugin_with_basename(cmdline, 660 | plugin_dir, 661 | arg) == 0) { 662 | /* extension_stripping failed, using the plain method */ 663 | snprintf(cmdline, LINE_MAX, "%s/%s", 664 | plugin_dir, arg); 665 | } 666 | if (access(cmdline, X_OK) == -1) { 667 | printf("# unknown plugin: %s\n", arg); 668 | continue; 669 | } 670 | 671 | /* Using fork() here instead of vork() since we will 672 | * do a little more than a mere exec --> setenvvars_conf() */ 673 | pid = fork(); 674 | 675 | if (pid == -1) { 676 | printf("# fork failed\n"); 677 | continue; 678 | } else if (pid == 0) { 679 | /* Now is the time to set environnement */ 680 | setenvvars_conf(arg); 681 | #ifdef LEGACY_FETCH 682 | /* The munin-node implementation does not set arg[1] if "fetch" */ 683 | if (strcmp(cmd, "fetch") == 0) { 684 | cmd = NULL; 685 | } 686 | #endif // LEGACY_FETCH 687 | execl(cmdline, arg, cmd, NULL); 688 | 689 | // If we are here the execl() failed, bailing out with an error 690 | printf("# execl failed\n"); 691 | exit(EXIT_FAILURE); 692 | } 693 | 694 | waitpid(pid, NULL, 0); 695 | 696 | /* We need to send the whole EOF string, since the plugin might not end itself with "\n" */ 697 | printf("\n.\n"); 698 | } else if (strcmp(cmd, "cap") == 0) { 699 | printf("cap "); 700 | if ('\0' != *spoolfetch_dir) { 701 | printf("spool "); 702 | } 703 | printf("\n"); 704 | } else if (strcmp(cmd, "spoolfetch") == 0) { 705 | printf("# not implem yet cmd: %s\n", cmd); 706 | } else { 707 | printf 708 | ("# Unknown cmd: %s. Try cap, list, nodes, config, fetch, version or quit\n", 709 | cmd); 710 | } 711 | } 712 | 713 | return 0; 714 | } 715 | 716 | pid_t acquire(char *plugin_name, char *plugin_filename); 717 | 718 | int acquire_all() 719 | { 720 | DIR *dirp = opendir(plugin_dir); 721 | if (dirp == NULL) { 722 | printf("# Cannot open plugin dir\n"); 723 | return (0); 724 | } 725 | { 726 | struct dirent *dp; 727 | while ((dp = readdir(dirp)) != NULL) { 728 | char cmdline[LINE_MAX]; 729 | char *plugin_filename = dp->d_name;; 730 | 731 | if (plugin_filename[0] == '.') { 732 | /* No dotted plugin */ 733 | continue; 734 | } 735 | 736 | snprintf(cmdline, LINE_MAX, "%s/%s", plugin_dir, 737 | plugin_filename); 738 | if (access(cmdline, X_OK) == 0) { 739 | if (extension_stripping) { 740 | /* Strip after the last . */ 741 | char *last_dot_idx = 742 | strrchr(plugin_filename, '.'); 743 | if (last_dot_idx != NULL) { 744 | *last_dot_idx = '\0'; 745 | } 746 | } 747 | 748 | /* run acquire on that */ 749 | printf("# acquire %s\n", plugin_filename); 750 | acquire(plugin_filename, cmdline); 751 | } 752 | } 753 | closedir(dirp); 754 | } 755 | 756 | /* wait for all childrens to end */ 757 | { 758 | pid_t waited_pid; 759 | while ((waited_pid = wait(NULL)) != -1); 760 | } 761 | 762 | return 0; 763 | } 764 | 765 | pid_t acquire(char *plugin_name, char *plugin_filename) 766 | { 767 | /* continue in background */ 768 | pid_t child = fork(); 769 | if (child) { 770 | // Sleep for 20ms. Ease scheduling 771 | usleep(20 * 1000); 772 | return child; 773 | } 774 | 775 | setenvvars_munin(); 776 | setenvvars_conf(plugin_name); 777 | 778 | /* ask the plugin not to fork */ 779 | putenv("no_fork=1"); 780 | 781 | /* Go underwater */ 782 | close(STDIN_FILENO); 783 | close(STDOUT_FILENO); 784 | close(STDERR_FILENO); 785 | 786 | execl(plugin_filename, plugin_name, "acquire", NULL); 787 | 788 | /* should nevec come here */ 789 | exit(2); 790 | } 791 | -------------------------------------------------------------------------------- /src/plugins/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 Helmut Grohne - All rights reserved. 3 | # Copyright (C) 2013 Steve Schnepp - All rights reserved. 4 | # Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | # 6 | # This copyrighted material is made available to anyone wishing to use, 7 | # modify, copy, or redistribute it subject to the terms and conditions 8 | # of the GNU General Public License v.2 or v.3. 9 | # 10 | 11 | include $(top_srcdir)/common.am 12 | 13 | pkglibexec_PROGRAMS = munin-plugins-c 14 | munin_plugins_c_SOURCES = \ 15 | common.c \ 16 | common.h \ 17 | plugins.h \ 18 | p/cpu.c \ 19 | p/df.c \ 20 | p/entropy.c \ 21 | p/external_.c \ 22 | p/forks.c \ 23 | p/fw_packets.c \ 24 | p/if_.c \ 25 | p/if_err_.c \ 26 | p/interrupts.c \ 27 | p/iostat.c \ 28 | p/load.c \ 29 | p/open_files.c \ 30 | p/open_inodes.c \ 31 | p/processes.c \ 32 | p/swap.c \ 33 | p/threads.c \ 34 | p/memory.c \ 35 | p/uptime.c \ 36 | main.c 37 | man_MANS = munin-plugins-c.1 38 | CLEANFILES = $(man_MANS) 39 | EXTRA_DIST = munin-plugins-c.pod 40 | -------------------------------------------------------------------------------- /src/plugins/README: -------------------------------------------------------------------------------- 1 | What is this? 2 | ~~~~~~~~~~~~~ 3 | This is a rewrite of commonly used munin plugins in C as a single binary. 4 | The purpose is reducing resource usage: 5 | * disk space: the binary is smaller than the plugins together 6 | * more diskspace: it has no dependencies on other programs 7 | * less forks: it does not fork internally 8 | * faster startup: it doesn't start perl or shell 9 | * less memory: just a small C program 10 | * less file accesses: one binary for many plugins 11 | This can be useful for machines with restricted resources like embedded 12 | machines. 13 | 14 | What plugins are included? 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | cpu entropy forks fw_packets interrupts load open_files open_inodes 17 | processes swap uptime 18 | 19 | Disadvantages? 20 | ~~~~~~~~~~~~~~ 21 | You lose flexibility. You can no longer just edit the plugin and if you try 22 | you have to be very careful not to break it. If you want to deploy this you 23 | have to create one binary for each architecture. 24 | 25 | How to use? 26 | ~~~~~~~~~~~ 27 | After compiling there will be binary munin-plugins-c. You can just 28 | replace symlinks in /etc/munin/plugins/ with symlinks to this binary. 29 | 30 | # vim7:spelllang=en 31 | # vim:textwidth=75 32 | -------------------------------------------------------------------------------- /src/plugins/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "common.h" 14 | 15 | #if !HAVE_DECL_ENVIRON 16 | extern char **environ; 17 | #endif 18 | 19 | int writeyes(void) 20 | { 21 | puts("yes"); 22 | return 0; 23 | } 24 | 25 | int autoconf_check_readable(const char *path) 26 | { 27 | if (0 == access(path, R_OK)) 28 | return writeyes(); 29 | else { 30 | printf("no (%s is not readable, errno=%d)\n", path, errno); 31 | return 0; 32 | } 33 | } 34 | 35 | int getenvint(const char *name, int defvalue) 36 | { 37 | const char *value; 38 | value = getenv(name); 39 | if (value == NULL) 40 | return defvalue; 41 | return atoi(value); 42 | } 43 | 44 | static 45 | /*@null@ */ 46 | /*@observer@ */ 47 | const char *getenv_composed(const char *name1, const char *name2) 48 | { 49 | char **p; 50 | size_t len1 = strlen(name1), len2 = strlen(name2); 51 | for (p = environ; *p; ++p) { 52 | if (0 == strncmp(*p, name1, len1) && 53 | 0 == strncmp(len1 + *p, name2, len2) && 54 | (*p)[len1 + len2] == '=') 55 | return len1 + len2 + 1 + *p; 56 | } 57 | return NULL; 58 | } 59 | 60 | void print_warning(const char *name) 61 | { 62 | const char *p; 63 | p = getenv_composed(name, "_warning"); 64 | if (p == NULL) 65 | p = getenv("warning"); 66 | if (p == NULL) 67 | return; 68 | 69 | printf("%s.warning %s\n", name, p); 70 | } 71 | 72 | void print_critical(const char *name) 73 | { 74 | const char *p; 75 | p = getenv_composed(name, "_critical"); 76 | if (p == NULL) 77 | p = getenv("critical"); 78 | if (p == NULL) 79 | return; 80 | 81 | printf("%s.critical %s\n", name, p); 82 | } 83 | 84 | void print_warncrit(const char *name) 85 | { 86 | print_warning(name); 87 | print_critical(name); 88 | } 89 | 90 | int fail(const char *message) 91 | { 92 | fputs(message, stderr); 93 | fputc('\n', stderr); 94 | return 1; 95 | } 96 | -------------------------------------------------------------------------------- /src/plugins/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #ifndef COMMON_H 9 | #define COMMON_H 10 | 11 | #define PROC_STAT "/proc/stat" 12 | 13 | /** Write yes to stdout and return 0. The intended use is give an autoconf 14 | * response like "return writeyes();". 15 | * @returns a success state to be passed on as the return value from main */ 16 | int writeyes(void); 17 | 18 | /** Answer an autoconf request by checking the readability of the given file. 19 | */ 20 | int autoconf_check_readable(const char *); 21 | 22 | /** Obtain an integer value from the environment. In the absence of the 23 | * variable the given defaultvalue is returned. */ 24 | int getenvint(const char *, int defaultvalue); 25 | 26 | /** Print a name.warning line using the "name_warning" or "warning" environment 27 | * variables. */ 28 | void print_warning(const char *name); 29 | 30 | /** Print a name.critical line using the "name_critical" or "critical" 31 | * environment variables. */ 32 | void print_critical(const char *name); 33 | 34 | /** Print both name.warning and name.critical lines using environment 35 | * variables. */ 36 | void print_warncrit(const char *name); 37 | 38 | /** Fail by printing the given message and a newline to stderr. 39 | * @returns a failure state to be passed on as the return value from main */ 40 | int fail(const char *message); 41 | 42 | #define xisspace(x) isspace((int)(unsigned char) x) 43 | #define xisdigit(x) isdigit((int)(unsigned char) x) 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/plugins/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * Copyright (C) 2013 Steve Schnepp - All rights reserved. 4 | * Copyright (C) 2013 Diego Elio Petteno - All rights reserved. 5 | * 6 | * This copyrighted material is made available to anyone wishing to use, 7 | * modify, copy, or redistribute it subject to the terms and conditions 8 | * of the GNU General Public License v.2 or v.3. 9 | */ 10 | #include 11 | #include 12 | #include 13 | #include "common.h" 14 | #include "plugins.h" 15 | 16 | static int busybox(int argc, char **argv) 17 | { 18 | if (argc < 2) 19 | return fail("missing parameter"); 20 | if (0 != strcmp(argv[1], "listplugins")) 21 | return fail("unknown parameter"); 22 | if (argc > 3 || (argc > 2 && 23 | 0 != strcmp(argv[2], "--include-experimental"))) 24 | return fail("unknown option"); 25 | 26 | /* The following is focused on readability over efficiency. */ 27 | puts("cpu"); 28 | puts("df"); 29 | puts("entropy"); 30 | puts("forks"); 31 | puts("fw_packets"); 32 | puts("interrupts"); 33 | puts("iostat"); 34 | puts("load"); 35 | puts("open_files"); 36 | puts("open_inodes"); 37 | puts("swap"); 38 | puts("threads"); 39 | puts("uptime"); 40 | 41 | if (argc > 2) { 42 | puts("memory"); 43 | puts("processes"); 44 | puts("external_"); 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | int main(int argc, char **argv) 51 | { 52 | char *progname; 53 | char *ext; 54 | progname = basename(argv[0]); 55 | ext = strrchr(progname, '.'); 56 | if (ext != NULL) 57 | ext[0] = '\0'; 58 | switch (*progname) { 59 | case 'c': 60 | if (!strcmp(progname, "cpu")) 61 | return cpu(argc, argv); 62 | break; 63 | case 'd': 64 | if (!strcmp(progname, "df")) 65 | return df(argc, argv); 66 | break; 67 | case 'e': 68 | if (!strcmp(progname, "entropy")) 69 | return entropy(argc, argv); 70 | if (!strncmp(progname, "external_", strlen("external_"))) 71 | return external_(argc, argv); 72 | break; 73 | case 'f': 74 | if (!strcmp(progname, "forks")) 75 | return forks(argc, argv); 76 | if (!strcmp(progname, "fw_packets")) 77 | return fw_packets(argc, argv); 78 | break; 79 | case 'i': 80 | if (!strcmp(progname, "interrupts")) 81 | return interrupts(argc, argv); 82 | if (!strncmp(progname, "if_err_", strlen("if_err_"))) 83 | return if_err_(argc, argv); 84 | if (!strncmp(progname, "if_", strlen("if_"))) 85 | return if_(argc, argv); 86 | if (!strcmp(progname, "iostat")) 87 | return iostat(argc, argv); 88 | break; 89 | case 'l': 90 | if (!strcmp(progname, "load")) 91 | return load(argc, argv); 92 | break; 93 | case 'm': 94 | if (!strcmp(progname, "memory")) 95 | return memory(argc, argv); 96 | if (!strcmp(progname, "munin-plugins-c")) 97 | return busybox(argc, argv); 98 | break; 99 | case 'o': 100 | if (!strcmp(progname, "open_files")) 101 | return open_files(argc, argv); 102 | if (!strcmp(progname, "open_inodes")) 103 | return open_inodes(argc, argv); 104 | break; 105 | case 'p': 106 | if (!strcmp(progname, "processes")) 107 | return processes(argc, argv); 108 | break; 109 | case 's': 110 | if (!strcmp(progname, "swap")) 111 | return swap(argc, argv); 112 | break; 113 | case 't': 114 | if (!strcmp(progname, "threads")) 115 | return threads(argc, argv); 116 | break; 117 | case 'u': 118 | if (!strcmp(progname, "uptime")) 119 | return uptime(argc, argv); 120 | break; 121 | } 122 | return fail("unknown basename"); 123 | } 124 | -------------------------------------------------------------------------------- /src/plugins/munin-plugins-c.pod: -------------------------------------------------------------------------------- 1 | =pod 2 | 3 | =head1 NAME 4 | 5 | munin-plugins-c - a single binary implementing a number of basic Munin plugins 6 | 7 | =head1 DESCRIPTION 8 | 9 | A Munin node runs plugins to gather statistics about the system. 10 | Most of the plugins were originally written in Perl or Shell for simplicity. 11 | The munin-plugins-c binary implements a number of the plugins as a single binary. 12 | It was written for reduced footprint in terms of system resources. 13 | Similar to the busybox utility, it evaluates the name it is called as. 14 | 15 | =head1 USAGE 16 | 17 | Discovering available plugins: 18 | 19 | @@pkglibexecdir@@/munin-plugins-c listplugins 20 | 21 | Enabling the I plugin: 22 | 23 | ln -s @@pkglibexecdir@@/munin-plugins-c @@CONFDIR@@/plugins/cpu 24 | 25 | =head1 AUTHORS 26 | 27 | Helmut Grohne, Steve Schnepp 28 | 29 | =cut 30 | -------------------------------------------------------------------------------- /src/plugins/p/cpu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * Copyright (C) 2013 Steve Schnepp - All rights reserved. 4 | * 5 | * This copyrighted material is made available to anyone wishing to use, 6 | * modify, copy, or redistribute it subject to the terms and conditions 7 | * of the GNU General Public License v.2 or v.3. 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "common.h" 18 | #include "plugins.h" 19 | 20 | #define SYSWARNING 30 21 | #define SYSCRITICAL 50 22 | #define USRWARNING 80 23 | 24 | /* TODO: port support for env.foo_warning and env.foo_critical from mainline plugin */ 25 | 26 | static int print_stat_value(const char *field_name, const char *stat_value, 27 | int hz_) 28 | { 29 | uint64_t stat_value_ll = strtoull(stat_value, NULL, 0); 30 | if (hz_ != 0) { 31 | /* hz_ is not ZERO, narmalize the value */ 32 | stat_value_ll = stat_value_ll * 100 / hz_; 33 | } 34 | return printf("%s.value %" PRIu64 "\n", field_name, stat_value_ll); 35 | } 36 | 37 | static int parse_cpu_line(char *buff) 38 | { 39 | char *s; 40 | int hz_ = getenvint("HZ", 100); 41 | if (!(s = strtok(buff + 4, " \t"))) 42 | return -1; 43 | print_stat_value("user", s, hz_); 44 | if (!(s = strtok(NULL, " \t"))) 45 | return -1; 46 | print_stat_value("nice", s, hz_); 47 | if (!(s = strtok(NULL, " \t"))) 48 | return -1; 49 | print_stat_value("system", s, hz_); 50 | if (!(s = strtok(NULL, " \t"))) 51 | return -1; 52 | print_stat_value("idle", s, hz_); 53 | if (!(s = strtok(NULL, " \t"))) 54 | return 0; 55 | print_stat_value("iowait", s, hz_); 56 | if (!(s = strtok(NULL, " \t"))) 57 | return 0; 58 | print_stat_value("irq", s, hz_); 59 | if (!(s = strtok(NULL, " \t"))) 60 | return 0; 61 | print_stat_value("softirq", s, hz_); 62 | if (!(s = strtok(NULL, " \t"))) 63 | return 0; 64 | print_stat_value("steal", s, hz_); 65 | if (!(s = strtok(NULL, " \t"))) 66 | return 0; 67 | print_stat_value("guest", s, hz_); 68 | return 0; 69 | } 70 | 71 | int cpu(int argc, char **argv) 72 | { 73 | FILE *f; 74 | char buff[256]; 75 | int ncpu = 0, extinfo = 0, ret; 76 | bool scaleto100 = false; 77 | if (argc > 1) { 78 | if (!strcmp(argv[1], "config")) { 79 | char *s = getenv("scaleto100"); 80 | if (s && !strcmp(s, "yes")) 81 | scaleto100 = true; 82 | 83 | if (!(f = fopen(PROC_STAT, "r"))) 84 | return fail("cannot open " PROC_STAT); 85 | while (fgets(buff, 256, f)) { 86 | if (!strncmp(buff, "cpu", 3)) { 87 | if (xisdigit(buff[3])) 88 | ncpu++; 89 | if (buff[3] == ' ' && 0 == extinfo) { 90 | strtok(buff + 4, " \t"); 91 | for (extinfo = 1; 92 | strtok(NULL, " \t"); 93 | extinfo++); 94 | } 95 | } 96 | } 97 | fclose(f); 98 | 99 | if (ncpu < 1 || extinfo < 4) 100 | return fail("cannot parse " PROC_STAT); 101 | 102 | puts("graph_title CPU usage"); 103 | if (extinfo >= 7) 104 | puts("graph_order system user nice idle iowait irq softirq"); 105 | else 106 | puts("graph_order system user nice idle"); 107 | if (scaleto100) 108 | puts("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100"); 109 | else 110 | printf 111 | ("graph_args --base 1000 -r --lower-limit 0 --upper-limit %d\n", 112 | 110 * ncpu); 113 | puts("graph_vlabel %\n" "graph_scale no\n" 114 | "graph_info This graph shows how CPU time is spent.\n" 115 | "graph_category system\n" 116 | "graph_period second\n" 117 | "system.label system\n" "system.draw AREA"); 118 | printf("system.max %d\n", 110 * ncpu); 119 | puts("system.min 0\n" "system.type DERIVE"); 120 | printf("system.warning %d\n", SYSWARNING * ncpu); 121 | printf("system.critical %d\n", SYSCRITICAL * ncpu); 122 | puts("system.info CPU time spent by the kernel in system activities\n" "user.label user\n" "user.draw STACK\n" "user.min 0"); 123 | printf("user.max %d\n", 110 * ncpu); 124 | printf("user.warning %d\n", USRWARNING * ncpu); 125 | puts("user.type DERIVE\n" 126 | "user.info CPU time spent by normal programs and daemons\n" 127 | "nice.label nice\n" 128 | "nice.draw STACK\n" "nice.min 0"); 129 | printf("nice.max %d\n", 110 * ncpu); 130 | puts("nice.type DERIVE\n" 131 | "nice.info CPU time spent by nice(1)d programs\n" 132 | "idle.label idle\n" 133 | "idle.draw STACK\n" "idle.min 0"); 134 | printf("idle.max %d\n", 110 * ncpu); 135 | puts("idle.type DERIVE\n" 136 | "idle.info Idle CPU time"); 137 | if (scaleto100) 138 | printf("system.cdef system,%d,/\n" 139 | "user.cdef user,%d,/\n" 140 | "nice.cdef nice,%d,/\n" 141 | "idle.cdef idle,%d,/\n", ncpu, ncpu, 142 | ncpu, ncpu); 143 | if (extinfo >= 7) { 144 | puts("iowait.label iowait\n" 145 | "iowait.draw STACK\n" "iowait.min 0"); 146 | printf("iowait.max %d\n", 110 * ncpu); 147 | puts("iowait.type DERIVE\n" 148 | "iowait.info CPU time spent waiting for I/O operations to finish\n" 149 | "irq.label irq\n" 150 | "irq.draw STACK\n" "irq.min 0"); 151 | printf("irq.max %d\n", 110 * ncpu); 152 | puts("irq.type DERIVE\n" 153 | "irq.info CPU time spent handling interrupts\n" 154 | "softirq.label softirq\n" 155 | "softirq.draw STACK\n" 156 | "softirq.min 0"); 157 | printf("softirq.max %d\n", 110 * ncpu); 158 | puts("softirq.type DERIVE\n" 159 | "softirq.info CPU time spent handling \"batched\" interrupts"); 160 | if (scaleto100) 161 | printf("iowait.cdef iowait,%d,/\n" 162 | "irq.cdef irq,%d,/\n" 163 | "softirq.cdef softirq,%d,/\n", 164 | ncpu, ncpu, ncpu); 165 | } 166 | if (extinfo >= 8) { 167 | puts("steal.label steal\n" 168 | "steal.draw STACK\n" "steal.min 0"); 169 | printf("steal.max %d\n", 110 * ncpu); 170 | puts("steal.type DERIVE\n" 171 | "steal.info The time that a virtual CPU had runnable tasks, but the virtual CPU itself was not running"); 172 | if (scaleto100) 173 | printf("steal.cdef steal,%d,/\n", 174 | ncpu); 175 | } 176 | if (extinfo >= 9) { 177 | puts("guest.label guest\n" 178 | "guest.draw STACK\n" "guest.min 0"); 179 | printf("guest.max %d\n", 110 * ncpu); 180 | puts("guest.type DERIVE\n" 181 | "guest.info The time spent running a virtual CPU for guest operating systems under the control of the Linux kernel."); 182 | if (scaleto100) 183 | printf("guest.cdef guest,%d,/\n", 184 | ncpu); 185 | } 186 | return 0; 187 | } 188 | if (!strcmp(argv[1], "autoconf")) 189 | return autoconf_check_readable(PROC_STAT); 190 | } 191 | if (!(f = fopen(PROC_STAT, "r"))) 192 | return fail("cannot open " PROC_STAT); 193 | while (fgets(buff, 256, f)) { 194 | if (!strncmp(buff, "cpu ", 4)) { 195 | ret = parse_cpu_line(buff); 196 | goto OK; 197 | } 198 | } 199 | /* We didn't find anyting */ 200 | ret = fail("no cpu line found in " PROC_STAT); 201 | OK: 202 | fclose(f); 203 | return ret; 204 | } 205 | -------------------------------------------------------------------------------- /src/plugins/p/df.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Bastiaan van Kesteren - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef HAVE_MNTENT_H 15 | #include /* for getmntent(), et al. */ 16 | #endif 17 | 18 | #include /* for getopt() */ 19 | #include 20 | 21 | #ifdef HAVE_SYS_VFS_H 22 | #include 23 | #endif 24 | 25 | #include "common.h" 26 | 27 | /* Defines taken from statfs(2) man page: */ 28 | #define ISOFS_SUPER_MAGIC 0x9660 29 | #define SQUASHFS_MAGIC 0x73717368 30 | #define UDF_SUPER_MAGIC 0x15013346 31 | #define ROMFS_MAGIC 0x7275 32 | #define RAMFS_MAGIC 0x858458f6 33 | #define DEBUGFS_MAGIC 0x64626720 34 | #define CGROUP_SUPER_MAGIC 0x27e0eb 35 | #define DEVPTS_SUPER_MAGIC 0x1cd1 36 | 37 | 38 | #ifndef HAVE_MNTENT_H 39 | int df(int argc, char **argv) 40 | { 41 | if (argc && argv) { 42 | /* Do nothing, but silence the warnings */ 43 | } 44 | return fail("getmntent() is not supported on your system"); 45 | } 46 | #else 47 | 48 | static char *replace_slash(char *c) 49 | { 50 | char *p = c; 51 | 52 | while (*p) { 53 | if (*p == '/') { 54 | *p = '_'; 55 | } 56 | p++; 57 | } 58 | return c; 59 | } 60 | 61 | int df(int argc, char **argv) 62 | { 63 | FILE *fp; 64 | struct mntent *fs; 65 | struct statfs vfs; 66 | 67 | fp = setmntent("/etc/mtab", "r"); 68 | if (fp == NULL) { 69 | return fail("cannot open /etc/mtab"); 70 | } 71 | 72 | if (argc > 1) { 73 | if (strcmp(argv[1], "config") == 0) { 74 | printf("graph_title Disk usage in percent\n" 75 | "graph_args --upper-limit 100 -l 0\n" 76 | "graph_vlabel %%\n" 77 | "graph_scale no\n" "graph_category disk\n"); 78 | 79 | while ((fs = getmntent(fp)) != NULL) { 80 | if (fs->mnt_fsname[0] != '/') { 81 | continue; 82 | } 83 | 84 | if (statfs(fs->mnt_dir, &vfs) != 0) { 85 | continue; 86 | } 87 | 88 | if ((unsigned int) vfs.f_type == 89 | ISOFS_SUPER_MAGIC 90 | || (unsigned int) vfs.f_type == 91 | SQUASHFS_MAGIC 92 | || (unsigned int) vfs.f_type == 93 | UDF_SUPER_MAGIC 94 | || (unsigned int) vfs.f_type == 95 | ROMFS_MAGIC 96 | || (unsigned int) vfs.f_type == 97 | RAMFS_MAGIC 98 | || (unsigned int) vfs.f_type == 99 | DEBUGFS_MAGIC 100 | || (unsigned int) vfs.f_type == 101 | CGROUP_SUPER_MAGIC 102 | || (unsigned int) vfs.f_type == 103 | DEVPTS_SUPER_MAGIC) { 104 | continue; 105 | } 106 | 107 | printf("%s.label %s\n", 108 | replace_slash(fs->mnt_fsname), 109 | fs->mnt_dir); 110 | } 111 | endmntent(fp); 112 | 113 | return 0; 114 | } 115 | } 116 | 117 | /* Asking for a fetch */ 118 | while ((fs = getmntent(fp)) != NULL) { 119 | if (fs->mnt_fsname[0] != '/') { 120 | continue; 121 | } 122 | 123 | if (statfs(fs->mnt_dir, &vfs) != 0) { 124 | continue; 125 | } 126 | 127 | if ((unsigned int) vfs.f_type == ISOFS_SUPER_MAGIC || 128 | (unsigned int) vfs.f_type == SQUASHFS_MAGIC || 129 | (unsigned int) vfs.f_type == UDF_SUPER_MAGIC || 130 | (unsigned int) vfs.f_type == ROMFS_MAGIC || 131 | (unsigned int) vfs.f_type == RAMFS_MAGIC || 132 | (unsigned int) vfs.f_type == DEBUGFS_MAGIC || 133 | (unsigned int) vfs.f_type == CGROUP_SUPER_MAGIC || 134 | (unsigned int) vfs.f_type == DEVPTS_SUPER_MAGIC) { 135 | continue; 136 | } 137 | 138 | printf("%s.value %lf\n", replace_slash(fs->mnt_fsname), 139 | (100.0 / vfs.f_blocks) * (vfs.f_blocks - 140 | vfs.f_bfree)); 141 | } 142 | endmntent(fp); 143 | 144 | return 0; 145 | } 146 | #endif 147 | -------------------------------------------------------------------------------- /src/plugins/p/entropy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include "common.h" 12 | #include "plugins.h" 13 | 14 | #define ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail" 15 | 16 | int entropy(int argc, char **argv) 17 | { 18 | FILE *f; 19 | int entropy; 20 | if (argc > 1) { 21 | if (!strcmp(argv[1], "config")) { 22 | puts("graph_title Available entropy\n" 23 | "graph_args --base 1000 -l 0\n" 24 | "graph_vlabel entropy (bytes)\n" 25 | "graph_scale no\n" 26 | "graph_category system\n" 27 | "graph_info This graph shows the amount of entropy available in the system.\n" 28 | "entropy.label entropy\n" 29 | "entropy.info The number of random bytes available. This is typically used by cryptographic applications."); 30 | print_warncrit("entropy"); 31 | return 0; 32 | } 33 | if (!strcmp(argv[1], "autoconf")) 34 | return autoconf_check_readable(ENTROPY_AVAIL); 35 | } 36 | if (!(f = fopen(ENTROPY_AVAIL, "r"))) 37 | return fail("cannot open " ENTROPY_AVAIL); 38 | if (1 != fscanf(f, "%d", &entropy)) { 39 | fclose(f); 40 | return fail("cannot read from " ENTROPY_AVAIL); 41 | } 42 | fclose(f); 43 | printf("entropy.value %d\n", entropy); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/plugins/p/external_.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Steve Schnepp - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #include "common.h" 18 | #include "plugins.h" 19 | 20 | #ifndef LINE_MAX 21 | #define LINE_MAX 2048 22 | #endif 23 | 24 | static const char MAGIC_BOM_UTF8[] = "\xEF\xBB\xBF"; 25 | 26 | static int read_file_to_stdout(const char *filename) 27 | { 28 | FILE *f; 29 | int c; 30 | bool should_remove_bom = false; 31 | bool should_convert_crlf = false; 32 | bool is_cr_retained = false; 33 | 34 | if (!(f = fopen(filename, "r"))) { 35 | fputs("cannot open ", stderr); /* filename is not a constant */ 36 | return fail(filename); 37 | } 38 | 39 | /* Test if we should remove the UTF-8 BOM */ 40 | { 41 | char *remove_bom = getenv("remove_bom"); 42 | if (remove_bom != NULL && !strcmp(remove_bom, "on")) { 43 | should_remove_bom = true; 44 | } 45 | } 46 | 47 | if (should_remove_bom) { 48 | #ifdef DUMMY_BOM_HANDLING 49 | fseek(f, 3, SEEK_SET); 50 | #else 51 | char bom_buf[3]; 52 | 53 | /* Reading an eventual BOM */ 54 | size_t read_bytes = fread(bom_buf, 3, 1, f); 55 | 56 | /* Checking BOM */ 57 | if (read_bytes != 3 || strncmp(bom_buf, MAGIC_BOM_UTF8, 3)) { 58 | /* Not a BOM, reverting to the beginning */ 59 | fseek(f, 0, SEEK_SET); 60 | } 61 | #endif 62 | } 63 | 64 | /* Test if we should convert the CRLF to LF */ 65 | { 66 | char *convert_crlf = getenv("convert_crlf"); 67 | if (convert_crlf != NULL && !strcmp(convert_crlf, "on")) { 68 | should_convert_crlf = true; 69 | } 70 | } 71 | 72 | while ((c = fgetc(f)) != EOF) { 73 | if (should_convert_crlf && c == '\r') { 74 | is_cr_retained = true; 75 | /* Directly get next char */ 76 | continue; 77 | } 78 | 79 | /* Not a "\r\n", emit the missing \r */ 80 | if (is_cr_retained && c != '\n') 81 | fputc('\r', stdout); 82 | /* is_cr_retained has been handled */ 83 | is_cr_retained = false; 84 | 85 | fputc(c, stdout); 86 | } 87 | 88 | fclose(f); 89 | 90 | /* If the last char was \r, we should still emit it */ 91 | if (is_cr_retained) 92 | fputc('\r', stdout); 93 | 94 | return 0; 95 | } 96 | 97 | static int set_filename(char *filename, const char *plugin_basename, 98 | const char *action) 99 | { 100 | 101 | if (getenv(action) == NULL) { 102 | /* Default */ 103 | return snprintf(filename, LINE_MAX, "%s/%s.%s", 104 | getenv("MUNIN_PLUGSTATE"), plugin_basename, 105 | action); 106 | } 107 | 108 | return snprintf(filename, LINE_MAX, "%s", getenv(action)); 109 | } 110 | 111 | int external_(int argc, char **argv) 112 | { 113 | char filename[LINE_MAX]; 114 | char *action = "fetch"; /* Default is "fetch" */ 115 | 116 | if (argc > 1) { 117 | if (!strcmp(argv[1], "autoconf")) 118 | return puts("no (not yet implemented)"); 119 | 120 | if (!strcmp(argv[1], "config")) { 121 | action = "config"; 122 | } 123 | } 124 | 125 | set_filename(filename, basename(argv[0]), action); 126 | read_file_to_stdout(filename); 127 | 128 | /* trigger on_read hook */ 129 | { 130 | char hookname[LINE_MAX]; 131 | char *on_read; 132 | 133 | snprintf(hookname, LINE_MAX, "on_%s", action); 134 | on_read = getenv(hookname); 135 | if (on_read == NULL || !strcmp(on_read, "nothing")) { 136 | /* nothing */ 137 | } else if (!strcmp(on_read, "unlink")) { 138 | return unlink(filename); 139 | } else if (!strcmp(on_read, "truncate")) { 140 | return truncate(filename, 0); 141 | } else { 142 | /* Do nothing if unknown */ 143 | } 144 | } 145 | 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /src/plugins/p/forks.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | #include "plugins.h" 16 | 17 | int forks(int argc, char **argv) 18 | { 19 | FILE *f; 20 | char buff[256]; 21 | if (argc > 1) { 22 | if (!strcmp(argv[1], "config")) { 23 | puts("graph_title Fork rate\n" 24 | "graph_args --base 1000 -l 0 \n" 25 | "graph_vlabel forks / ${graph_period}\n" 26 | "graph_category processes\n" 27 | "graph_info This graph shows the forking rate (new processes started).\n" 28 | "forks.label forks\n" 29 | "forks.type DERIVE\n" 30 | "forks.min 0\n" 31 | "forks.max 100000\n" 32 | "forks.info The number of forks per second."); 33 | print_warncrit("forks"); 34 | return 0; 35 | } 36 | if (!strcmp(argv[1], "autoconf")) 37 | return autoconf_check_readable(PROC_STAT); 38 | } 39 | if (!(f = fopen(PROC_STAT, "r"))) 40 | return fail("cannot open " PROC_STAT); 41 | while (fgets(buff, 256, f)) { 42 | if (!strncmp(buff, "processes ", 10)) { 43 | fclose(f); 44 | printf("forks.value %s", buff + 10); 45 | return 0; 46 | } 47 | } 48 | fclose(f); 49 | return fail("no processes line found in " PROC_STAT); 50 | } 51 | -------------------------------------------------------------------------------- /src/plugins/p/fw_packets.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "common.h" 13 | #include "plugins.h" 14 | 15 | #define PROC_NET_SNMP "/proc/net/snmp" 16 | 17 | int fw_packets(int argc, char **argv) 18 | { 19 | FILE *f; 20 | char buff[1024], *s; 21 | int ret; 22 | if (argc > 1) { 23 | if (!strcmp(argv[1], "config")) { 24 | puts("graph_title Firewall Throughput\n" 25 | "graph_args --base 1000 -l 0\n" 26 | "graph_vlabel Packets/${graph_period}\n" 27 | "graph_category network\n" 28 | "received.label Received\n" 29 | "received.draw AREA\n" 30 | "received.type DERIVE\n" 31 | "received.min 0\n" 32 | "forwarded.label Forwarded\n" 33 | "forwarded.draw LINE2\n" 34 | "forwarded.type DERIVE\n" "forwarded.min 0"); 35 | return 0; 36 | } 37 | if (!strcmp(argv[1], "autoconf")) 38 | return autoconf_check_readable(PROC_NET_SNMP); 39 | } 40 | if (!(f = fopen(PROC_NET_SNMP, "r"))) 41 | return fail("cannot open " PROC_NET_SNMP); 42 | while (fgets(buff, 1024, f)) { 43 | if (!strncmp(buff, "Ip: ", 4) && xisdigit(buff[4])) { 44 | if (!(s = strtok(buff + 4, " \t"))) 45 | break; 46 | if (!(s = strtok(NULL, " \t"))) 47 | break; 48 | if (!(s = strtok(NULL, " \t"))) 49 | break; 50 | printf("received.value %s\n", s); 51 | if (!(s = strtok(NULL, " \t"))) 52 | break; 53 | if (!(s = strtok(NULL, " \t"))) 54 | break; 55 | if (!(s = strtok(NULL, " \t"))) 56 | break; 57 | printf("forwarded.value %s\n", s); 58 | ret = 0; 59 | goto OK; 60 | } 61 | } 62 | ret = fail("no ip line found in " PROC_NET_SNMP); 63 | OK: 64 | fclose(f); 65 | return ret; 66 | } 67 | -------------------------------------------------------------------------------- /src/plugins/p/if_.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * Copyright (C) 2023 Kirill Ovchinnikov - All rights reserved. 4 | * 5 | * This copyrighted material is made available to anyone wishing to use, 6 | * modify, copy, or redistribute it subject to the terms and conditions 7 | * of the GNU General Public License v.2 or v.3. 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | 16 | #define SYS_CLASS_NET "/sys/class/net/" 17 | #define TMPBUFSIZE 256 18 | 19 | int if_(int argc, char **argv) 20 | { 21 | char *interface; 22 | FILE *f; 23 | char tmpbuf[TMPBUFSIZE]; 24 | 25 | interface = basename(argv[0]); 26 | if (strncmp(interface, "if_", 3) != 0) 27 | return fail("if_ invoked with invalid basename"); 28 | interface += 3; 29 | 30 | if (argc > 1) { 31 | if (!strcmp(argv[1], "autoconf")) { 32 | puts("yes"); 33 | return 0; 34 | } 35 | if (!strcmp(argv[1], "suggest")) { 36 | struct dirent *dent; 37 | DIR *ifdir; 38 | if (NULL == (ifdir = opendir(SYS_CLASS_NET))) 39 | return 1; 40 | while ((dent = readdir(ifdir)) != NULL) { 41 | if (strcmp(dent->d_name, ".") == 0 || 42 | strcmp(dent->d_name, "..") == 0) 43 | continue; 44 | if (strcmp(dent->d_name, "lo") == 0) 45 | continue; 46 | // skip docker and bridge interfaces by default 47 | // user can add them manually if needed 48 | if (strncmp(dent->d_name, "docker", 6) == 0 49 | || strncmp(dent->d_name, "br", 2) == 0) 50 | continue; 51 | puts(dent->d_name); 52 | } 53 | closedir(ifdir); 54 | return 0; 55 | } 56 | if (!strcmp(argv[1], "config")) { 57 | puts("graph_order down up"); 58 | printf("graph_title %s traffic\n", interface); 59 | puts("graph_args --base 1000\n" 60 | "graph_vlabel bits in (-) / out (+) per " 61 | "${graph_period}\n" "graph_category network"); 62 | printf("graph_info This graph shows the amount of " 63 | "traffic on the %s network interface.\n", 64 | interface); 65 | puts("down.label received\n" 66 | "down.type DERIVE\n" 67 | "down.graph no\n" 68 | "down.cdef down,8,*\n" 69 | "down.min 0\n" 70 | "up.label bps\n" 71 | "up.type DERIVE\n" 72 | "up.cdef up,8,*\n" 73 | "up.min 0\n" "up.negative down\n"); 74 | print_warncrit("up"); 75 | print_warncrit("down"); 76 | return 0; 77 | } 78 | } 79 | snprintf(tmpbuf, TMPBUFSIZE, "%s/%s/statistics/tx_bytes", 80 | SYS_CLASS_NET, interface); 81 | if (NULL == (f = fopen(tmpbuf, "r"))) 82 | return 1; 83 | if (NULL == fgets(tmpbuf, TMPBUFSIZE, f)) 84 | return 1; 85 | printf("up.value %s", tmpbuf); 86 | fclose(f); 87 | snprintf(tmpbuf, 255, "%s/%s/statistics/rx_bytes", SYS_CLASS_NET, 88 | interface); 89 | if (NULL == (f = fopen(tmpbuf, "r"))) 90 | return 1; 91 | if (NULL == fgets(tmpbuf, TMPBUFSIZE, f)) 92 | return 1; 93 | printf("down.value %s", tmpbuf); 94 | fclose(f); 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /src/plugins/p/if_err_.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "common.h" 14 | #include "plugins.h" 15 | 16 | #define PROC_NET_DEV "/proc/net/dev" 17 | 18 | int if_err_(int argc, char **argv) 19 | { 20 | char *interface; 21 | size_t interface_len; 22 | FILE *f; 23 | char buff[256], *s; 24 | int i; 25 | 26 | interface = basename(argv[0]); 27 | if (strncmp(interface, "if_err_", 7) != 0) 28 | return fail("if_err_ invoked with invalid basename"); 29 | interface += 7; 30 | interface_len = strlen(interface); 31 | 32 | if (argc > 1) { 33 | if (!strcmp(argv[1], "autoconf")) 34 | return autoconf_check_readable(PROC_NET_DEV); 35 | if (!strcmp(argv[1], "suggest")) { 36 | if (NULL == (f = fopen(PROC_NET_DEV, "r"))) 37 | return 1; 38 | while (fgets(buff, 256, f)) { 39 | for (s = buff; *s == ' '; ++s); 40 | i = 0; 41 | if (!strncmp(s, "lo:", 3)) 42 | continue; 43 | if (!strncmp(s, "sit", 3)) { 44 | for (i = 3; xisdigit(s[i]); ++i); 45 | if (s[i] == ':') 46 | continue; 47 | } 48 | while (s[i] != ':' && s[i] != '\0') 49 | ++i; 50 | if (s[i] != ':') 51 | continue; /* a header line */ 52 | s[i] = '\0'; 53 | puts(s); 54 | } 55 | fclose(f); 56 | return 0; 57 | } 58 | if (!strcmp(argv[1], "config")) { 59 | puts("graph_order rcvd trans"); 60 | printf("graph_title %s errors\n", interface); 61 | puts("graph_args --base 1000\n" 62 | "graph_vlabel packets in (-) / out (+) per " 63 | "${graph_period}\n" "graph_category network"); 64 | printf("graph_info This graph shows the amount of " 65 | "errors on the %s network interface.\n", 66 | interface); 67 | puts("rcvd.label packets\n" 68 | "rcvd.type COUNTER\n" 69 | "rcvd.graph no\n" 70 | "rcvd.warning 1\n" 71 | "trans.label packets\n" 72 | "trans.type COUNTER\n" 73 | "trans.negative rcvd\n" "trans.warning 1"); 74 | print_warncrit("rcvd"); 75 | print_warncrit("trans"); 76 | return 0; 77 | } 78 | } 79 | if (NULL == (f = fopen(PROC_NET_DEV, "r"))) 80 | return 1; 81 | while (fgets(buff, 256, f)) { 82 | for (s = buff; *s == ' '; ++s); 83 | if (0 != strncmp(s, interface, interface_len)) 84 | continue; 85 | s += interface_len; 86 | if (*s != ':') 87 | continue; 88 | ++s; 89 | 90 | while (*s == ' ') 91 | ++s; 92 | 93 | for (i = 1; i < 3; ++i) { 94 | while (xisdigit(*s)) 95 | ++s; 96 | while (xisspace(*s)) 97 | ++s; 98 | } 99 | for (i = 0; xisdigit(s[i]); ++i); 100 | printf("rcvd.value "); 101 | fwrite(s, 1, i, stdout); 102 | putchar('\n'); 103 | s += i; 104 | while (xisspace(*s)) 105 | ++s; 106 | 107 | for (i = 4; i < 11; ++i) { 108 | while (xisdigit(*s)) 109 | ++s; 110 | while (xisspace(*s)) 111 | ++s; 112 | } 113 | for (i = 0; xisdigit(s[i]); ++i); 114 | printf("trans.value "); 115 | fwrite(s, 1, i, stdout); 116 | putchar('\n'); 117 | } 118 | fclose(f); 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /src/plugins/p/interrupts.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | #include "plugins.h" 16 | 17 | int interrupts(int argc, char **argv) 18 | { 19 | FILE *f; 20 | char buff[256]; 21 | if (argc > 1) { 22 | if (!strcmp(argv[1], "config")) { 23 | puts("graph_title Interrupts and context switches\n" "graph_args --base 1000 -l 0\n" "graph_vlabel interrupts & ctx switches / ${graph_period}\n" "graph_category system\n" "graph_info This graph shows the number of interrupts and context switches on the system. These are typically high on a busy system.\n" "intr.info Interrupts are events that alter sequence of instructions executed by a processor. They can come from either hardware (exceptions, NMI, IRQ) or software."); 24 | puts("ctx.info A context switch occurs when a multitasking operatings system suspends the currently running process, and starts executing another.\n" "intr.label interrupts\n" "ctx.label context switches\n" "intr.type DERIVE\n" "ctx.type DERIVE\n" "intr.max 100000\n" "ctx.max 100000\n" "intr.min 0\n" "ctx.min 0"); 25 | print_warncrit("intr"); 26 | print_warncrit("ctx"); 27 | return 0; 28 | } 29 | if (!strcmp(argv[1], "autoconf")) 30 | return autoconf_check_readable(PROC_STAT); 31 | } 32 | if (!(f = fopen(PROC_STAT, "r"))) 33 | return fail("cannot open " PROC_STAT); 34 | while (fgets(buff, 256, f)) { 35 | if (!strncmp(buff, "intr ", 5)) { 36 | buff[5 + strcspn(buff + 5, " \t\n")] = '\0'; 37 | printf("intr.value %s\n", buff + 5); 38 | } else if (!strncmp(buff, "ctxt ", 5)) { 39 | buff[5 + strcspn(buff + 5, " \t\n")] = '\0'; 40 | printf("ctx.value %s\n", buff + 5); 41 | } 42 | } 43 | fclose(f); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/plugins/p/iostat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Michal Sojka - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "common.h" 16 | #include "plugins.h" 17 | 18 | #define PROC_DISKSTAT "/proc/diskstats" 19 | 20 | #define XSTR(x) #x 21 | #define STR(x) XSTR(x) 22 | #define NAME_SIZE 16 23 | 24 | struct dev { 25 | struct dev *next; 26 | uint8_t major; 27 | char key[10]; 28 | char name[NAME_SIZE + 1]; 29 | unsigned long rsect; 30 | unsigned long wsect; 31 | }; 32 | 33 | static bool is_numbered(struct dev *dev) 34 | { 35 | char *tail = dev->name + strlen(dev->name) - 1; 36 | if (strncmp(dev->name, "mmcblk", 6) == 0) { 37 | /* Skip mmcblkXpY, mmcblkXbootY, etc but not mmcblkX */ 38 | while (tail >= dev->name && *tail >= '0' && *tail <= '9') 39 | tail--; 40 | if (tail - dev->name > 6) 41 | return true; 42 | } else { 43 | if (tail >= dev->name && isdigit(*tail)) 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | int iostat(int argc, char **argv) 50 | { 51 | /* TODO: char *include_only = getenv("include_only"); */ 52 | bool include_numbered = getenv("SHOW_NUMBERED") != NULL; /* By default we want sda but not sda1 */ 53 | 54 | FILE *f; 55 | struct dev *devs = NULL, *devs_end = NULL; 56 | unsigned dev_cnt = 0; 57 | struct dev *dev; 58 | 59 | if (!(f = fopen(PROC_DISKSTAT, "r"))) 60 | return fail("cannot open " PROC_DISKSTAT); 61 | 62 | while (!feof(f)) { 63 | unsigned cnt = 0; 64 | struct dev *d; 65 | 66 | dev = alloca(sizeof(*dev)); 67 | dev->next = NULL; 68 | 69 | if (4 != fscanf(f, "%hhu %*u %" STR(NAME_SIZE) 70 | "s %*u %*u %lu %*u %*u %*u %lu%*[^\n]", 71 | &dev->major, dev->name, &dev->rsect, 72 | &dev->wsect)) 73 | continue; 74 | 75 | if (!include_numbered && is_numbered(dev)) 76 | continue; 77 | 78 | if (dev->rsect == 0 && dev->wsect == 0) 79 | continue; 80 | 81 | for (d = devs; d; d = d->next) 82 | if (dev->major == d->major) 83 | cnt++; 84 | snprintf(dev->key, sizeof(dev->key), "dev%d_%u", 85 | dev->major, cnt); 86 | 87 | dev_cnt++; 88 | if (!devs) { 89 | devs = devs_end = dev; 90 | } else { 91 | devs_end->next = dev; 92 | devs_end = dev; 93 | } 94 | } 95 | fclose(f); 96 | 97 | if (argc > 1) { 98 | if (!strcmp(argv[1], "config")) { 99 | puts("graph_title IOstat\n" 100 | "graph_args --base 1024\n" 101 | "graph_vlabel blocks per ${graph_period} read (-) / written (+)\n" 102 | "graph_category disk"); 103 | if (dev_cnt > 1) 104 | puts("graph_total Total"); 105 | puts("graph_info This graph shows the I/O to and from block devices."); 106 | printf("graph_order"); 107 | for (dev = devs; dev; dev = dev->next) 108 | printf(" %s_read %s_write ", dev->key, 109 | dev->key); 110 | printf("\n"); 111 | for (dev = devs; dev; dev = dev->next) { 112 | char graph_name[128]; 113 | 114 | printf("%s_read.label %s\n", dev->key, 115 | dev->name); 116 | printf("%s_read.type DERIVE\n", dev->key); 117 | printf("%s_read.min 0\n", dev->key); 118 | printf("%s_read.graph no\n", dev->key); 119 | printf("%s_write.label %s\n", dev->key, 120 | dev->name); 121 | printf("%s_write.info I/O on device %s\n", 122 | dev->key, dev->name); 123 | printf("%s_write.type DERIVE\n", dev->key); 124 | printf("%s_write.min 0\n", dev->key); 125 | printf("%s_write.negative %s_read\n", 126 | dev->key, dev->key); 127 | 128 | snprintf(graph_name, sizeof(graph_name), 129 | "%s_read", dev->key); 130 | print_warncrit(graph_name); 131 | 132 | snprintf(graph_name, sizeof(graph_name), 133 | "%s_write", dev->key); 134 | print_warncrit(graph_name); 135 | } 136 | 137 | return 0; 138 | } 139 | if (!strcmp(argv[1], "autoconf")) 140 | return writeyes(); 141 | } 142 | for (dev = devs; dev; dev = dev->next) { 143 | printf("%s_read.value %lu\n", dev->key, dev->rsect); 144 | printf("%s_write.value %lu\n", dev->key, dev->wsect); 145 | } 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /src/plugins/p/load.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | #include "plugins.h" 16 | 17 | #define PROC_LOADAVG "/proc/loadavg" 18 | 19 | int load(int argc, char **argv) 20 | { 21 | FILE *f; 22 | float val; 23 | if (argc > 1) { 24 | if (!strcmp(argv[1], "config")) { 25 | puts("graph_title Load average\n" 26 | "graph_args --base 1000 -l 0 -u 1\n" 27 | "graph_vlabel load\n" 28 | "graph_scale no\n" 29 | "graph_category system\n" "load.label load"); 30 | print_warncrit("load"); 31 | puts("graph_info The load average of the machine describes how many processes are in the run-queue (scheduled to run \"immediately\").\n" "load.info 5 minute load average"); 32 | return 0; 33 | } 34 | if (!strcmp(argv[1], "autoconf")) 35 | return writeyes(); 36 | } 37 | if (!(f = fopen(PROC_LOADAVG, "r"))) 38 | return fail("cannot open " PROC_LOADAVG); 39 | if (1 != fscanf(f, "%*f %f", &val)) { 40 | fclose(f); 41 | return fail("cannot read from " PROC_LOADAVG); 42 | } 43 | fclose(f); 44 | printf("load.value %.2f\n", val); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/plugins/p/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Steve Schnepp - All rights reserved. 3 | * Copyright (C) 2013 Helmut Grohne - All rights reserved. 4 | * 5 | * This copyrighted material is made available to anyone wishing to use, 6 | * modify, copy, or redistribute it subject to the terms and conditions 7 | * of the GNU General Public License v.2 or v.3. 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "common.h" 17 | #include "plugins.h" 18 | 19 | #define SYSWARNING 30 20 | #define SYSCRITICAL 50 21 | #define USRWARNING 80 22 | 23 | #define PROC_MEMINFO "/proc/meminfo" 24 | 25 | /* Samples "/proc/meminfo" 26 | 27 | Linux 2.6.32: 28 | MemTotal: 121484 kB 29 | MemFree: 16036 kB 30 | Buffers: 13260 kB 31 | Cached: 35432 kB 32 | SwapCached: 13600 kB 33 | Active: 43160 kB 34 | Inactive: 43920 kB 35 | Active(anon): 12616 kB 36 | Inactive(anon): 26096 kB 37 | Active(file): 30544 kB 38 | Inactive(file): 17824 kB 39 | Unevictable: 0 kB 40 | Mlocked: 0 kB 41 | SwapTotal: 262136 kB 42 | SwapFree: 215608 kB 43 | Dirty: 92 kB 44 | Writeback: 0 kB 45 | AnonPages: 29468 kB 46 | Mapped: 6728 kB 47 | Shmem: 308 kB 48 | Slab: 12024 kB 49 | SReclaimable: 6708 kB 50 | SUnreclaim: 5316 kB 51 | KernelStack: 680 kB 52 | PageTables: 2116 kB 53 | NFS_Unstable: 0 kB 54 | Bounce: 0 kB 55 | WritebackTmp: 0 kB 56 | CommitLimit: 322876 kB 57 | Committed_AS: 108564 kB 58 | VmallocTotal: 34359738367 kB 59 | VmallocUsed: 1196 kB 60 | VmallocChunk: 34359737024 kB 61 | HardwareCorrupted: 0 kB 62 | HugePages_Total: 0 63 | HugePages_Free: 0 64 | HugePages_Rsvd: 0 65 | HugePages_Surp: 0 66 | Hugepagesize: 2048 kB 67 | DirectMap4k: 131072 kB 68 | DirectMap2M: 0 kB 69 | 70 | 71 | Cygwin: 72 | MemTotal: 121484 kB 73 | MemFree: 16036 kB 74 | HighTotal: 0 kB 75 | HighFree: 0 kB 76 | LowFree: 16036 kB 77 | SwapTotal: 262136 kB 78 | SwapFree: 215608 kB 79 | } 80 | 81 | */ 82 | 83 | struct meminfo_pair { 84 | char *key; 85 | char *label; 86 | char *draw; 87 | char *info; 88 | int colour; 89 | int_fast64_t value; 90 | bool exists; 91 | }; 92 | 93 | struct meminfo_pair meminfo[] = { 94 | { 95 | .key = "Shmem", 96 | .label = "shmem", 97 | .draw = "STACK", 98 | .info = "Shared Memory (SYSV SHM segments, tmpfs).", 99 | .colour = 9, 100 | }, 101 | { 102 | .key = "Slab", 103 | .label = "slab_cache", 104 | .draw = "STACK", 105 | .info = 106 | "Memory used by the kernel (major users are caches like inode, " 107 | "dentry, etc).", 108 | .colour = 3, 109 | }, 110 | { 111 | .key = "SwapCached", 112 | .label = "swap_cache", 113 | .draw = "STACK", 114 | .info = 115 | "A piece of memory that keeps track of pages that have been " 116 | "fetched from swap but not yet been modified.", 117 | .colour = 2, 118 | }, 119 | { 120 | .key = "PageTables", 121 | .label = "page_tables", 122 | .draw = "STACK", 123 | .info = 124 | "Memory used to map between virtual and physical memory addresses.", 125 | .colour = 1, 126 | }, 127 | { 128 | .key = "VmallocUsed", 129 | .label = "vmalloc_used", 130 | .draw = "LINE2", 131 | .info = "'VMalloc' (kernel) memory used.", 132 | .colour = 8, 133 | }, 134 | { 135 | .key = "Committed_AS", 136 | .label = "committed", 137 | .draw = "LINE2", 138 | .info = 139 | "The amount of memory allocated to programs. Overcommitting is " 140 | "normal, but may indicate memory leaks.", 141 | .colour = 10, 142 | }, 143 | { 144 | .key = "Mapped", 145 | .label = "mapped", 146 | .draw = "LINE2", 147 | .info = "All mmap()ed pages.", 148 | .colour = 11, 149 | }, 150 | { 151 | .key = "Active", 152 | .label = "active", 153 | .draw = "LINE2", 154 | .info = 155 | "Memory recently used. Not reclaimed unless absolutely necessary.", 156 | .colour = 12, 157 | }, 158 | { 159 | .key = "ActiveAnon", 160 | .label = "active_anon", 161 | .draw = "LINE1", 162 | .colour = 13, 163 | }, 164 | { 165 | .key = "ActiveCache", 166 | .label = "active_cache", 167 | .draw = "LINE1", 168 | .colour = 14, 169 | }, 170 | { 171 | .key = "Inactive", 172 | .label = "inactive", 173 | .draw = "LINE2", 174 | .info = "Memory not currently used.", 175 | .colour = 15, 176 | }, 177 | { 178 | .key = "Inact_dirty", 179 | .label = "inactive_dirty", 180 | .draw = "LINE1", 181 | .info = 182 | "Memory not currently used, but in need of being written to disk.", 183 | .colour = 16, 184 | }, 185 | { 186 | .key = "Inact_laundry", 187 | .label = "inactive_laundry", 188 | .draw = "LINE1", 189 | .colour = 17, 190 | }, 191 | { 192 | .key = "Inact_clean", 193 | .label = "inactive_clean", 194 | .draw = "LINE1", 195 | .info = "Memory not currently used.", 196 | .colour = 18, 197 | }, 198 | { 199 | .key = "KSM", 200 | .label = "ksm_sharing", 201 | .draw = "LINE2", 202 | .info = "Memory saved by KSM sharing.", 203 | .colour = 19, 204 | }, 205 | // Fields that we do not report directly, but still care about parsing from 206 | // /proc/meminfo. 207 | {.key = "MemTotal" }, 208 | {.key = "MemFree" }, 209 | {.key = "SwapTotal" }, 210 | {.key = "SwapFree" }, 211 | {.key = "Buffers" }, 212 | {.key = "Cached" }, 213 | // Sentinel field. 214 | {.key = NULL } 215 | }; 216 | 217 | struct meminfo_pair *get_meminfo_key(char *key) 218 | { 219 | for (struct meminfo_pair * info = meminfo; info->key; info++) { 220 | if (!strcmp(info->key, key)) { 221 | return info; 222 | } 223 | } 224 | 225 | return NULL; 226 | } 227 | 228 | int_fast64_t get_meminfo_value(char *key) 229 | { 230 | struct meminfo_pair *info = get_meminfo_key(key); 231 | return info && info->exists ? info->value : -1; 232 | } 233 | 234 | void parse_meminfo(void) 235 | { 236 | FILE *f; 237 | char buff[256]; 238 | 239 | /* Asking for a fetch */ 240 | if (!(f = fopen(PROC_MEMINFO, "r"))) 241 | exit(fail("cannot open " PROC_MEMINFO)); 242 | 243 | while (fgets(buff, 256, f)) { 244 | char key[256]; 245 | char *colon; 246 | int_fast64_t value; 247 | if (!sscanf(buff, "%s %" SCNdFAST64, key, &value) || 248 | !(colon = strstr(key, ":"))) { 249 | fclose(f); 250 | exit(fail("cannot parse " PROC_MEMINFO " line")); 251 | } 252 | 253 | *colon = '\0'; 254 | 255 | struct meminfo_pair *info = get_meminfo_key(key); 256 | if (info) { 257 | info->exists = true; 258 | info->value = value * 1024; 259 | } 260 | } 261 | 262 | fclose(f); 263 | } 264 | 265 | int memory(int argc, char **argv) 266 | { 267 | parse_meminfo(); 268 | 269 | if (argc > 1) { 270 | if (!strcmp(argv[1], "config")) { 271 | printf("graph_args --base 1024 -l 0\n" 272 | "graph_vlabel Bytes\n" 273 | "graph_title Memory usage\n" 274 | "graph_category system\n" 275 | "graph_info This graph shows what the machine uses memory for.\n"); 276 | printf("apps.label apps\n"); 277 | printf("apps.draw AREA\n"); 278 | printf 279 | ("apps.info Memory used by user-space applications.\n"); 280 | 281 | printf("free.label free\n"); 282 | printf("free.draw STACK\n"); 283 | printf 284 | ("free.info Wasted memory. Memory that is not used for anything at all.\n"); 285 | 286 | printf("swap.label swap\n"); 287 | printf("swap.draw STACK\n"); 288 | printf("swap.info Swap space used.\n"); 289 | 290 | printf("buffers.label buffers\n"); 291 | printf("buffers.draw STACK\n"); 292 | printf 293 | ("buffers.info Block device (e.g. harddisk) cache. " 294 | "Also where \"dirty\" blocks are stored until written.\n"); 295 | printf("buffers.colour COLOUR5\n"); 296 | 297 | printf("cached.label cache\n"); 298 | printf("cached.draw STACK\n"); 299 | printf 300 | ("cached.info Parked file data (file content) cache.\n"); 301 | printf("cached.colour COLOUR4\n"); 302 | 303 | for (struct meminfo_pair * info = meminfo; 304 | info->key; info++) { 305 | if (!info->exists || !info->label) 306 | continue; 307 | 308 | printf("%s.label %s\n", info->label, 309 | info->label); 310 | printf("%s.draw %s\n", info->label, 311 | info->draw); 312 | if (info->info) 313 | printf("%s.info %s\n", info->label, 314 | info->info); 315 | printf("%s.colour COLOUR%d\n", info->label, 316 | info->colour); 317 | } 318 | 319 | return 0; 320 | } 321 | 322 | if (!strcmp(argv[1], "autoconf")) 323 | return autoconf_check_readable(PROC_MEMINFO); 324 | } 325 | 326 | printf("apps.value %" PRIdFAST64 "\n", 327 | get_meminfo_value("MemTotal") - 328 | get_meminfo_value("MemFree") - 329 | get_meminfo_value("Buffers") - 330 | get_meminfo_value("Cached") - 331 | get_meminfo_value("Slab") - 332 | get_meminfo_value("PageTables") - 333 | get_meminfo_value("SwapCached")); 334 | printf("free.value %" PRIdFAST64 "\n", 335 | get_meminfo_value("MemFree")); 336 | printf("buffers.value %" PRIdFAST64 "\n", 337 | get_meminfo_value("Buffers")); 338 | printf("cached.value %" PRIdFAST64 "\n", 339 | get_meminfo_value("Cached")); 340 | printf("swap.value %" PRIdFAST64 "\n", 341 | get_meminfo_value("SwapTotal") - 342 | get_meminfo_value("SwapFree")); 343 | 344 | for (struct meminfo_pair * info = meminfo; info->key; info++) { 345 | if (info->exists && info->label) 346 | printf("%s.value %" PRIdFAST64 "\n", info->label, 347 | info->value); 348 | } 349 | 350 | return 0; 351 | } 352 | -------------------------------------------------------------------------------- /src/plugins/p/open_files.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include "common.h" 12 | #include "plugins.h" 13 | 14 | #define FS_FILE_NR "/proc/sys/fs/file-nr" 15 | 16 | /* TODO: support env.warning and friends after the upstream plugin is fixed */ 17 | 18 | int open_files(int argc, char **argv) 19 | { 20 | FILE *f; 21 | unsigned long alloc, freeh, avail; 22 | if (argc > 1) { 23 | if (!strcmp(argv[1], "config")) { 24 | if (!(f = fopen(FS_FILE_NR, "r"))) 25 | return fail("cannot open " FS_FILE_NR); 26 | if (1 != fscanf(f, "%*d %*d %lu", &avail)) { 27 | fclose(f); 28 | return fail("cannot read from " 29 | FS_FILE_NR); 30 | } 31 | fclose(f); 32 | puts("graph_title File table usage\n" 33 | "graph_args --base 1000 -l 0\n" 34 | "graph_vlabel number of open files\n" 35 | "graph_category system\n" 36 | "graph_info This graph monitors the Linux open files table.\n" 37 | "used.label open files\n" 38 | "used.info The number of currently open files.\n" 39 | "max.label max open files\n" 40 | "max.info The maximum supported number of open " 41 | "files. Tune by modifying " FS_FILE_NR "."); 42 | printf("used.warning %lu\nused.critical %lu\n", 43 | (unsigned long) (avail * 0.92), 44 | (unsigned long) (avail * 0.98)); 45 | return 0; 46 | } 47 | if (!strcmp(argv[1], "autoconf")) 48 | return autoconf_check_readable(FS_FILE_NR); 49 | } 50 | if (!(f = fopen(FS_FILE_NR, "r"))) 51 | return fail("cannot open " FS_FILE_NR); 52 | if (3 != fscanf(f, "%lu %lu %lu", &alloc, &freeh, &avail)) { 53 | fclose(f); 54 | return fail("cannot read from " FS_FILE_NR); 55 | } 56 | fclose(f); 57 | printf("used.value %lu\nmax.value %lu\n", alloc - freeh, avail); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /src/plugins/p/open_inodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-13 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | #include "plugins.h" 16 | 17 | #define FS_INODE_NR "/proc/sys/fs/inode-nr" 18 | 19 | int open_inodes(int argc, char **argv) 20 | { 21 | FILE *f; 22 | int nr, freen; 23 | if (argc > 1) { 24 | if (!strcmp(argv[1], "config")) { 25 | puts("graph_title Inode table usage\n" 26 | "graph_args --base 1000 -l 0\n" 27 | "graph_vlabel number of open inodes\n" 28 | "graph_category system\n" 29 | "graph_info This graph monitors the Linux open inode table.\n" 30 | "used.label open inodes\n" 31 | "used.info The number of currently open inodes.\n" 32 | "max.label inode table size\n" 33 | "max.info The size of the system inode table. This is dynamically adjusted by the kernel."); 34 | print_warncrit("used"); 35 | print_warncrit("max"); 36 | return 0; 37 | } 38 | if (!strcmp(argv[1], "autoconf")) 39 | return autoconf_check_readable(FS_INODE_NR); 40 | } 41 | if (!(f = fopen(FS_INODE_NR, "r"))) 42 | return fail("cannot open " FS_INODE_NR); 43 | if (2 != fscanf(f, "%d %d", &nr, &freen)) { 44 | fclose(f); 45 | return fail("cannot read from " FS_INODE_NR); 46 | } 47 | fclose(f); 48 | printf("used.value %d\nmax.value %d\n", nr - freen, nr); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /src/plugins/p/processes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-13 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "common.h" 17 | #include "plugins.h" 18 | 19 | /* TODO: The upstream plugin does way more nowawdays. */ 20 | 21 | int processes(int argc, char **argv) 22 | { 23 | DIR *d; 24 | struct dirent *e; 25 | char *s; 26 | int n = 0; 27 | struct stat statbuf; 28 | 29 | if (argc > 1) { 30 | if (!strcmp(argv[1], "config")) { 31 | puts("graph_title Number of Processes\n" 32 | "graph_args --base 1000 -l 0 \n" 33 | "graph_vlabel number of processes\n" 34 | "graph_category processes\n" 35 | "graph_info This graph shows the number of processes in the system.\n" 36 | "processes.label processes\n" 37 | "processes.draw LINE2\n" 38 | "processes.info The current number of processes."); 39 | return 0; 40 | } 41 | if (!strcmp(argv[1], "autoconf")) { 42 | if (0 != stat("/proc/1", &statbuf)) { 43 | printf 44 | ("no (cannot stat /proc/1, errno=%d)\n", 45 | errno); 46 | return 1; 47 | } 48 | if (!S_ISDIR(statbuf.st_mode)) { 49 | printf("no (/proc/1 is not a directory\n"); 50 | return 1; 51 | } 52 | return writeyes(); 53 | } 54 | } 55 | if (!(d = opendir("/proc"))) 56 | return fail("cannot open /proc"); 57 | while ((e = readdir(d))) { 58 | for (s = e->d_name; *s; ++s) 59 | if (!xisdigit(*s)) 60 | break; 61 | if (!*s) 62 | ++n; 63 | } 64 | closedir(d); 65 | printf("processes.value %d\n", n); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/plugins/p/swap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-13 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "common.h" 16 | #include "plugins.h" 17 | 18 | #define PROC_VMSTAT "/proc/vmstat" 19 | 20 | int swap(int argc, char **argv) 21 | { 22 | FILE *f; 23 | char buff[256]; 24 | bool in, out; 25 | int inval, outval; 26 | if (argc > 1) { 27 | if (!strcmp(argv[1], "config")) { 28 | puts("graph_title Swap in/out\n" 29 | "graph_args -l 0 --base 1000\n" 30 | "graph_vlabel pages per ${graph_period} in (-) / out (+)\n" 31 | "graph_category system\n" 32 | "swap_in.label swap\n" 33 | "swap_in.type DERIVE\n" 34 | "swap_in.max 100000\n" 35 | "swap_in.min 0\n" 36 | "swap_in.graph no\n" 37 | "swap_out.label swap\n" 38 | "swap_out.type DERIVE\n" 39 | "swap_out.max 100000\n" 40 | "swap_out.min 0\n" 41 | "swap_out.negative swap_in"); 42 | print_warncrit("swap_in"); 43 | print_warncrit("swap_out"); 44 | return 0; 45 | } 46 | if (!strcmp(argv[1], "autoconf")) 47 | return autoconf_check_readable(PROC_STAT); 48 | } 49 | if ((f = fopen(PROC_VMSTAT, "r"))) { 50 | in = out = false; 51 | while (fgets(buff, 256, f)) { 52 | if (!in && !strncmp(buff, "pswpin ", 7)) { 53 | in = true; 54 | printf("swap_in.value %s", buff + 7); 55 | } else if (!out && !strncmp(buff, "pswpout ", 8)) { 56 | out = true; 57 | printf("swap_out.value %s", buff + 8); 58 | } 59 | } 60 | fclose(f); 61 | if (!(in && out)) 62 | return fail("no usable data on " PROC_VMSTAT); 63 | return 0; 64 | } else { 65 | if (!(f = fopen(PROC_STAT, "r"))) 66 | return fail("cannot open " PROC_STAT); 67 | while (fgets(buff, 256, f)) { 68 | if (!strncmp(buff, "swap ", 5)) { 69 | fclose(f); 70 | if (2 != 71 | sscanf(buff + 5, "%d %d", &inval, 72 | &outval)) 73 | return fail("bad data on " 74 | PROC_STAT); 75 | printf 76 | ("swap_in.value %d\nswap_out.value %d\n", 77 | inval, outval); 78 | return 0; 79 | } 80 | } 81 | fclose(f); 82 | return fail("no swap line found in " PROC_STAT); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/plugins/p/threads.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "common.h" 18 | #include "plugins.h" 19 | 20 | int threads(int argc, char **argv) 21 | { 22 | FILE *f; 23 | char buff[270]; 24 | const char *s; 25 | int i, sum; 26 | DIR *d; 27 | struct dirent *e; 28 | 29 | if (argc > 1) { 30 | if (!strcmp(argv[1], "autoconf")) { 31 | i = getpid(); 32 | snprintf(buff, sizeof(buff), "/proc/%d/status", i); 33 | if (NULL == (f = fopen(buff, "r"))) 34 | return 35 | fail("failed to open /proc/$$/status"); 36 | while (fgets(buff, 256, f)) 37 | if (!strncmp(buff, "Threads:", 8)) { 38 | fclose(f); 39 | return writeyes(); 40 | } 41 | fclose(f); 42 | puts("no"); 43 | return 0; 44 | } 45 | if (!strcmp(argv[1], "config")) { 46 | puts("graph_title Number of threads\n" 47 | "graph_vlabel number of threads\n" 48 | "graph_category processes\n" 49 | "graph_info This graph shows the number of threads.\n" 50 | "threads.label threads\n" 51 | "threads.info The current number of threads."); 52 | return 0; 53 | } 54 | } 55 | if (NULL == (d = opendir("/proc"))) 56 | return fail("cannot open /proc"); 57 | sum = 0; 58 | while ((e = readdir(d))) { 59 | for (s = e->d_name; *s; ++s) 60 | if (!xisdigit(*s)) 61 | break; 62 | if (*s) /* non-digit found */ 63 | continue; 64 | snprintf(buff, 270, "/proc/%s/status", e->d_name); 65 | if (!(f = fopen(buff, "r"))) 66 | continue; /* process has vanished */ 67 | while (fgets(buff, 256, f)) { 68 | if (strncmp(buff, "Threads:", 8)) 69 | continue; 70 | if (1 != sscanf(buff + 8, "%d", &i)) { 71 | fclose(f); 72 | closedir(d); 73 | return fail("failed to parse " 74 | "/proc/somepid/status"); 75 | } 76 | sum += i; 77 | } 78 | fclose(f); 79 | } 80 | closedir(d); 81 | printf("threads.value %d\n", sum); 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /src/plugins/p/uptime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | /* This plugin is compatible with munin-mainline version 2.0.17. */ 10 | 11 | #include 12 | #include 13 | #include "common.h" 14 | #include "plugins.h" 15 | 16 | #define PROC_UPTIME "/proc/uptime" 17 | 18 | int uptime(int argc, char **argv) 19 | { 20 | FILE *f; 21 | float uptime; 22 | if (argc > 1) { 23 | if (!strcmp(argv[1], "config")) { 24 | puts("graph_title Uptime\n" 25 | "graph_args --base 1000 -l 0 \n" 26 | "graph_vlabel uptime in days\n" 27 | "graph_category system\n" 28 | "uptime.label uptime\n" "uptime.draw AREA"); 29 | print_warncrit("uptime"); 30 | return 0; 31 | } 32 | if (!strcmp(argv[1], "autoconf")) 33 | return writeyes(); 34 | } 35 | if (!(f = fopen(PROC_UPTIME, "r"))) 36 | return fail("cannot open " PROC_UPTIME); 37 | if (1 != fscanf(f, "%f", &uptime)) { 38 | fclose(f); 39 | return fail("cannot read from " PROC_UPTIME); 40 | } 41 | fclose(f); 42 | printf("uptime.value %.2f\n", uptime / 86400); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/plugins/plugins.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 Helmut Grohne - All rights reserved. 3 | * 4 | * This copyrighted material is made available to anyone wishing to use, 5 | * modify, copy, or redistribute it subject to the terms and conditions 6 | * of the GNU General Public License v.2 or v.3. 7 | */ 8 | 9 | #ifndef PLUGINS_H 10 | #define PLUGINS_H 11 | 12 | int cpu(int argc, char **argv); 13 | int df(int argc, char **argv); 14 | int entropy(int argc, char **argv); 15 | int external_(int argc, char **argv); 16 | int forks(int argc, char **argv); 17 | int fw_packets(int argc, char **argv); 18 | int if_(int argc, char **argv); 19 | int if_err_(int argc, char **argv); 20 | int interrupts(int argc, char **argv); 21 | int iostat(int argc, char **argv); 22 | int load(int argc, char **argv); 23 | int memory(int argc, char **argv); 24 | int open_files(int argc, char **argv); 25 | int open_inodes(int argc, char **argv); 26 | int processes(int argc, char **argv); 27 | int swap(int argc, char **argv); 28 | int threads(int argc, char **argv); 29 | int uptime(int argc, char **argv); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /systemd/munin-node-c.socket: -------------------------------------------------------------------------------- 1 | [Socket] 2 | ListenStream=4949 3 | Accept=true 4 | 5 | [Install] 6 | WantedBy=sockets.target 7 | -------------------------------------------------------------------------------- /systemd/munin-node-c@.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | JoinsNamespaceOf=munin-node-daemon.service 3 | 4 | [Service] 5 | ExecStart=/usr/local/sbin/munin-node-c 6 | PrivateTmp=yes 7 | ProtectHome=yes 8 | StandardInput=socket 9 | StandardOutput=socket 10 | -------------------------------------------------------------------------------- /systemd/munin-node-daemon.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | 3 | [Service] 4 | ExecStart=/usr/local/sbin/munin-node-c -a 5 | 6 | PrivateTmp=yes 7 | PrivateNetwork=no 8 | ProtectHome=yes 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | -------------------------------------------------------------------------------- /t.conf/env.conf: -------------------------------------------------------------------------------- 1 | # Test conf file for env 2 | [env] 3 | env.foo aa 4 | env.bar bb 5 | 6 | [en*] 7 | env.foo aa1 8 | env.baz aa 9 | 10 | [*] 11 | env.foo aa10 12 | env.faz aa02 13 | -------------------------------------------------------------------------------- /t/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 Steve Schnepp - All rights reserved. 2 | # 3 | # This copyrighted material is made available to anyone wishing to use, 4 | # modify, copy, or redistribute it subject to the terms and conditions 5 | # of the GNU General Public License v.2 or v.3. 6 | # 7 | 8 | include $(top_srcdir)/common.am 9 | 10 | check_PROGRAMS = p/ok_plugin p/nb_env 11 | p_ok_plugin_SOURCES = p/ok_plugin.c common.c common.h 12 | p_nb_env_SOURCES = p/nb_env.c common.c common.h 13 | -------------------------------------------------------------------------------- /t/common.c: -------------------------------------------------------------------------------- 1 | /* Simmle plugin framework */ 2 | #include 3 | 4 | #include "common.h" 5 | 6 | int main(int argc, const char *argv[]) 7 | { 8 | int is_config = (argc == 2) && (strcmp(argv[1], "config") == 0); 9 | return is_config ? emit_config() : emit_fetch(); 10 | } 11 | -------------------------------------------------------------------------------- /t/common.h: -------------------------------------------------------------------------------- 1 | /* This is the forward API of all test plugins */ 2 | 3 | int emit_config(); 4 | int emit_fetch(); 5 | 6 | /* This is the common main function */ 7 | int main(int argc, const char *argv[]); 8 | -------------------------------------------------------------------------------- /t/node_list: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # lauching the list of testing 4 | echo list | src/node/munin-node-c -d t/p -D t.conf 5 | 6 | # 7 | echo config nb_env | src/node/munin-node-c -d t/p -D t.conf 8 | echo fetch nb_env | src/node/munin-node-c -d t/p -D t.conf 9 | -------------------------------------------------------------------------------- /t/p/nb_env.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "common.h" 5 | 6 | extern char **environ; 7 | 8 | int count_env_nb() 9 | { 10 | int env_nb = 0; 11 | char **cur_environ = environ; 12 | while (*cur_environ) { 13 | env_nb++; 14 | cur_environ++; 15 | } 16 | 17 | return env_nb; 18 | } 19 | 20 | int emit_config() 21 | { 22 | printf("graph_title " __FILE__ "\n"); 23 | printf("env_nb.label Number of env vars\n"); 24 | 25 | return 0; 26 | } 27 | 28 | int emit_fetch() 29 | { 30 | char **cur_environ = environ; 31 | 32 | printf("env_nb.value %d\n", count_env_nb()); 33 | printf("env_nb.ext_info "); 34 | 35 | while (*cur_environ) { 36 | printf("{%s},", *cur_environ); 37 | cur_environ++; 38 | } 39 | 40 | printf("\n"); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /t/p/ok_plugin.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "common.h" 4 | 5 | int emit_config() 6 | { 7 | printf("graph_title " __FILE__ "\n"); 8 | printf("first_f.label This is the first field\n"); 9 | printf("second_f.label This is the second field\n"); 10 | 11 | return 0; 12 | } 13 | 14 | int emit_fetch() 15 | { 16 | printf("first_f.value %f\n", 1234.567); 17 | printf("second_f.value %f\n", -2345.678); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /t/plugin_list: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | src/plugins/munin-plugins-c listplugins 4 | --------------------------------------------------------------------------------