diff options
-rw-r--r-- | lib/mountlist.c | 92 | ||||
-rw-r--r-- | plugins/check_disk.c | 31 |
2 files changed, 68 insertions, 55 deletions
diff --git a/lib/mountlist.c b/lib/mountlist.c index b667c44..d171858 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c | |||
@@ -35,9 +35,9 @@ void free (); | |||
35 | #ifndef strstr | 35 | #ifndef strstr |
36 | char *strstr (); | 36 | char *strstr (); |
37 | #endif | 37 | #endif |
38 | char *xmalloc (); | 38 | /* char *xmalloc (); */ |
39 | char *xrealloc (); | 39 | /* char *realloc (); */ |
40 | char *xstrdup (); | 40 | /* char *xstrdup (); */ |
41 | 41 | ||
42 | #include <errno.h> | 42 | #include <errno.h> |
43 | #ifndef errno | 43 | #ifndef errno |
@@ -307,10 +307,10 @@ read_filesystem_list (int need_fs_type) | |||
307 | return NULL; | 307 | return NULL; |
308 | for (p = mntlist; p; p = p->next) { | 308 | for (p = mntlist; p; p = p->next) { |
309 | mnt = p->ment; | 309 | mnt = p->ment; |
310 | me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry)); | 310 | me = (struct mount_entry*) malloc(sizeof (struct mount_entry)); |
311 | me->me_devname = xstrdup(mnt->mnt_fsname); | 311 | me->me_devname = strdup(mnt->mnt_fsname); |
312 | me->me_mountdir = xstrdup(mnt->mnt_dir); | 312 | me->me_mountdir = strdup(mnt->mnt_dir); |
313 | me->me_type = xstrdup(mnt->mnt_type); | 313 | me->me_type = strdup(mnt->mnt_type); |
314 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 314 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
315 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 315 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
316 | me->me_dev = -1; | 316 | me->me_dev = -1; |
@@ -334,10 +334,10 @@ read_filesystem_list (int need_fs_type) | |||
334 | 334 | ||
335 | while ((mnt = getmntent (fp))) | 335 | while ((mnt = getmntent (fp))) |
336 | { | 336 | { |
337 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 337 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
338 | me->me_devname = xstrdup (mnt->mnt_fsname); | 338 | me->me_devname = strdup (mnt->mnt_fsname); |
339 | me->me_mountdir = xstrdup (mnt->mnt_dir); | 339 | me->me_mountdir = strdup (mnt->mnt_dir); |
340 | me->me_type = xstrdup (mnt->mnt_type); | 340 | me->me_type = strdup (mnt->mnt_type); |
341 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 341 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
342 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 342 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
343 | devopt = strstr (mnt->mnt_opts, "dev="); | 343 | devopt = strstr (mnt->mnt_opts, "dev="); |
@@ -373,9 +373,9 @@ read_filesystem_list (int need_fs_type) | |||
373 | { | 373 | { |
374 | char *fs_type = fsp_to_string (fsp); | 374 | char *fs_type = fsp_to_string (fsp); |
375 | 375 | ||
376 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 376 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
377 | me->me_devname = xstrdup (fsp->f_mntfromname); | 377 | me->me_devname = strdup (fsp->f_mntfromname); |
378 | me->me_mountdir = xstrdup (fsp->f_mntonname); | 378 | me->me_mountdir = strdup (fsp->f_mntonname); |
379 | me->me_type = fs_type; | 379 | me->me_type = fs_type; |
380 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 380 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
381 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 381 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
@@ -398,9 +398,9 @@ read_filesystem_list (int need_fs_type) | |||
398 | 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, | 398 | 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, |
399 | (char *) 0))) | 399 | (char *) 0))) |
400 | { | 400 | { |
401 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 401 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
402 | me->me_devname = xstrdup (fsd.fd_req.devname); | 402 | me->me_devname = strdup (fsd.fd_req.devname); |
403 | me->me_mountdir = xstrdup (fsd.fd_req.path); | 403 | me->me_mountdir = strdup (fsd.fd_req.path); |
404 | me->me_type = gt_names[fsd.fd_req.fstype]; | 404 | me->me_type = gt_names[fsd.fd_req.fstype]; |
405 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 405 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
406 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 406 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
@@ -458,10 +458,10 @@ read_filesystem_list (int need_fs_type) | |||
458 | continue; | 458 | continue; |
459 | 459 | ||
460 | if (strcmp (d->d_name, ".") == 0) | 460 | if (strcmp (d->d_name, ".") == 0) |
461 | name = xstrdup ("/"); | 461 | name = strdup ("/"); |
462 | else | 462 | else |
463 | { | 463 | { |
464 | name = xmalloc (1 + strlen (d->d_name) + 1); | 464 | name = malloc (1 + strlen (d->d_name) + 1); |
465 | name[0] = '/'; | 465 | name[0] = '/'; |
466 | strcpy (name + 1, d->d_name); | 466 | strcpy (name + 1, d->d_name); |
467 | } | 467 | } |
@@ -470,7 +470,7 @@ read_filesystem_list (int need_fs_type) | |||
470 | { | 470 | { |
471 | struct rootdir_entry *re; | 471 | struct rootdir_entry *re; |
472 | 472 | ||
473 | re = (struct rootdir_entry *) xmalloc (sizeof (struct rootdir_entry)); | 473 | re = (struct rootdir_entry *) malloc (sizeof (struct rootdir_entry)); |
474 | re->name = name; | 474 | re->name = name; |
475 | re->dev = statbuf.st_dev; | 475 | re->dev = statbuf.st_dev; |
476 | re->ino = statbuf.st_ino; | 476 | re->ino = statbuf.st_ino; |
@@ -496,10 +496,10 @@ read_filesystem_list (int need_fs_type) | |||
496 | if (re->dev == fi.dev && re->ino == fi.root) | 496 | if (re->dev == fi.dev && re->ino == fi.root) |
497 | break; | 497 | break; |
498 | 498 | ||
499 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 499 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
500 | me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); | 500 | me->me_devname = strdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); |
501 | me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); | 501 | me->me_mountdir = strdup (re != NULL ? re->name : fi.fsh_name); |
502 | me->me_type = xstrdup (fi.fsh_name); | 502 | me->me_type = strdup (fi.fsh_name); |
503 | me->me_dev = fi.dev; | 503 | me->me_dev = fi.dev; |
504 | me->me_dummy = 0; | 504 | me->me_dummy = 0; |
505 | me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; | 505 | me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; |
@@ -530,7 +530,7 @@ read_filesystem_list (int need_fs_type) | |||
530 | return (NULL); | 530 | return (NULL); |
531 | 531 | ||
532 | bufsize = (1 + numsys) * sizeof (struct statfs); | 532 | bufsize = (1 + numsys) * sizeof (struct statfs); |
533 | stats = (struct statfs *)xmalloc (bufsize); | 533 | stats = (struct statfs *)malloc (bufsize); |
534 | numsys = getfsstat (stats, bufsize, MNT_WAIT); | 534 | numsys = getfsstat (stats, bufsize, MNT_WAIT); |
535 | 535 | ||
536 | if (numsys < 0) | 536 | if (numsys < 0) |
@@ -541,9 +541,9 @@ read_filesystem_list (int need_fs_type) | |||
541 | 541 | ||
542 | for (counter = 0; counter < numsys; counter++) | 542 | for (counter = 0; counter < numsys; counter++) |
543 | { | 543 | { |
544 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 544 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
545 | me->me_devname = xstrdup (stats[counter].f_mntfromname); | 545 | me->me_devname = strdup (stats[counter].f_mntfromname); |
546 | me->me_mountdir = xstrdup (stats[counter].f_mntonname); | 546 | me->me_mountdir = strdup (stats[counter].f_mntonname); |
547 | me->me_type = mnt_names[stats[counter].f_type]; | 547 | me->me_type = mnt_names[stats[counter].f_type]; |
548 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 548 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
549 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 549 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
@@ -570,15 +570,15 @@ read_filesystem_list (int need_fs_type) | |||
570 | 570 | ||
571 | while (fread (&mnt, sizeof mnt, 1, fp) > 0) | 571 | while (fread (&mnt, sizeof mnt, 1, fp) > 0) |
572 | { | 572 | { |
573 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 573 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
574 | # ifdef GETFSTYP /* SVR3. */ | 574 | # ifdef GETFSTYP /* SVR3. */ |
575 | me->me_devname = xstrdup (mnt.mt_dev); | 575 | me->me_devname = strdup (mnt.mt_dev); |
576 | # else | 576 | # else |
577 | me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6); | 577 | me->me_devname = malloc (strlen (mnt.mt_dev) + 6); |
578 | strcpy (me->me_devname, "/dev/"); | 578 | strcpy (me->me_devname, "/dev/"); |
579 | strcpy (me->me_devname + 5, mnt.mt_dev); | 579 | strcpy (me->me_devname + 5, mnt.mt_dev); |
580 | # endif | 580 | # endif |
581 | me->me_mountdir = xstrdup (mnt.mt_filsys); | 581 | me->me_mountdir = strdup (mnt.mt_filsys); |
582 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 582 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
583 | me->me_type = ""; | 583 | me->me_type = ""; |
584 | # ifdef GETFSTYP /* SVR3. */ | 584 | # ifdef GETFSTYP /* SVR3. */ |
@@ -589,7 +589,7 @@ read_filesystem_list (int need_fs_type) | |||
589 | 589 | ||
590 | if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 | 590 | if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 |
591 | && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) | 591 | && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) |
592 | me->me_type = xstrdup (typebuf); | 592 | me->me_type = strdup (typebuf); |
593 | } | 593 | } |
594 | # endif | 594 | # endif |
595 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 595 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
@@ -618,10 +618,10 @@ read_filesystem_list (int need_fs_type) | |||
618 | struct mntent **mnttbl=getmnttbl(),**ent; | 618 | struct mntent **mnttbl=getmnttbl(),**ent; |
619 | for (ent=mnttbl;*ent;ent++) | 619 | for (ent=mnttbl;*ent;ent++) |
620 | { | 620 | { |
621 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 621 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
622 | me->me_devname = xstrdup ( (*ent)->mt_resource); | 622 | me->me_devname = strdup ( (*ent)->mt_resource); |
623 | me->me_mountdir = xstrdup( (*ent)->mt_directory); | 623 | me->me_mountdir = strdup( (*ent)->mt_directory); |
624 | me->me_type = xstrdup ((*ent)->mt_fstype); | 624 | me->me_type = strdup ((*ent)->mt_fstype); |
625 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 625 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
626 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 626 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
627 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 627 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
@@ -679,10 +679,10 @@ read_filesystem_list (int need_fs_type) | |||
679 | { | 679 | { |
680 | while ((ret = getmntent (fp, &mnt)) == 0) | 680 | while ((ret = getmntent (fp, &mnt)) == 0) |
681 | { | 681 | { |
682 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 682 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); |
683 | me->me_devname = xstrdup (mnt.mnt_special); | 683 | me->me_devname = strdup (mnt.mnt_special); |
684 | me->me_mountdir = xstrdup (mnt.mnt_mountp); | 684 | me->me_mountdir = strdup (mnt.mnt_mountp); |
685 | me->me_type = xstrdup (mnt.mnt_fstype); | 685 | me->me_type = strdup (mnt.mnt_fstype); |
686 | me->me_dummy = MNT_IGNORE (&mnt) != 0; | 686 | me->me_dummy = MNT_IGNORE (&mnt) != 0; |
687 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 687 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
688 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 688 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
@@ -714,7 +714,7 @@ read_filesystem_list (int need_fs_type) | |||
714 | 714 | ||
715 | /* Ask how many bytes to allocate for the mounted filesystem info. */ | 715 | /* Ask how many bytes to allocate for the mounted filesystem info. */ |
716 | mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize); | 716 | mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize); |
717 | entries = xmalloc (bufsize); | 717 | entries = malloc (bufsize); |
718 | 718 | ||
719 | /* Get the list of mounted filesystems. */ | 719 | /* Get the list of mounted filesystems. */ |
720 | mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); | 720 | mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); |
@@ -734,7 +734,7 @@ read_filesystem_list (int need_fs_type) | |||
734 | /* Prepend the remote pathname. */ | 734 | /* Prepend the remote pathname. */ |
735 | host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; | 735 | host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; |
736 | path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; | 736 | path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; |
737 | me->me_devname = xmalloc (strlen (host) + strlen (path) + 2); | 737 | me->me_devname = malloc (strlen (host) + strlen (path) + 2); |
738 | strcpy (me->me_devname, host); | 738 | strcpy (me->me_devname, host); |
739 | strcat (me->me_devname, ":"); | 739 | strcat (me->me_devname, ":"); |
740 | strcat (me->me_devname, path); | 740 | strcat (me->me_devname, path); |
@@ -742,11 +742,11 @@ read_filesystem_list (int need_fs_type) | |||
742 | else | 742 | else |
743 | { | 743 | { |
744 | me->me_remote = 0; | 744 | me->me_remote = 0; |
745 | me->me_devname = xstrdup (thisent + | 745 | me->me_devname = strdup (thisent + |
746 | vmp->vmt_data[VMT_OBJECT].vmt_off); | 746 | vmp->vmt_data[VMT_OBJECT].vmt_off); |
747 | } | 747 | } |
748 | me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); | 748 | me->me_mountdir = strdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); |
749 | me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); | 749 | me->me_type = strdup (fstype_to_string (vmp->vmt_gfstype)); |
750 | options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; | 750 | options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; |
751 | ignore = strstr (options, "ignore"); | 751 | ignore = strstr (options, "ignore"); |
752 | me->me_dummy = (ignore | 752 | me->me_dummy = (ignore |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 2558f6d..f9a9a84 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -63,6 +63,7 @@ const char *options = "\ | |||
63 | #include "utils.h" | 63 | #include "utils.h" |
64 | #include <stdarg.h> | 64 | #include <stdarg.h> |
65 | #include "../lib/fsusage.h" | 65 | #include "../lib/fsusage.h" |
66 | #include "../lib/mountlist.h" | ||
66 | 67 | ||
67 | /* If nonzero, show inode information. */ | 68 | /* If nonzero, show inode information. */ |
68 | static int inode_format; | 69 | static int inode_format; |
@@ -146,6 +147,8 @@ int verbose = 0; | |||
146 | int erronly = FALSE; | 147 | int erronly = FALSE; |
147 | int display_mntp = FALSE; | 148 | int display_mntp = FALSE; |
148 | 149 | ||
150 | /* Linked list of mounted filesystems. */ | ||
151 | static struct mount_entry *mount_list; | ||
149 | 152 | ||
150 | int | 153 | int |
151 | main (int argc, char **argv) | 154 | main (int argc, char **argv) |
@@ -162,22 +165,32 @@ main (int argc, char **argv) | |||
162 | char mntp[MAX_INPUT_BUFFER]; | 165 | char mntp[MAX_INPUT_BUFFER]; |
163 | char *output = ""; | 166 | char *output = ""; |
164 | 167 | ||
168 | struct mount_entry *me; | ||
165 | struct fs_usage fsp; | 169 | struct fs_usage fsp; |
166 | char *disk; | 170 | char *disk; |
167 | 171 | ||
168 | if (process_arguments (argc, argv) != OK) | 172 | if (process_arguments (argc, argv) != OK) |
169 | usage ("Could not parse arguments\n"); | 173 | usage ("Could not parse arguments\n"); |
170 | 174 | ||
171 | get_fs_usage (path, disk, &fsp); | 175 | mount_list = read_filesystem_list (0); |
176 | |||
177 | for (me = mount_list; me; me = me->me_next) { | ||
178 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | ||
179 | if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { | ||
180 | usp = (fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; | ||
181 | disk_result = check_disk (usp, fsp.fsu_bavail); | ||
182 | result = max_state (disk_result, result); | ||
183 | asprintf (&output, "%s %llu of %llu kB (%2.0f%%) free (%d-byte blocks) on %s (%s) %d\n", | ||
184 | output, | ||
185 | fsp.fsu_bavail*fsp.fsu_blocksize/1024, | ||
186 | fsp.fsu_blocks*fsp.fsu_blocksize/1024, | ||
187 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, | ||
188 | fsp.fsu_blocksize, | ||
189 | me->me_mountdir, | ||
190 | me->me_type, usp); | ||
191 | } | ||
192 | } | ||
172 | 193 | ||
173 | usp = (fsp.fsu_blocks - fsp.fsu_bavail) / fsp.fsu_blocks; | ||
174 | disk_result = check_disk (usp, fsp.fsu_bavail); | ||
175 | result = disk_result; | ||
176 | asprintf (&output, "%llu of %llu kB (%2.0f%%) free (%d-byte blocks)", | ||
177 | fsp.fsu_bavail*fsp.fsu_blocksize/1024, | ||
178 | fsp.fsu_blocks*fsp.fsu_blocksize/1024, | ||
179 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, | ||
180 | fsp.fsu_blocksize); | ||
181 | 194 | ||
182 | terminate (result, "DISK %s %s\n", state_text (result), output); | 195 | terminate (result, "DISK %s %s\n", state_text (result), output); |
183 | } | 196 | } |