checkxalloc: nudge regex, fix newfound instances
PATCH 1/5 checkxalloc: nudge regex, fix newfound instances
Using the -w flag with grep actually fought against us here, and hid some instances where xalloc functions weren't used. Discard it in favor of an explicit word boundary as a prefix to the function name, and extend our requirements on the trailing side of the pattern.
This also fixes the few new instances that were overlooked because of the regex's deficiency.
--- fdisk/sfdisk.c | 2 +- sys-utils/swapon.c | 4 ++-- tools/checkxalloc.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
fdisk/sfdisk.c +1 -1
@@ -304,7 +304,7 @@ restore_sectors(char *dev) {error (_ ("partition restore file has wrong size - not restoring\n" )); goto err; } -if (!(ss0 = (char *)malloc (statbuf.st_size))) { +if (!(ss0 =xmalloc (statbuf.st_size))) {error (_ ("out of memory?\n" )); goto err; }
sys-utils/swapon.c +2 -2
@@ -197,7 +197,7 @@ read_proc_swaps(void) { *p ='\0' ; } - q =realloc (swapFiles, (numSwaps+1 ) *sizeof (*swapFiles)); + q =xrealloc (swapFiles, (numSwaps+1 ) *sizeof (*swapFiles));if (q ==NULL )break ; swapFiles = q;
@@ -640,7 +640,7 @@ swapon_all(void) {if (!streq (fstab->mnt_type,MNTTYPE_SWAP ))continue ; - opts =strdup (fstab->mnt_opts); + opts =xstrdup (fstab->mnt_opts);for (opt =strtok (opts,"," ); opt !=NULL ; opt =strtok (NULL ,"," )) {
tools/checkxalloc.sh +1 -1
@@ -10,7 +10,7 @@ cd "$(git rev-parse --show-toplevel)" || { } git grep -zl '#include "xalloc.h"' | - xargs -0 grep -nwE '[^x](([cm]|re)alloc|strdup)\(' + xargs -0 grep -nE '\b(([cm]|re)alloc|strdup)[[:space:]]*\([^)]' result=$?
Signature · 1 line
1.7.9.4
PATCH 2/5 tunelp: remove old, now unneeded header
malloc and friends are provided by stdlib.h.
--- sys-utils/tunelp.c | 1 - 1 file changed, 1 deletion(-)
sys-utils/tunelp.c +0 -1
@@ -52,7 +52,6 @@#include <errno.h> #include <fcntl.h> #include <getopt.h> -#include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
Signature · 1 line
1.7.9.4
PATCH 3/5 include/ttyutils.h: add include guards
In reply to Dave Reisner--- include/ttyutils.h | 4 ++++ 1 file changed, 4 insertions(+)
include/ttyutils.h +4 -0
@@ -1,3 +1,5 @@ +#ifndef UTIL_LINUX_TTYUTILS_H +#define UTIL_LINUX_TTYUTILS_H #include <termios.h>
@@ -71,3 +73,5 @@ static inline void reset_virtual_console(struct termios *tp, int flags) tp->c_cc[VLNEXT ] =CLNEXT ; tp->c_cc[VEOL2] = _POSIX_VDISABLE; } + +#endif /* UTIL_LINUX_TTYUTILS_H */
Signature · 1 line
1.7.9.4
PATCH 4/5 findmnt: add FS size, avail, used, and use% columns
In reply to Dave ReisnerProvide display of filesystem attributes from statvfs(3). These are all displayed in human readable format.
--- misc-utils/findmnt.8 | 4 ++++ misc-utils/findmnt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-)
misc-utils/findmnt.8 +4 -0
@@ -103,6 +103,10 @@ Define output columns. Currently supported are .BR OLD-OPTIONS, .BR VFS-OPTIONS , .BR FS-OPTIONS , +.BR SIZE , +.BR AVAIL , +.BR USED , +.BR USE% , .BR LABEL and .BR UUID .
misc-utils/findmnt.c +53 -1
92 lines not on this page · raw message
Signature · 1 line
1.7.9.4
PATCH 5/5 findmnt: add -D, --df option to imitate df(1)
In reply to Dave Reisner--- misc-utils/findmnt.8 | 3 +++ misc-utils/findmnt.c | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
misc-utils/findmnt.8 +3 -0
@@ -49,6 +49,9 @@ Search in The output is in the tree-like format. This is the default. .IP "\fB\-c, \-\-canonicalize\fP" Canonicalize all printed paths. +.IP "\fB\-D, \-\-df\fP" +Imitate the output of df(1). This option is equivalent to +"-o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET". .IP "\fB\-d, \-\-direction \fIword\fP" The search direction - .IR forward
misc-utils/findmnt.c +18 -2
@@ -890,6 +890,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fprintf(out, _( " -a, --ascii use ASCII chars for tree formatting\n" " -c, --canonicalize canonicalize printed paths\n" + " -D, --df imitate the output of df(1)\n" " -d, --direction <word> direction of search, 'forward' or 'backward'\n" " -e, --evaluate convert tags (LABEL/UUID) to device names\n" " -F, --tab-file <path> alternative file for --fstab, --mtab or --kernel options\n"
@@ -936,7 +937,7 @@ int main(int argc, char *argv[])struct libmnt_table *tb =NULL ;char **tabfiles =NULL ;int direction =MNT_ITER_FORWARD ; -int i, c, rc =-1 , timeout =-1 ; +int i, c, rc =-1 , timeout =-1 , df_output =0 ;int ntabfiles =0 , tabtype =0 ;/* table.h */
@@ -946,6 +947,7 @@ int main(int argc, char *argv[]) { "ascii", 0, 0, 'a' }, { "canonicalize", 0, 0, 'c' }, { "direction", 1, 0, 'd' }, + { "df", 0, 0, 'D' }, { "evaluate", 0, 0, 'e' }, { "first-only", 0, 0, 'f' }, { "fstab", 0, 0, 's' },
@@ -982,7 +984,7 @@ int main(int argc, char *argv[]) tt_flags |=TT_FL_TREE ;while ((c =getopt_long (argc, argv, -"acd:ehifF:o:O:p::Pklmnrst:uvRS:T:w:" , +"acDd:ehifF:o:O:p::Pklmnrst:uvRS:T:w:" , longopts,NULL )) !=-1 ) {switch (c) {case 'a' :
@@ -991,6 +993,10 @@ int main(int argc, char *argv[])case 'c' : flags |=FL_CANONICALIZE ;break ; +case 'D' : + tt_flags &= ~TT_FL_TREE ; + df_output =1 ; +break ;case 'd' :if (!strcmp (optarg,"forward" )) direction =MNT_ITER_FORWARD ;
@@ -1100,6 +1106,16 @@ int main(int argc, char *argv[]) } } +if (df_output) { + columns[ncolumns++] =COL_SOURCE ; + columns[ncolumns++] =COL_FSTYPE ; + columns[ncolumns++] =COL_SIZE ; + columns[ncolumns++] =COL_USED ; + columns[ncolumns++] =COL_AVAIL ; + columns[ncolumns++] =COL_USEPERC ; + columns[ncolumns++] =COL_TARGET ; + } +/* default columns */ if (!ncolumns) {if (flags &FL_POLL )
Signature · 1 line
1.7.9.4
Quoted 20 lines · Dave Reisner
Using the -w flag with grep actually fought against us here, and hid some instances where xalloc functions weren't used. Discard it in favor of an explicit word boundary as a prefix to the function name, and extend our requirements on the trailing side of the pattern.
This also fixes the few new instances that were overlooked because of the regex's deficiency.
Signed-off-by Dave Reisner <[email protected]>--- fdisk/sfdisk.c | 2 +- sys-utils/swapon.c | 4 ++-- tools/checkxalloc.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)fdisk/sfdisk.c +0
-0
fdisk/sfdisk.c restore_sectors(char *dev) { · line 310
Quoted 8 lines
fdisk/sfdisk.c +1
-1@@ -304,7 +304,7 @@ restore_sectors(char *dev) {error (_ ("partition restore file has wrong size - not restoring\n" )); goto err; } -if (!(ss0 = (char *)malloc (statbuf.st_size))) { +if (!(ss0 =xmalloc (statbuf.st_size))) {error (_ ("out of memory?\n" )); goto err; }
xmalloc and friends abort the program when allocation fail.
sys-utils/swapon.c read_proc_swaps(void) { · line 202
Quoted 12 lines
sys-utils/swapon.c +1
-1@@ -197,7 +197,7 @@ read_proc_swaps(void) { *p ='\0' ; } - q =realloc (swapFiles, (numSwaps+1 ) *sizeof (*swapFiles)); + q =xrealloc (swapFiles, (numSwaps+1 ) *sizeof (*swapFiles));if (q ==NULL )break ;
same here. This would actually break functionality.
Quoted 23 lines
sys-utils/swapon.c +1
-1swapFiles = q;@@ -640,7 +640,7 @@ swapon_all(void) {if (!streq (fstab->mnt_type,MNTTYPE_SWAP ))continue ; - opts =strdup (fstab->mnt_opts); + opts =xstrdup (fstab->mnt_opts);for (opt =strtok (opts,"," ); opt !=NULL ; opt =strtok (NULL ,"," )) {tools/checkxalloc.sh +1
-1@@ -10,7 +10,7 @@ cd "$(git rev-parse --show-toplevel)" || { } git grep -zl '#include "xalloc.h"' | - xargs -0 grep -nwE '[^x](([cm]|re)alloc|strdup)\(' + xargs -0 grep -nE '\b(([cm]|re)alloc|strdup)[[:space:]]*\([^)]' result=$?
Karel Zak
maintainerQuoted 4 lines · Dave Reisner
fdisk/sfdisk.c | 2 +- sys-utils/swapon.c | 4 ++-- tools/checkxalloc.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
Applied with some minor changes, thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 2/5] tunelp: remove old, now unneeded header
In reply to Dave ReisnerQuoted 2 lines · Dave Reisner
sys-utils/tunelp.c | 1 - 1 file changed, 1 deletion(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 3/5] include/ttyutils.h: add include guards
In reply to Dave ReisnerQuoted 2 lines · Dave Reisner
include/ttyutils.h | 4 ++++ 1 file changed, 4 insertions(+)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 4/5] findmnt: add FS size, avail, used, and use% columns
In reply to Dave ReisnerQuoted 2 lines · Dave Reisner
misc-utils/findmnt.8 | 4 ++++ misc-utils/findmnt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 5/5] findmnt: add -D, --df option to imitate df(1)
In reply to Dave ReisnerQuoted 3 lines · Dave Reisner
misc-utils/findmnt.8 | 3 +++ misc-utils/findmnt.c | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
Applied, thanks.
I have added built-in filter to filter out pseudo filesystems for the df output and new --all option to disable this filter.
Karel
PS. yes, we have to fix (=de-duplicate) our and df(1) output, this is
still on TODO list.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com