From: niki Date: Sat, 10 Dec 2005 16:19:49 +0000 (+0000) Subject: changed quota_mnt_getlist(). X-Git-Tag: collectd-3.5.0~1^2~20 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=909020dc149c416f1da60639414b2a08e056f92c;p=collectd.git changed quota_mnt_getlist(). it returns a pointer to the last entry now. --- diff --git a/src/quota_fs.h b/src/quota_fs.h index b6ec038a..b689ae84 100644 --- a/src/quota_fs.h +++ b/src/quota_fs.h @@ -73,10 +73,10 @@ void quota_fs_printquota_dbg(quota_t *quota); RETURN VALUE The quota_fs_getquota() function returns a pointer to - the last entry of the list, or NULL if an error occurs. + the last entry of the list, or NULL if an error occued. NOTES - In case of an error, quota is not modified. + In case of an error, *quota is not modified. */ quota_t *quota_fs_getquota(quota_t **quota, quota_mnt_t *m); diff --git a/src/quota_mnt.c b/src/quota_mnt.c index 921c5898..50b0f4ff 100644 --- a/src/quota_mnt.c +++ b/src/quota_mnt.c @@ -506,16 +506,20 @@ quota_mnt_getmountopt(char *line, char *keyword) } /* char *quota_mnt_getmountopt(char *line, char *keyword) */ #if HAVE_GETMNTENT -static void +static quota_mnt_t * quota_mnt_getmntent(FILE *mntf, quota_mnt_t **list) { + quota_mnt_t *last = *list; struct mntent *mnt; +#if HAVE_GETMNTENT1 while((mnt = getmntent(mntf)) != NULL) { +#endif /* HAVE_GETMNTENT1 */ char *loop = NULL, *device = NULL; char *usrjquota = NULL; char *grpjquota = NULL; char *jqfmt = NULL; + int opts = QMO_NONE; #if 0 DBG("------------------"); @@ -559,8 +563,23 @@ quota_mnt_getmntent(FILE *mntf, quota_mnt_t **list) device = loop; } + if(quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_QUOTA, 1) != NULL) { + opts |= QMO_USRQUOTA; + } + if(quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_USRQUOTA, 1) != NULL) { + opts |= QMO_USRQUOTA; + } usrjquota = quota_mnt_getmountopt(mnt->mnt_opts, "usrjquota="); + if(usrjquota != NULL) { + opts |= QMO_USRQUOTA; + } + if(quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_GRPQUOTA, 1) != NULL) { + opts |= QMO_GRPQUOTA; + } grpjquota = quota_mnt_getmountopt(mnt->mnt_opts, "grpjquota="); + if(grpjquota != NULL) { + opts |= QMO_GRPQUOTA; + } jqfmt = quota_mnt_getmountopt(mnt->mnt_opts, "jqfmt="); #if HAVE_XFS_XQM_H @@ -579,16 +598,10 @@ quota_mnt_getmntent(FILE *mntf, quota_mnt_t **list) } } else { #endif /* HAVE_XFS_XQM_H */ - if(quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_QUOTA, 1) - == NULL - && quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_USRQUOTA, 1) - == NULL - && quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_GRPQUOTA, 1) - == NULL - && quota_fs_isnfs(mnt->mnt_type) == EXIT_FAILURE) + if((opts == QMO_NONE) && (quota_fs_isnfs(mnt->mnt_type) == EXIT_FAILURE)) { - DBG("neither quota/usrquota/grpquota option" - " nor nfs fs (%s) %s (%s): ignored", + DBG("neither quota/usrquota/grpquota/usrjquota/grpjquota" + " option nor nfs fs (%s) %s (%s): ignored", mnt->mnt_type, mnt->mnt_dir, mnt->mnt_fsname); sfree(loop); sfree(usrjquota); @@ -602,28 +615,26 @@ quota_mnt_getmntent(FILE *mntf, quota_mnt_t **list) #if 0 DBG("------------------ OK"); #endif - *list = (quota_mnt_t *)smalloc(sizeof(quota_mnt_t)); - (*list)->dir = sstrdup(mnt->mnt_dir); - (*list)->device = device; - (*list)->usrjquota = usrjquota; - (*list)->grpjquota = grpjquota; - (*list)->jqfmt = jqfmt; - (*list)->type = sstrdup(mnt->mnt_type); - (*list)->opts = QMO_NONE; -/* TODO: this is not sufficient for XFS! */ -/* TODO: maybe we should anyway NOT rely on the option in the mountfile... - ... maybe the fs should be asked direktly all time! */ - if(quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_QUOTA, 1) != NULL - || quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_USRQUOTA, 1) != NULL) { - (*list)->opts |= QMO_USRQUOTA; - } - if(quota_mnt_checkmountopt(mnt->mnt_opts, MNTOPT_GRPQUOTA, 1) != NULL) { - (*list)->opts |= QMO_GRPQUOTA; + if(*list == NULL) { + *list = (quota_mnt_t *)smalloc(sizeof(quota_mnt_t)); + last = *list; + } else { + last->next = (quota_mnt_t *)smalloc(sizeof(quota_mnt_t)); + last = last->next; } - (*list)->next = NULL; - list = &((*list)->next); + last->dir = sstrdup(mnt->mnt_dir); + last->device = device; + last->type = sstrdup(mnt->mnt_type); + last->options = sstrdup(mnt->mnt_opts); + last->usrjquota = usrjquota; + last->grpjquota = grpjquota; + last->jqfmt = jqfmt; + last->opts = opts; + last->next = NULL; } /* while((mnt = getmntent(mntf)) != NULL) */ -} + + return last; +} /* static quota_mnt_t *quota_mnt_getmntent(FILE *mntf, quota_mnt_t **list) */ #endif /* HAVE_GETMNTENT */ @@ -631,6 +642,8 @@ quota_mnt_getmntent(FILE *mntf, quota_mnt_t **list) quota_mnt_t * quota_mnt_getlist(quota_mnt_t **list) { + quota_mnt_t *last = NULL; + /* yes, i know that the indentation is wrong. but show me a better way to do this... */ /* see lib/mountlist.c of coreutils for all @@ -674,41 +687,40 @@ quota_mnt_getlist(quota_mnt_t **list) #endif /* give up */ DBG("failed get local mountpoints"); - *list = NULL; return(NULL); #if HAVE_LISTMNTENT - } else { quota_mnt_listmntent(mntlist, list); } + } else { last = quota_mnt_listmntent(mntlist, list); } freemntlist(mntlist); } #endif #if HAVE_GETVFSENT && defined(VFSTAB) - } else { quota_mnt_getvfsmnt(mntf, list); } + } else { last = quota_mnt_getvfsmnt(mntf, list); } (void)fclose(mntf); } #endif #if HAVE_GETMNTENT && defined(_PATH_MNTTAB) - } else { quota_mnt_getmntent(mntf, list); } + } else { last = quota_mnt_getmntent(mntf, list); } (void)endmntent(mntf); } #endif #if HAVE_GETMNTENT && defined(MNTTABNAME) - } else { quota_mnt_getmntent(mntf, list); } + } else { last = quota_mnt_getmntent(mntf, list); } (void)endmntent(mntf); } #endif #if HAVE_GETMNTENT && defined(MNT_MNTTAB) - } else { quota_mnt_getmntent(mntf, list); } + } else { last = quota_mnt_getmntent(mntf, list); } (void)endmntent(mntf); } #endif #if HAVE_GETMNTENT && defined(_PATH_MOUNTED) - } else { quota_mnt_getmntent(mntf, list); } + } else { last = quota_mnt_getmntent(mntf, list); } (void)endmntent(mntf); } #endif - return(*list); -} + return(last); +} /* quota_mnt_t *quota_mnt_getlist(quota_mnt_t **list) */ void quota_mnt_freelist(quota_mnt_t *list) @@ -726,6 +738,7 @@ quota_mnt_freelist(quota_mnt_t *list) sfree(l->dir); sfree(l->device); sfree(l->type); + sfree(l->options); sfree(l->usrjquota); sfree(l->grpjquota); sfree(l->jqfmt); diff --git a/src/quota_mnt.h b/src/quota_mnt.h index 7b56bf1c..36484f8f 100644 --- a/src/quota_mnt.h +++ b/src/quota_mnt.h @@ -44,10 +44,11 @@ typedef struct _quota_mnt_t quota_mnt_t; struct _quota_mnt_t { char *dir; /* "/sys" or "/" */ char *device; /* "none" or "/dev/hda1" */ - char *type; /* "sysfs" or "ext3"*/ - char *usrjquota; - char *grpjquota; - char *jqfmt; + char *type; /* "sysfs" or "ext3" */ + char *options; /* "rw,noatime,commit=600,quota,grpquota" */ + char *usrjquota; /* "q.u" */ + char *grpjquota; /* "q.g" */ + char *jqfmt; /* "TODO" */ int opts; quota_mnt_t *next; }; @@ -57,6 +58,24 @@ int quota_mnt_type(const char *type); char *quota_mnt_getmountopt(char *line, char *keyword); char *quota_mnt_checkmountopt(char *line, char *keyword, int full); +/* + DESCRIPTION + The quota_mnt_getlist() function creates a list + of all mountpoints. + + If *list is NULL, a new list is created and *list is + set to point to the first entry. + + If *list is set, the list is appended and *list is + not changed. + + RETURN VALUE + The quota_mnt_getlist() function returns a pointer to + the last entry of the list, or NULL if an error occured. + + NOTES + In case of an error, *list is not modified. +*/ quota_mnt_t *quota_mnt_getlist(quota_mnt_t **list); void quota_mnt_freelist(quota_mnt_t *list); diff --git a/src/quota_plugin.c b/src/quota_plugin.c index 15377966..d2d629ab 100644 --- a/src/quota_plugin.c +++ b/src/quota_plugin.c @@ -115,12 +115,14 @@ quota_read(void) quota_mnt_t *list = NULL, *l = NULL; quota_t *quota = NULL, *q = NULL; - l = quota_mnt_getlist(&list); + (void)quota_mnt_getlist(&list); + l = list; DBG("local mountpoints:"); while(l != NULL) { DBG("\tdir: %s", l->dir); DBG("\tdevice: %s", l->device); DBG("\ttype: %s", l->type); + DBG("\toptions: %s", l->options); DBG("\tusrjquota: %s", l->usrjquota); DBG("\tgrpjquota: %s", l->grpjquota); DBG("\tjqfmt: %s", l->jqfmt); @@ -138,7 +140,8 @@ quota_read(void) } DBG("\t== "); - q = quota_fs_getquota("a, list); + (void)quota_fs_getquota("a, list); + q = quota; #if 0 DBG("quotas:"); #endif