-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(check_ifmount): add the cmdline switch -l|--list
to list the mounted filesystems. same output as the 'mount' command executed without options). Signed-off-by: Davide Madrisan <[email protected]>
- Loading branch information
Showing
1 changed file
with
24 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
/* | ||
* License: GPLv3+ | ||
* Copyright (c) 2013 Davide Madrisan <[email protected]> | ||
* Copyright (c) 2013,2014,2024 Davide Madrisan <[email protected]> | ||
* | ||
* A Nagios plugin to check for readonly filesystems. | ||
* | ||
|
@@ -32,14 +32,16 @@ | |
#include "mountlist.h" | ||
#include "progname.h" | ||
#include "progversion.h" | ||
#include "system.h" | ||
|
||
static const char *program_copyright = | ||
"Copyright (C) 2013-2014 Davide Madrisan <" PACKAGE_BUGREPORT ">\n"; | ||
"Copyright (C) 2013,2014,2024 Davide Madrisan <" PACKAGE_BUGREPORT ">\n"; | ||
|
||
/* Linked list of mounted file systems. */ | ||
static struct mount_entry *mount_list; | ||
|
||
static struct option const longopts[] = { | ||
{(char *) "list", no_argument, NULL, 'l'}, | ||
{(char *) "help", no_argument, NULL, GETOPT_HELP_CHAR}, | ||
{(char *) "version", no_argument, NULL, GETOPT_VERSION_CHAR}, | ||
{NULL, 0, NULL, 0} | ||
|
@@ -55,6 +57,7 @@ usage (FILE * out) | |
fputs (USAGE_HEADER, out); | ||
fprintf (out, " %s [FILESYSTEM]...\n", program_name); | ||
fputs (USAGE_OPTIONS, out); | ||
fputs (" -l, --list list the mounted filesystems and exit\n", out); | ||
fputs (USAGE_HELP, out); | ||
fputs (USAGE_VERSION, out); | ||
fputs (USAGE_EXAMPLES, out); | ||
|
@@ -89,25 +92,29 @@ int | |
main (int argc, char **argv) | ||
{ | ||
int c, i; | ||
bool just_list_fs = false; | ||
nagstatus status = STATE_OK; | ||
|
||
set_program_name (argv[0]); | ||
|
||
while ((c = getopt_long (argc, argv, GETOPT_HELP_VERSION_STRING, longopts, | ||
while ((c = getopt_long (argc, argv, "l" GETOPT_HELP_VERSION_STRING, longopts, | ||
NULL)) != -1) | ||
{ | ||
switch (c) | ||
{ | ||
default: | ||
usage (stderr); | ||
case 'l': | ||
just_list_fs = true; | ||
break; | ||
|
||
case_GETOPT_HELP_CHAR | ||
case_GETOPT_VERSION_CHAR | ||
|
||
} | ||
} | ||
|
||
if (argc <= optind) | ||
if (argc <= optind && (false == just_list_fs)) | ||
usage (stderr); | ||
|
||
mount_list = read_file_system_list (false); | ||
|
@@ -117,6 +124,19 @@ main (int argc, char **argv) | |
plugin_error (STATE_UNKNOWN, 0, | ||
"cannot read table of mounted file systems"); | ||
|
||
if (just_list_fs) { | ||
struct mount_entry *me; | ||
printf ("--- List of mounted filesystems ---\n"); | ||
for (me = mount_list; me; me = me->me_next) | ||
printf ("%s on %s type %s (%s)\n" | ||
, me->me_devname | ||
, me->me_mountdir | ||
, me->me_type | ||
, me->me_opts); | ||
|
||
return STATE_UNKNOWN; | ||
} | ||
|
||
for (i = optind; i < argc; ++i) | ||
if (STATE_CRITICAL == check_entry (argv[i])) | ||
status = STATE_CRITICAL; | ||
|