[BACK]Return to IMonIrix.c++ CVS log [TXT][DIR] Up to [Development] / fam / fam

Annotation of fam/fam/IMonIrix.c++, Revision 1.1

1.1     ! trev        1: //  Copyright (C) 1999 Silicon Graphics, Inc.  All Rights Reserved.
        !             2: //
        !             3: //  This program is free software; you can redistribute it and/or modify it
        !             4: //  under the terms of version 2 of the GNU General Public License as
        !             5: //  published by the Free Software Foundation.
        !             6: //
        !             7: //  This program is distributed in the hope that it would be useful, but
        !             8: //  WITHOUT ANY WARRANTY; without even the implied warranty of
        !             9: //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Further, any
        !            10: //  license provided herein, whether implied or otherwise, is limited to
        !            11: //  this program in accordance with the express provisions of the GNU
        !            12: //  General Public License.  Patent licenses, if any, provided herein do not
        !            13: //  apply to combinations of this program with other product or programs, or
        !            14: //  any other product whatsoever.  This program is distributed without any
        !            15: //  warranty that the program is delivered free of the rightful claim of any
        !            16: //  third person by way of infringement or the like.  See the GNU General
        !            17: //  Public License for more details.
        !            18: //
        !            19: //  You should have received a copy of the GNU General Public License along
        !            20: //  with this program; if not, write the Free Software Foundation, Inc., 59
        !            21: //  Temple Place - Suite 330, Boston MA 02111-1307, USA.
        !            22:
        !            23: #include <sys/types.h>
        !            24: #include <sys/stat.h>
        !            25: #include <sys/imon.h>
        !            26: #include <sys/sysmacros.h>
        !            27:
        !            28: #include <fcntl.h>
        !            29: #include <stropts.h>
        !            30: #include <unistd.h>
        !            31: #include <stdlib.h>
        !            32: #include <errno.h>
        !            33:
        !            34: #include "Log.h"
        !            35: #include "IMon.h"
        !            36:
        !            37: const intmask_t INTEREST_MASK = (IMON_CONTENT | IMON_ATTRIBUTE | IMON_DELETE |
        !            38: 				 IMON_EXEC | IMON_EXIT | IMON_RENAME);
        !            39:
        !            40: int IMon::imon_open()
        !            41: {
        !            42:     int imon = open("/dev/imon", O_RDONLY, 0);
        !            43:     if (imon == -1) {
        !            44: 	Log::critical("can't open /dev/imon: %m");
        !            45:     }
        !            46:     return imon;
        !            47: }
        !            48:
        !            49: IMon::Status IMon::imon_express(const char *name, struct stat *status)
        !            50: {
        !            51:     interest_t interest = { (char *) name, status, INTEREST_MASK };
        !            52:     int rc = ioctl(imonfd, IMONIOC_EXPRESS, &interest);
        !            53:     if (rc < 0)
        !            54:     {
        !            55:         if (name[0] == '/') {
        !            56:             Log::info("IMONIOC_EXPRESS on \"%s\" failed (euid: %i): %m",
        !            57:                       name, geteuid());
        !            58:         } else {
        !            59:             char * cwd = getcwd(0, 256);
        !            60:             Log::info("IMONIOC_EXPRESS on \"%s\" with cwd \"%s\" failed (euid: %i): %m",
        !            61:                       name,cwd,geteuid());
        !            62:             free(cwd);
        !            63:         }
        !            64: 	return BAD;
        !            65:     }
        !            66:     else
        !            67:     {
        !            68: 	if (status != NULL) {
        !            69: 	    Log::debug("told imon to monitor \"%s\" = dev %d/%d, ino %d", name,
        !            70: 		       major(status->st_dev), minor(status->st_dev),
        !            71: 		       status->st_ino);
        !            72:         } else {
        !            73: 	    Log::debug("told imon to monitor \"%s\" (but I didn't ask for dev/ino)",
        !            74:                        name);
        !            75:         }
        !            76: 	return OK;
        !            77:     }
        !            78: }
        !            79:
        !            80: IMon::Status IMon::imon_revoke(const char *name, dev_t dev, ino_t ino)
        !            81: {
        !            82:     static bool can_revokdi = true;
        !            83:     bool revokdi_failed;
        !            84:
        !            85: #ifdef HAVE_IMON_REVOKDI
        !            86:     if (can_revokdi)
        !            87:     {
        !            88: 	struct revokdi revokdi = { dev, ino, INTEREST_MASK };
        !            89: 	int rc = ioctl(imonfd, IMONIOC_REVOKDI, &revokdi);
        !            90: 	if (rc < 0)
        !            91: 	{   Log::perror("IMONIOC_REVOKDI on \"%s\" failed", name);
        !            92: 	    revokdi_failed = true;
        !            93: 	    if (errno == EINVAL)
        !            94: 		can_revokdi = false;
        !            95: 	}
        !            96: 	else
        !            97: 	    revokdi_failed = false;
        !            98:     }
        !            99: #else
        !           100:     can_revokdi = false;
        !           101: #endif  //  !HAVE_IMON_REVOKDI
        !           102:
        !           103:     if (!can_revokdi || revokdi_failed)
        !           104:     {
        !           105: 	// Try the old revoke ioctl.
        !           106:
        !           107: 	interest_t interest = { (char *) name, NULL, INTEREST_MASK };
        !           108: 	int rc = ioctl(imonfd, IMONIOC_REVOKE, &interest);
        !           109: 	if (rc < 0)
        !           110: 	{   //  Log error at LOG_DEBUG.  IMONIOC_REVOKE fails all the time.
        !           111: 	    Log::debug("IMONIOC_REVOKE on \"%s\" failed: %m", name);
        !           112: 	    return BAD;
        !           113: 	}
        !           114:     }
        !           115:
        !           116:     Log::debug("told imon to forget \"%s\"", name);
        !           117:     return OK;
        !           118: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>