From 14c106f9ca21b7f4479d966d20b4252b51019c20 Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Mon, 4 Feb 2013 12:07:27 +0100 Subject: [PATCH 1/6] beecut: exit if getopt_long_only returns an error beecut now exits if an unknown option was given or an argument was missing --- src/beecut.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/beecut.c b/src/beecut.c index d3553ef..a0358bc 100644 --- a/src/beecut.c +++ b/src/beecut.c @@ -159,6 +159,9 @@ int main(int argc, char *argv[]) case OPT_VERSION: print_version(); exit(EXIT_SUCCESS); + + case '?': + exit(EXIT_FAILURE); } } /* end while getopt_long_only */ From 2d2a0c368bc0d0ff59a254062211e31b28641865 Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Fri, 8 Feb 2013 10:46:42 +0100 Subject: [PATCH 2/6] bee-check: fix reading the CONTENT file and the filename handling there were problems if a filename contains spaces replacing the for loop and always quoting the arguments fixes this issue --- src/bee-check.sh.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bee-check.sh.in b/src/bee-check.sh.in index 2896c75..e004561 100644 --- a/src/bee-check.sh.in +++ b/src/bee-check.sh.in @@ -230,8 +230,8 @@ do_check() { echo "checking ${pkg} .." - for line in $(cat ${filesfile}) ; do - eval $(${BEESEP} ${line}) + while read line ; do + eval $(${BEESEP} "${line}") # save and strip possible symbolic link destination.. symlink=${file#*//} @@ -246,7 +246,7 @@ do_check() { if [ ! -h "${file}" ] ; then echo " [changed] ${file}" else - sdest=$(readlink ${file}) + sdest=$(readlink "${file}") if [ "${sdest}" != "${symlink}" ] ; then echo " [changed] ${file}" fi @@ -262,7 +262,7 @@ do_check() { fi else # regular file - check md5sum.. - md5now=$(md5sum ${file} | sed -e 's,^\([a-z0-9]*\).*$,\1,') + md5now=$(md5sum "${file}" | sed -e 's,^\([a-z0-9]*\).*$,\1,') if [ "${md5}" != "${md5now}" ] ; then echo " [changed] ${file}" @@ -271,7 +271,7 @@ do_check() { # check mode, uid and gid of directory/file - stat=( $(stat ${file} --printf "%f %u %g %U %G") ) + stat=( $(stat "${file}" --printf "%f %u %g %U %G") ) full=$(printf "0%o" 0x${stat[0]}) @@ -286,7 +286,7 @@ do_check() { if [ "${gid}" != "${stat[2]}" ] ; then echo " [changed] ${file}" fi - done + done < "${filesfile}" } From 78a39da8b230ee01771b8edd1e4826fdc018ca59 Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Fri, 8 Feb 2013 11:02:59 +0100 Subject: [PATCH 3/6] bee-query: fix reading the CONTENT file and the filename handling there were problems if a filename contains spaces replacing the for loops and always quoting arguments fixes this issue --- src/bee-query.sh.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bee-query.sh.in b/src/bee-query.sh.in index fbcec0f..c7b0df4 100644 --- a/src/bee-query.sh.in +++ b/src/bee-query.sh.in @@ -57,7 +57,7 @@ query() { eval $(${BEE_BINDIR}/beeversion $base) get_files "${PKGALLPKG}" else - get_pkgs ${f} + get_pkgs "${f}" fi done } @@ -68,10 +68,10 @@ get_files() { for s in "" "${BEE_METADIR}" ; do ff="${s}/${pkg}/CONTENT" if [ -e "${ff}" ] ; then - for line in $(cat ${ff}) ; do - eval $(${BEESEP} ${line}) + while read line ; do + eval $(${BEESEP} "${line}") echo ${file} - done + done < "${ff}" fi done } @@ -81,12 +81,12 @@ get_pkgs() { for pkg in $(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed) ; do - if egrep -q "file=.*${f}" ${BEE_METADIR}/${pkg}/CONTENT ; then + if egrep -q "file=.*${f}" "${BEE_METADIR}/${pkg}/CONTENT" ; then echo ${pkg} - for line in $(egrep "file=.*${f}" ${BEE_METADIR}/${pkg}/CONTENT) ; do - eval $(${BEESEP} ${line}) + while read line ; do + eval $(${BEESEP} "${line}") echo " ${file}" - done + done < <(egrep "file=.*${f}" "${BEE_METADIR}/${pkg}/CONTENT") fi done } From d6b32f994bac4c0210e284f60822b11bd84ca8cc Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Sat, 29 Dec 2012 22:34:58 +0100 Subject: [PATCH 4/6] beegetopt: free memory before exiting beegetopt is leaking memory if BEE_GETOPT_ERROR occurs the variables beeopts and beeoptptr are now freed before exiting --- src/beegetopt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/beegetopt.c b/src/beegetopt.c index a66f5d3..ffbbd85 100644 --- a/src/beegetopt.c +++ b/src/beegetopt.c @@ -244,6 +244,8 @@ int main(int argc, char *argv[]) while((opt=bee_getopt(&optctl, &i)) != BEE_GETOPT_END) { if (opt == BEE_GETOPT_ERROR) { + free(beeopts); + free(beeoptptr); exit(1); } From 2e62d45a8cffb76f005ac04fdfbb5a8c6e1cc810 Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Sun, 24 Feb 2013 21:17:00 +0100 Subject: [PATCH 5/6] bee-check: declare bash functions with keyword 'function' --- src/bee-check.sh.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bee-check.sh.in b/src/bee-check.sh.in index e004561..2fe0f7d 100644 --- a/src/bee-check.sh.in +++ b/src/bee-check.sh.in @@ -41,7 +41,7 @@ VERSION=${BEE_VERSION} ############################################################################### ## ## -pkg_check_all() { +function pkg_check_all() { if [ ! "${1}" ] ; then pkg_check @@ -57,7 +57,7 @@ pkg_check_all() { ############################################################################### ## ## -pkg_check_deps() { +function pkg_check_deps() { installed=$(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed --by-pkgfullname ${1}) if [ ! "${installed}" -a $OPT_F -gt 0 ] ; then @@ -75,7 +75,7 @@ pkg_check_deps() { ############################################################################### ## ## -pkg_check() { +function pkg_check() { installed=$(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed --by-pkgfullname ${1}) if [ ! "${installed}" -a $OPT_F -gt 0 ] ; then @@ -101,7 +101,7 @@ pkg_check() { } -do_check_deps_of_file() { +function do_check_deps_of_file() { local file=${1} local type="OTHER" @@ -175,7 +175,7 @@ do_check_deps_of_file() { ############################################################################### ## ## -do_check_deps() { +function do_check_deps() { local pkg=${1} local filesfile=${BEE_METADIR}/${pkg}/CONTENT @@ -222,7 +222,7 @@ do_check_deps() { ############################################################################### ## ## -do_check() { +function do_check() { local pkg=${1} local stat local full @@ -291,7 +291,7 @@ do_check() { } ##### usage ################################################################### -usage() { +function usage() { cat <<-EOF bee-check v${VERSION} 2009-2012 by Marius Tolzmann and Tobias Dreyer <{tolzmann,dreyer}@molgen.mpg.de> From 7ea346c0bdc10fe08977487f389cc706e5f8574a Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Sun, 24 Feb 2013 21:18:02 +0100 Subject: [PATCH 6/6] bee-query: declare bash functions with keyword 'function' --- src/bee-query.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bee-query.sh.in b/src/bee-query.sh.in index c7b0df4..1a9d2b5 100644 --- a/src/bee-query.sh.in +++ b/src/bee-query.sh.in @@ -46,7 +46,7 @@ usage() { EOF } -query() { +function query() { list=$@ for f in "${list[@]}" ; do @@ -62,7 +62,7 @@ query() { done } -get_files() { +function get_files() { pkg=${1} for s in "" "${BEE_METADIR}" ; do @@ -76,7 +76,7 @@ get_files() { done } -get_pkgs() { +function get_pkgs() { f=$1 for pkg in $(${BEE_LIBEXECDIR}/bee/bee.d/bee-list --installed) ; do