[pacman-dev] [PATCH 1/2] Add diskspace checking support for Solaris/Illumos
Was able to get my hands on one of these boxes today, so add yet another new way of doing this. I'm glad these calls are so standardized. This was compile tested on Linux and Illumos and seems to still be working in both places. Signed-off-by: Dan McGee <dan@archlinux.org> --- configure.ac | 3 +- lib/libalpm/diskspace.c | 54 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 0de908a..a8b142e 100644 --- a/configure.ac +++ b/configure.ac @@ -173,7 +173,8 @@ AM_CONDITIONAL([HAVE_LIBGPGME], [test "x$with_gpgme" = "xyes"]) # Checks for header files. AC_CHECK_HEADERS([fcntl.h float.h glob.h libintl.h limits.h locale.h \ - mntent.h stddef.h string.h sys/ioctl.h sys/mount.h \ + mntent.h stddef.h string.h sys/ioctl.h \ + sys/mnttab.h sys/mount.h \ sys/param.h sys/statvfs.h sys/time.h sys/types.h \ sys/ucred.h syslog.h termios.h wchar.h]) diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index fe2036d..4127153 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -1,7 +1,7 @@ /* * diskspace.c * - * Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2010-2012 Pacman Development Team <pacman-dev@archlinux.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +19,15 @@ #include "config.h" +#include <stdio.h> #include <errno.h> + #if defined(HAVE_MNTENT_H) #include <mntent.h> #endif +#if defined(HAVE_MNTTAB_H) +#include <mnttab.h> +#endif #if defined(HAVE_SYS_STATVFS_H) #include <sys/statvfs.h> #endif @@ -60,10 +65,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) alpm_list_t *mount_points = NULL, *ptr; alpm_mountpoint_t *mp; -#if defined HAVE_GETMNTENT +#if defined(HAVE_GETMNTENT) && defined(HAVE_MNTENT_H) + /* Linux */ struct mntent *mnt; FILE *fp; - struct statvfs fsp; fp = setmntent(MOUNTED, "r"); @@ -72,8 +77,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } while((mnt = getmntent(fp))) { + struct statvfs fsp; if(!mnt) { - _alpm_log(handle, ALPM_LOG_WARNING, _("could not get filesystem information\n")); + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information\n")); continue; } if(statvfs(mnt->mnt_dir, &fsp) != 0) { @@ -93,7 +100,44 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } endmntent(fp); -#elif defined HAVE_GETMNTINFO +#elif defined(HAVE_GETMNTENT) && defined(HAVE_MNTTAB_H) + /* Solaris, Illumos */ + struct mnttab mnt; + FILE *fp; + int ret; + + fp = fopen("/etc/mnttab", "r"); + + if(fp == NULL) { + return NULL; + } + + while((ret = getmntent(fp, &mnt)) == 0) { + struct statvfs fsp; + if(statvfs(mnt->mnt_mountp, &fsp) != 0) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information for %s: %s\n"), + mnt->mnt_mountp, strerror(errno)); + continue; + } + + CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); + mp->mount_dir = strdup(mnt->mnt_mountp); + mp->mount_dir_len = strlen(mp->mount_dir); + memcpy(&(mp->fsp), &fsp, sizeof(struct statvfs)); + mp->read_only = fsp.f_flag & ST_RDONLY; + + mount_points = alpm_list_add(mount_points, mp); + } + /* -1 == EOF */ + if(ret != -1) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information\n")); + } + + fclose(fp); +#elif defined(HAVE_GETMNTINFO) + /* FreeBSD (statfs), NetBSD (statvfs), OpenBSD (statfs), OS X (statfs) */ int entries; FSSTATSTYPE *fsp; -- 1.7.8.3
If you are a crazy developer like me and have bogus options in your pacman.conf file, the tab completion gets messed up by the output on stderr. Suppress it. Fix the same basic issue in zsh_completion, thanks to the work by Florian Pritz <bluewind@xinu.at>. Signed-off-by: Dan McGee <dan@archlinux.org> --- contrib/bash_completion.in | 4 ++-- contrib/zsh_completion.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/bash_completion.in b/contrib/bash_completion.in index d9e0c78..8983c92 100644 --- a/contrib/bash_completion.in +++ b/contrib/bash_completion.in @@ -59,9 +59,9 @@ _makepkg() { _pacman_pkg() { _arch_compgen "$( if [[ $2 ]]; then - \pacman -$1 | \cut -d' ' -f1 | \sort -u + \pacman -$1 2>/dev/null | \cut -d' ' -f1 | \sort -u else - \pacman -$1 + \pacman -$1 2>/dev/null fi )" } diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index 59551c5..2cfc946 100644 --- a/contrib/zsh_completion.in +++ b/contrib/zsh_completion.in @@ -276,7 +276,7 @@ _pacman_completions_repositories() { # $cmd must be declared by calling function _pacman_get_command() { # this is mostly nicked from _perforce - cmd=( "pacman" ) + cmd=( "pacman" "2>/dev/null") integer i for (( i = 2; i < CURRENT - 1; i++ )); do if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then -- 1.7.8.3
participants (1)
-
Dan McGee