Skip to content

Commit

Permalink
fix solaris device file support in check filesystem path
Browse files Browse the repository at this point in the history
git-svn-id: http://monit.googlecode.com/svn/trunk@313 808b68a2-07de-11de-a1f0-819f45317607
  • Loading branch information
mmonit@tildeslash.com committed Dec 18, 2010
1 parent 2b778b4 commit a0c1a61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Expand Up @@ -11,7 +11,7 @@ Version 5.2.4

BUGFIXES:

* FreeBSD, NetBSD, OpenBSD, MacOSX filesystem check fix:
* FreeBSD, NetBSD, OpenBSD, MacOSX, Solaris filesystem check fix:
If block/character device was used in the check path instead
of mountpoint, monit reported usage of wrong filesystem.

Expand Down
18 changes: 4 additions & 14 deletions device/device_common.c
Expand Up @@ -88,7 +88,6 @@
* @return NULL in the case of failure otherwise filesystem path
*/
char *device_path(Info_T inf, char *object) {

struct stat buf;

ASSERT(inf);
Expand All @@ -100,21 +99,15 @@ char *device_path(Info_T inf, char *object) {
}

if(S_ISREG(buf.st_mode) || S_ISDIR(buf.st_mode)) {

inf->mntpath[sizeof(inf->mntpath) - 1] = 0;
return strncpy(inf->mntpath, object, sizeof(inf->mntpath) - 1);

snprintf(inf->mntpath, sizeof(inf->mntpath), "%s", object);
return inf->mntpath;
} else if(S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) {

return device_mountpoint_sysdep(inf, object);

}

LogError("%s: Not file, directory or block special device: '%s'",
prog, object);
LogError("%s: Not file, directory or block special device: '%s'", prog, object);

return NULL;

}


Expand All @@ -128,18 +121,15 @@ char *device_path(Info_T inf, char *object) {
* @return TRUE if informations were succesfully read otherwise FALSE
*/
int filesystem_usage(Info_T inf, char *object) {

ASSERT(inf);
ASSERT(object);

if(!device_path(inf, object)) {
if(!device_path(inf, object))
return FALSE;
}

/* save the previous filesystem flags */
inf->_flags= inf->flags;

return filesystem_usage_sysdep(inf);

}

31 changes: 10 additions & 21 deletions device/sysdep_SOLARIS.c
Expand Up @@ -76,36 +76,28 @@
* @return NULL in the case of failure otherwise mountpoint
*/
char *device_mountpoint_sysdep(Info_T inf, char *blockdev) {

struct mnttab mnt;
FILE *mntfd;

ASSERT(inf);
ASSERT(blockdev);


if((mntfd= fopen("/etc/mnttab", "r")) == NULL) {
if ((mntfd= fopen("/etc/mnttab", "r")) == NULL) {
LogError("%s: Cannot open /etc/mnttab file\n", prog);
return NULL;
}

/* First match is significant */
while(getmntent(mntfd, &mnt) == 0) {

if(IS(blockdev, mnt.mnt_special)) {

fclose(mntfd);
inf->mntpath[sizeof(inf->mntpath) - 1] = 0;
return strncpy(inf->mntpath, mnt.mnt_mountp, sizeof(inf->mntpath) - 1);

while (getmntent(mntfd, &mnt) == 0) {
char real_mnt_special[PATH_MAX+1];
if (realpath(mnt.mnt_special, real_mnt_special) && IS(real_mnt_special, blockdev)) {
fclose(mntfd);
snprintf(inf->mntpath, sizeof(inf->mntpath), "%s", mnt.mnt_mountp);
return inf->mntpath;
}

}

fclose(mntfd);

return NULL;

}


Expand All @@ -114,17 +106,15 @@ char *device_mountpoint_sysdep(Info_T inf, char *blockdev) {
* given information structure.
*
* @param inf Information structure where resulting data will be stored
* @return TRUE if informations were succesfully read otherwise FALSE
* @return TRUE if informations were succesfully read otherwise FALSE
*/
int filesystem_usage_sysdep(Info_T inf) {

struct statvfs usage;

ASSERT(inf);

if(statvfs(inf->mntpath, &usage) != 0) {
LogError("%s: Error getting usage statistics for filesystem '%s' -- %s\n",
prog, inf->mntpath, STRERROR);
if (statvfs(inf->mntpath, &usage) != 0) {
LogError("%s: Error getting usage statistics for filesystem '%s' -- %s\n", prog, inf->mntpath, STRERROR);
return FALSE;
}

Expand All @@ -137,6 +127,5 @@ int filesystem_usage_sysdep(Info_T inf) {
inf->flags= usage.f_flag;

return TRUE;

}

0 comments on commit a0c1a61

Please sign in to comment.