Skip to contentSkip to conversation

require C99, add robustness and small fixes

GIT PULL Applied Sami Kerola 3 participants 8 messages Jun 10, 2012 – Jun 15, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Karel et.al.

Here is bunch of patches which are result of reading compiler warnings, and thinking what could be done to them. Most of the fixes are straight forward, but then again there are some which affect more. I suspect requiring C99 is one of such.

Few last patches might be more interesting than others. The partx fix will make command behave more explicit manner. The eject and lsblk fixes are all about dealing what system call might return.

The following changes since commit 0e60bc9b152a3414c04c50523b5bf555665a6cea:

build-sys: add compiler warnings (2012-06-06 12:10:41 +0200)

are available in the git repository at:

git://github.com/kerolasa/lelux-utiliteetit.git 2012wk23

for you to fetch changes up to e8089b7a0378117c7285d1def395bff905f62c60:

lsblk: print hex code when unknown block device type is found
(2012-06-10 22:58:05 +0200)

----------------------------------------------------------------
Sami Kerola (14):
setarch: do not use -1 as array index [cppcheck]
blkid: fix realloc memory leak [cppcheck]
uuidd: use output redirection which works [checkbashisms]
build-sys: expect C99 compliant compiler
include: fix spurious list.h warnings
build: fix redundant redeclaration warnings
build: fix unused parameter warnings
sysfs: fix printf format warnings
include: fix void pointer arithmetics warnings
partx: clarify up exclusive option handling
docs: clean up partx.8 manual
eject: inform if CD-ROM drive is not ready
wipefs: use symbolic value for markup mode
lsblk: print hex code when unknown block device type is found

 configure.ac          |   28 ++++++
 getopt/getopt.c       |    1 -
 include/all-io.h      |    4 +-
 include/list.h        |    4 +-
 lib/env.c             |    2 +
 lib/pager.c           |    3 +-
 lib/randutils.c       |    3 +-
 lib/sysfs.c           |    2 +-
 libmount/src/mountP.h |    2 -
 libmount/src/optstr.c |    5 +-
 login-utils/su.c      |    2 +
 misc-utils/blkid.c    |    4 +-
 misc-utils/kill.c     |    3 -
 misc-utils/lsblk.c    |    6 ++
 misc-utils/uuidd.rc   |    2 +-
 misc-utils/wipefs.c   |   11 ++-
 mount/fstab.c         |    2 +
 partx/partx.8         |  231 +++++++++++++++++++++++++++++--------------------
 partx/partx.c         |   54 ++++++------
 sys-utils/eject.c     |    8 ++
 sys-utils/setarch.c   |    6 +-
 term-utils/agetty.c   |    2 -
 term-utils/script.c   |    1 -
 term-utils/wall.c     |    1 -
 24 files changed, 238 insertions(+), 149 deletions(-)
configure.ac +2 -0
index 2280e7e..13c9637 100644
@@ -80,6 +80,24 @@ AC_CANONICAL_HOST
 AC_C_CONST
 AC_C_VOLATILE
 AC_C_BIGENDIAN
+if test "$cross_compiling" = no; then
+  if test "x$ac_cv_prog_cc_c99" = "xno" || test "x$ac_cv_prog_cc_c99"

= "x"; then

+  # We might be on RHEL5 with a git checkout and so broken
+  # autoconf. Check if CC is gcc and if it bails when given -std=gnu99.
+  # If not, use that.  Yuck.

+ if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
+ CC="$CC -std=gnu99"
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([],[[
+ return 0;

+      ]])],
+      [],
+      [AC_MSG_ERROR([Could not find a C99 compatible compiler])])

+ else
+ AC_MSG_ERROR([Could not find a C99 compatible compiler])
+ fi
+ fi
+fi

dnl Compiler warnings
UL_WARN_ADD([-Wextra])
@@ -262,6 +280,16 @@ AC_CHECK_DECL([lseek64],
#define _LARGEFILE64_SOURCE
#include <unistd.h>])

+AC_CHECK_DECL([environ],
+ [AC_DEFINE(HAVE_ENVIRON_DECL, 1,
+ [Define to 1 if have **environ prototype])],
+)
+
+AC_CHECK_DECL([strsignal],
+ [AC_DEFINE(HAVE_STRSIGNAL_DECL, 1,
+ [Define to 1 if have strsignal function prototype])],
+)
+
AC_CHECK_FUNCS([ \
__fpending \
__secure_getenv \

getopt/getopt.c +0 -0
index dcc55b6..4ba3401 100644
@@ -86,7 +86,6 @@ int (*getopt_long_fp) (int argc, char *const *argv,

const char *optstr,
static const char *normalize(const char *arg);
static int generate_output(char *argv[], int argc, const char *optstr,
const struct option *longopts);
-int main(int argc, char *argv[]);
static void parse_error(const char *message);
static void add_long_options(char *options);
static void add_longopt(const char *name, int has_arg);

include/all-io.h +0 -0
index b79d702..38a760f 100644
@@ -15,7 +15,7 @@ static inline int write_all(int fd, const void *buf,

size_t count)
if (tmp > 0) {
count -= tmp;
if (count)
- buf += tmp;
+ buf = (void *) ((char *) buf + tmp);
} else if (errno != EINTR && errno != EAGAIN)
return -1;
if (errno == EAGAIN) /* Try later, *sigh* */
@@ -35,7 +35,7 @@ static inline int fwrite_all(const void *ptr, size_t size,
if (tmp > 0) {
nmemb -= tmp;
if (nmemb)
- ptr += (tmp * size);
+ ptr = (void *) ((char *) ptr + (tmp * size));
} else if (errno != EINTR && errno != EAGAIN)
return -1;
if (errno == EAGAIN) /* Try later, *sigh* */

include/list.h +0 -0
index d8c3bf0..1824af0 100644
@@ -221,7 +221,7 @@ _INLINE_ struct list_head *merge(int (*cmp)(struct

list_head *a,
}
tail = tail->next;
}
- tail->next = a?:b;
+ tail->next = a ? a : b;
return head.next;
}

@@ -252,7 +252,7 @@ _INLINE_ void merge_and_restore_back_links(int (*cmp)(struct list_head *a,
}
tail = tail->next;
}
- tail->next = a ? : b;
+ tail->next = a ? a : b;

do {
/*

lib/env.c +2 -0
index e6d119f..04e0f0b 100644
@@ -21,7 +21,9 @@
 
 #include "env.h"
 
+#ifndef HAVE_ENVIRON_DECL
 extern char **environ;
+#endif
 
 static char * const forbid[] = {
         "_RLD_=",
lib/pager.c +2 -1
index f02d55d..4c50de4 100644
@@ -200,7 +200,8 @@ void setup_pager(void)
 
 #define MAX 255
 
-int main(int argc, char *argv[])
+int main(int argc __attribute__ ((__unused__)),
+	 char *argv[] __attribute__ ((__unused__)))
 {
 	int i;
 
lib/randutils.c +2 -1
index b90c886..85cb1a9 100644
@@ -105,7 +105,8 @@ void random_get_bytes(void *buf, size_t nbytes)
 }
 
 #ifdef TEST_PROGRAM
-int main(int argc, char *argv[])
+int main(int argc __attribute__ ((__unused__)),
+         char *argv[] __attribute__ ((__unused__)))
 {
 	unsigned int v, i;
 
lib/sysfs.c +0 -0
index 3b5d045..312191f 100644
@@ -90,7 +90,7 @@ dev_t sysfs_devname_to_devno(const char *name, const

char *parent)
if (!f)
return 0;

- if (fscanf(f, "%u:%u", &maj, &min) == 2)
+ if (fscanf(f, "%d:%d", &maj, &min) == 2)
dev = makedev(maj, min);
fclose(f);
}

libmount/src/mountP.h +0 -0
index c7d378e..f7cd7d5 100644
@@ -380,7 +380,6 @@ extern int mnt_context_guess_fstype(struct

libmnt_context *cxt);
extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
const char *name, const char *type);
extern int mnt_context_prepare_update(struct libmnt_context *cxt);
-extern struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt);
extern int mnt_context_merge_mflags(struct libmnt_context *cxt); extern int mnt_context_update_tabs(struct libmnt_context *cxt);

@@ -395,7 +394,6 @@ extern int mnt_context_clear_loopdev(struct libmnt_context *cxt);
extern int mnt_fork_context(struct libmnt_context *cxt);

/* tab_update.c */
-extern struct libmnt_fs *mnt_update_get_fs(struct libmnt_update *upd);
extern int mnt_update_set_filename(struct libmnt_update *upd,
const char *filename, int userspace_only);

libmount/src/optstr.c +0 -1
index 66d2a06..75d0263 100644
@@ -771,7 +771,10 @@ err:
  *
  * Returns: 0 on success, negative number in case of error.
  */
-int mnt_optstr_fix_secontext(char **optstr, char *value, size_t

valsz, char **next)
+int mnt_optstr_fix_secontext(char **optstr __attribute__ ((__unused__)),

+			     char *value   __attribute__ ((__unused__)),
+			     size_t valsz  __attribute__ ((__unused__)),
+			     char **next   __attribute__ ((__unused__)))

{
int rc = 0;

login-utils/su.c +2 -0
index 0f535b9..2622209 100644
@@ -78,7 +78,9 @@ enum
 /* The user to become if none is specified.  */
 #define DEFAULT_USER "root"
 
+#ifndef HAVE_ENVIRON_DECL
 extern char **environ;
+#endif
 
 static void run_shell (char const *, char const *, char **, size_t)
      __attribute__ ((__noreturn__));
misc-utils/blkid.c +0 -0
index 25e6c00..7b2170f 100644
@@ -365,8 +365,10 @@ static int append_str(char **res, size_t *sz,

const char *a, const char *b)
return -1;

str = realloc(str, len + 1);
- if (!str)
+ if (!str) {
+ free(res);
return -1;
+ }

*res = str;
str += *sz;

misc-utils/kill.c +0 -3
index c592f52..8e2a1d8 100644
@@ -139,7 +139,6 @@ struct signv {
 #endif
 };
 
-int main (int argc, char *argv[]);
 extern char *mybasename(char *);
 int signame_to_signum (char *sig);
 int arg_to_signum (char *arg, int mask);
@@ -149,8 +148,6 @@ void printsignals (FILE *fp);
 int usage (int status);
 int kill_verbose (char *procname, int pid, int sig);
 
-extern int *get_pids (char *, int);
-
 static char *progname;
 
 #ifdef HAVE_SIGQUEUE
misc-utils/lsblk.c +6 -0
index 9e894ef..f9e05b6 100644
@@ -527,6 +527,12 @@ static char *get_type(struct blkdev_cxt *cxt)
 				type = "mo-disk"; break;
 			case 0x0e: /* TYPE_RBC */
 				type = "rbc"; break;
+			default:
+				/* Perhaps include/scsi/scsi.h in
+				 * kernel git section 'DEVICE TYPES'
+				 * will know what was found.  */
+				sprintf(type, "0x%02x", x);
+				break;
 		}
 
 		res = xstrdup(type);
misc-utils/uuidd.rc +1 -1
index dbdd5f5..d10fced 100644
@@ -49,7 +49,7 @@ case "$1" in
 	log_end_msg $?
     ;;
   status)
-	if pidofproc -p $PIDFILE $DAEMON >& /dev/null ; then
+	if pidofproc -p $PIDFILE $DAEMON >/dev/null 2>&1; then
 	    echo "$DAEMON is running";
 	    exit 0;
 	else
misc-utils/wipefs.c +8 -3
index e0ced2f..259ca37 100644
@@ -56,8 +56,10 @@ struct wipe_desc {
 	struct wipe_desc	*next;
 };
 
-#define WP_MODE_PRETTY		0		/* default */
-#define WP_MODE_PARSABLE	1
+enum {
+	WP_MODE_PRETTY,		/* default */
+	WP_MODE_PARSABLE
+};
 
 static const char *type_pattern;
 
@@ -117,6 +119,8 @@ print_all(struct wipe_desc *wp, int mode)
 		case WP_MODE_PARSABLE:
 			print_parsable(wp, n++);
 			break;
+		default:
+			abort();
 		}
 		wp = wp->next;
 	}
@@ -375,7 +379,8 @@ int
 main(int argc, char **argv)
 {
 	struct wipe_desc *wp0 = NULL, *wp;
-	int c, all = 0, has_offset = 0, noact = 0, mode = 0, quiet = 0;
+	int c, all = 0, has_offset = 0, noact = 0, quiet = 0;
+	int mode = WP_MODE_PRETTY;
 
 	static const struct option longopts[] = {
 	    { "all",       0, 0, 'a' },
mount/fstab.c +2 -0
index 043cc43..a394591 100644
@@ -578,7 +578,9 @@ static int lockfile_fd = -1;
 static int signals_have_been_setup = 0;
 
 /* Ensure that the lock is released if we are interrupted.  */
+#ifndef HAVE_STRSIGNAL_DECL
 extern char *strsignal(int sig);	/* not always in <string.h> */
+#endif
 
 static void
 handler (int sig) {
partx/partx.8 +6 -20
index dd5ebe7..86350c4 100644
@@ -3,132 +3,171 @@
 .\" Copyright 2007 Red Hat, Inc.
 .\" Copyright 2010 Davidlohr Bueso <[email protected]>
 .\" May be distributed under the GNU General Public License
-.TH PARTX 8 "February 2011" "util-linux" "System Administration"
+.TH PARTX "8" "June 2012" "util-linux" "System Administration"
 .SH NAME
-partx \-
-tell the Linux kernel about the presence and numbering of on-disk partitions
+partx \- tell the Linux kernel about the presence and numbering of
+on-disk partitions
 .SH SYNOPSIS
-.B partx
-.RB [ \-a | \-d | \-s ]
-.RB [ \-t
-.IR TYPE ]
-.RB [ \-n
-.IR M:N ]
-.RI [ \- ]
-.I disk
-
-.B partx
-.RB [ \-a | \-d | \-s ]
-.RB [ \-t
-.IR TYPE ]
-.I partition
-.RI [ disk ]
-
+partx [\-a|\-d|\-s] [\-t TYPE] [\-n M:N] [\-] disk
+.br
+partx [\-a|\-d|\-s] [\-t TYPE] partition [disk]
 .SH DESCRIPTION
-Given a device or disk-image, \fBpartx\fP tries to parse the

partition table and
-list its contents. It optionally adds or removes partitions.
-
+Given a device or disk-image,
+.B partx
+tries to parse the partition table and list its contents. It +optionally adds or removes partitions.
+.PP
The
.I disk
-argument is optional when a
-.I partition
-argument is provided. To force scanning a partition as if it were a whole disk -(for example to list nested subpartitions), use the argument "-". For example:
-
-.RS
-.br
-.B partx \-\-show \- /dev/sda3
+argument is optional when a
+.I partition
+argument is provided. To force scanning a partition as if it were a +whole disk (for example to list nested subpartitions), use the argument +"-". For example:
+.RS 7
+.TP
+partx \-\-show \- /dev/sda3
.RE
-
+.PP
This will see sda3 as a whole-disk rather than a partition.
-
-.B This is not an fdisk program
-\-\- adding and removing partitions
-does not change the disk, it just tells the kernel
-about the presence and numbering of on-disk partitions.
-
+.PP
+The
+.B partx is not an fdisk program
+\-\- adding and removing partitions does not change the disk, it just +tells the kernel about the presence and numbering of on-disk +partitions.
.SH OPTIONS
-.IP "\fB\-a, \-\-add\fP"
+.IP "\fB\-a\fR, \fB\-\-add\fP"
Add the specified partitions, or read the disk and add all partitions.
-.IP "\fB\-b, \-\-bytes\fP"
+.IP "\fB\-b\fR, \fB\-\-bytes\fP"
Print the SIZE column in bytes rather than in human-readable format.
-.IP "\fB\-d, \-\-delete\fP"
+.IP "\fB\-d\fR, \fB\-\-delete\fP"
Delete the specified partitions or all partitions.
-.IP "\fB\-g, \-\-noheadings\fP"
+.IP "\fB\-g\fR, \fB\-\-noheadings\fP"
Do not print a header line.
-.IP "\fB\-h, \-\-help\fP"
+.IP "\fB\-h\fR, \fB\-\-help\fP"
Print a help text and exit.
-.IP "\fB\-l, \-\-list\fP"
-List the partitions. Note that all numbers are in 512-byte sectors. This output
-format is DEPRECATED in favour of \fB\-\-show\fP. Don't use it in newly written
-scripts.
-.IP "\fB\-o, \-\-output \fIlist\fP"
-Define the output columns to use for \fB\-\-show\fP and \fB\-\-raw\fP output. -If no output arrangement is specified, then a default set is used. -Use \fB\-\-help\fP to get list of all supported columns.
-.IP "\fB\-P, \-\-pairs\fP"
-Use key="value" output format.
-.IP "\fB\-n, \-\-nr \fIM:N\fP"
-Specify the range of partitions. For backward compatibility also the format -<M-N> is supported. The range may contain negative
-numbers, for example "--nr :-1" means the last partition, and "--nr -2:-1" means
-the last two partitions. Supported range specifications are:
-.RS
+.IP "\fB\-l\fR, \fB\-\-list\fP"
+List the partitions. Note that all numbers are in 512-byte sectors. +This output format is DEPRECATED in favour of
+.BR \-\-show .
+Do not use it in newly written scripts.
+.IP "\fB\-o\fR, \fB\-\-output \fIlist\fP"
+Define the output columns to use for
+.B \-\-show
+and
+.B \-\-raw
+output. If no output arrangement is specified, then a default set is +used. Use
+.B \-\-help
+to get
+.I list
+of all supported columns. This option cannot be combined with +.BR \-\-add ,
+.B \-\-delete
+or
+.B \-\-list
+options.
+.IP "\fB\-P\fR, \fB\-\-pairs\fP"
+Output using key="value" format.
+.IP "\fB\-n\fR, \fB\-\-nr \fIM:N\fP"
+Specify the range of partitions. For backward compatibility also the +format
+.I M-N
+is supported. The range may contain negative numbers, for example +.BI \-\-nr \ :\-1
+means the last partition, and
+.BI \-\-nr \ \-2:\-1
+means the last two partitions. Supported range specifications are:
+.RS 14
.TP
-.B <M>
-Specifies just one partition (e.g. --nr 3).
+.I M
+Specifies just one partition (e.g. \fB\-\-nr\fR
+.IR 3 ).
.TP
-.B <M:>
-Specifies lower limit only (e.g. --nr 2:).
+.I M:
+Specifies lower limit only (e.g. \fB\-\-nr\fR
+.IR 2: ).
.TP
-.B <:N>
-Specifies upper limit only (e.g. --nr :4).
+.I :N
+Specifies upper limit only (e.g. \fB\-\-nr\fR
+.IR :4 ).
.TP
-.B <M:N>
-or
-.B <M-N>
-Specifies lower and upper limits (e.g. --nr 2:4).
+.IR M:N \ or
+.TQ
+.I M-N
+Specifies lower and upper limits (e.g. \fB--nr\fR
+.IR 2:4 ).
.RE
-.IP "\fB\-r, \-\-raw\fP"
+.IP "\fB\-r\fR, \fB\-\-raw\fP"
Use the raw output format.
-.IP "\fB\-s, \-\-show\fP"
-List the partitions. All numbers (except SIZE) are in 512-byte sectors. The output
-columns can be rearranged with the \fB\-\-output\fP option.
-.IP "\fB\-t, \-\-type \fItype\fP"
-Specify the partition table type -- aix, bsd, dos, gpt, mac, minix, sgi, solaris_x86,
-sun, ultrix or unixware.
-.IP "\fB\-v, \-\-verbose\fP"
+.IP "\fB\-s\fR, \fB\-\-show\fP"
+List the partitions. All numbers (except SIZE) are in 512-byte +sectors. The output columns can be rearranged with the
+.B \-\-output
+option.
+.IP "\fB\-t\fR, \fB\-\-type \fItype\fP"
+Specify the partition table type
+.IR aix ,
+.IR bsd ,
+.IR dos ,
+.IR gpt ,
+.IR mac ,
+.IR minix ,
+.IR sgi ,
+.IR solaris_x86 ,
+.IR sun ,
+.I ultrix
+or
+.IR unixware .
+.IP "\fB\-v\fR, \fB\-\-verbose\fP"
Verbose mode.
.SH EXAMPLES
-.IP "\fBpartx \-\-show /dev/sdb3\fP"
-.IP "\fBpartx \-\-show --nr 3 /dev/sdb\fP"
-.IP "\fBpartx \-\-show /dev/sdb3 /dev/sdb\fP"
+.TP
+partx \-\-show /dev/sdb3
+.TQ
+partx \-\-show --nr 3 /dev/sdb
+.TQ
+partx \-\-show /dev/sdb3 /dev/sdb
All three commands list partition 3 of /dev/sdb.
-.IP "\fBpartx \-\-show \- /dev/sdb3\fP"
-Lists all subpartitions on /dev/sdb3 (the device is used as whole-disk). -.IP "\fBpartx \-o START -g --nr 3 /dev/sdb\fP"
-Prints the start sector of partition 5 on /dev/sda without header. -.IP "\fBpartx \-o SECTORS,SIZE /dev/sda5 /dev/sda\fP"
-Lists the length in sectors and human-readable size of partition 5 on /dev/sda. -.IP "\fBpartx \-\-add --nr 3:5 /dev/sdd\fP"
+.TP
+partx \-\-show \- /dev/sdb3
+Lists all subpartitions on /dev/sdb3 (the device is used as +whole-disk).
+.TP
+partx \-o START -g --nr 5 /dev/sdb
+Prints the start sector of partition 5 on /dev/sdb without header. +.TP
+partx \-o SECTORS,SIZE /dev/sda5 /dev/sda
+Lists the length in sectors and human-readable size of partition 5 on +/dev/sda.
+.TP
+partx \-\-add --nr 3:5 /dev/sdd
Adds all available partitions from 3 to 5 (inclusive) on /dev/sdd.
-.IP "\fBpartx \-d --nr :-1 /dev/sdd\fP"
+.TP
+partx \-d --nr :-1 /dev/sdd
Removes the last partition on /dev/sdd.
-
.SH SEE ALSO
.BR addpart (8),
.BR delpart (8),
.BR fdisk (8),
.BR parted (8),
.BR partprobe (8)
-
.SH AUTHORS
-.nf
-Davidlohr Bueso <[email protected]>
-Karel Zak <[email protected]>
-.fi
-
-The original version was written by Andries E. Brouwer <[email protected]>. +.MT [email protected]
+Davidlohr Bueso
+.ME
+.br
+.MT [email protected]
+Karel Zak
+.ME
+.PP
+The original version was written by
+.MT [email protected]
+Andries E. Brouwer
+.ME .
.SH AVAILABILITY
The partx command is part of the util-linux package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
+.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/ +Linux Kernel Archive
+.UE .

partx/partx.c +27 -27

119 lines not on this page · raw message

sys-utils/eject.c +8 -0
index 4f3fb83..68f1f85 100644
@@ -429,6 +429,14 @@ static void toggle_tray(int fd)
 		if (eject_cdrom(fd))
 			err(EXIT_FAILURE, _("CD-ROM eject command failed"));
 		return;
+	case CDS_NO_INFO:
+		warnx(_("no CD-ROM information available"));
+		return;
+	case CDS_DRIVE_NOT_READY:
+		warnx(_("CD-ROM drive is not ready"));
+		return;
+	default:
+		abort();
 	}
 #endif
 
sys-utils/setarch.c +3 -3
index 97269f4..a0c6ea8 100644
@@ -259,12 +259,12 @@ int main(int argc, char *argv[])
 
   p = program_invocation_short_name;
   if (!strcmp(p, "setarch")) {
-    argv++;
     argc--;
     if (argc < 1)
       show_usage(_("Not enough arguments"));
-    p = argv[0];
-    argv[0] = argv[-1];      /* for getopt_long() to get the program name */
+    p = argv[1];
+    argv[1] = argv[0];		/* for getopt_long() to get the program name */
+    argv++;
     if (!strcmp(p, "-h") || !strcmp(p, "--help"))
       show_help();
     else if (!strcmp(p, "-V") || !strcmp(p, "--version"))
term-utils/agetty.c +0 -2
index 9101e7f..862b8c4 100644
@@ -533,8 +533,6 @@ static void login_options_to_argv(char *argv[], int *argc,
 /* Parse command-line arguments. */
 static void parse_args(int argc, char **argv, struct options *op)
 {
-	extern char *optarg;
-	extern int optind;
 	int c;
 
 	enum {
term-utils/script.c +0 -1
index 07be7e9..05d9f85 100644
@@ -158,7 +158,6 @@ int
 main(int argc, char **argv) {
 	sigset_t block_mask, unblock_mask;
 	struct sigaction sa;
-	extern int optind;
 	int ch;
 	FILE *timingfd = stderr;
 
term-utils/wall.c +0 -1
index 3255a51..9966506 100644
@@ -93,7 +93,6 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 
 int
 main(int argc, char **argv) {
-	extern int optind;
 	int ch;
 	struct iovec iov;
 	struct utmp *utmpptr;
Signature · 2 lines
   Sami Kerola
   http://www.iki.fi/kerolasa/
#1 lore raw

Hi,

Quoted 15 lines
configure.ac +2 -0
@@ -80,6 +80,24 @@ AC_CANONICAL_HOST
 AC_C_CONST
 AC_C_VOLATILE
 AC_C_BIGENDIAN
+if test "$cross_compiling" = no; then
+  if test "x$ac_cv_prog_cc_c99" = "xno" || test "x$ac_cv_prog_cc_c99"

= "x"; then

configure.ac +6 -0
+  # We might be on RHEL5 with a git checkout and so broken
+  # autoconf. Check if CC is gcc and if it bails when given -std=gnu99.
+  # If not, use that.  Yuck.
+    if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
+       CC="$CC -std=gnu99"
+       AC_RUN_IFELSE(

configure.ac

Quoted 10 lines
configure.ac +10 -0
+          [AC_LANG_PROGRAM([],[[
+  return 0;
+      ]])],
+      [],
+      [AC_MSG_ERROR([Could not find a C99 compatible compiler])])
+    else
+      AC_MSG_ERROR([Could not find a C99 compatible compiler])
+    fi
+  fi
+fi

This break cross compiling as in this case -std=gnu99 is not added to $CC. Why not use AC_PROG_CC_C99 (present in autoconf-2.69) that is cross compiling friendly and set CC to the correct value depending on which compiler is used (GCC, AIX, HP ...)

I advise you to read autoconf/c.m4.

Signature · 1 line
Beber
maintainer
#2 lore raw
In reply to Sami Kerola
Quoted 17 lines · Sami Kerola
configure.ac +2 -0
index 2280e7e..13c9637 100644
@@ -80,6 +80,24 @@ AC_CANONICAL_HOST
 AC_C_CONST
 AC_C_VOLATILE
 AC_C_BIGENDIAN
+if test "$cross_compiling" = no; then
+  if test "x$ac_cv_prog_cc_c99" = "xno" || test "x$ac_cv_prog_cc_c99"

= "x"; then

configure.ac +6 -0
+  # We might be on RHEL5 with a git checkout and so broken
+  # autoconf. Check if CC is gcc and if it bails when given -std=gnu99.
+  # If not, use that.  Yuck.
+    if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
+       CC="$CC -std=gnu99"
+       AC_RUN_IFELSE(

configure.ac

Quoted 10 lines
configure.ac +10 -0
+          [AC_LANG_PROGRAM([],[[
+  return 0;
+      ]])],
+      [],
+      [AC_MSG_ERROR([Could not find a C99 compatible compiler])])
+    else
+      AC_MSG_ERROR([Could not find a C99 compatible compiler])
+    fi
+  fi
+fi

AC_PROG_CC_C99 sounds really like a better solution, although I have autoconf 2.68 on Fedora 16 :-(

misc-utils/blkid.c static int append_str(char **res, size_t *sz, · line 370

Quoted 10 lines
misc-utils/blkid.c +2 -1
@@ -365,8 +365,10 @@ static int append_str(char **res, size_t *sz,
 const char *a, const char *b)
 		return -1;
 
 	str = realloc(str, len + 1);
-	if (!str)
+	if (!str) {
+		free(res);
        free(*res);
Quoted 10 lines
misc-utils/blkid.c +1 -0
 		return -1;
+	}
 
 	*res = str;
misc-utils/blkid.c +0 -0
 	str += *sz;
misc-utils/lsblk.c +0 -0
index 9e894ef..f9e05b6 100644

misc-utils/lsblk.c static char *get_type(struct blkdev_cxt *cxt) · line 535

Quoted 9 lines
misc-utils/lsblk.c +6 -0
@@ -527,6 +527,12 @@ static char *get_type(struct blkdev_cxt *cxt)
 				type = "mo-disk"; break;
 			case 0x0e: /* TYPE_RBC */
 				type = "rbc"; break;
+			default:
+				/* Perhaps include/scsi/scsi.h in
+				 * kernel git section 'DEVICE TYPES'
+				 * will know what was found.  */
+				sprintf(type, "0x%02x", x);
+				break;

What about to add scsi_type_to_name() to lib/blkdev.c and add SCSI_TYPE_* macros (TYPE_* sounds too generic) to include/blkdev.h with fallbacks for too old /usr/include/scsi/scsi.h files.

...

misc-utils/lsblk.c static char *get_type(struct blkdev_cxt *cxt)

Quoted 10 lines
misc-utils/lsblk.c +10 -0
+static void set_exclusive(int *what, int how)
+{
+	if (*what == ACT_NONE) {
+		*what = how;
+		return;
+	}
+	if (*what == how)
+		return;
+	errx_mutually_exclusive("--{add,delete,show,list,raw,pairs}");
+}

This is good idea, I guess we have the same problem on more places where is the "mutually exclusive" error message.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#3 lore raw

On Mon, Jun 11, 2012 at 11:48 AM, Karel Zak <[email protected]> wrote:

New try available in the git repository at:

git://github.com/kerolasa/lelux-utiliteetit.git 2012wk23

for you to fetch changes up to 1edd8af70b4794c796d0faed0cf763ff3474b92e:

lsblk: use blkdev_scsi_type_to_name() (2012-06-11 22:06:06 +0200)

----------------------------------------------------------------
Sami Kerola (13):
setarch: do not use -1 as array index [cppcheck]
blkid: fix realloc memory leak [cppcheck]
uuidd: use output redirection which works [checkbashisms]
include: fix spurious list.h warnings
build: fix redundant redeclaration warnings
build: fix unused parameter warnings
sysfs: fix printf format warnings
include: fix void pointer arithmetics warnings
docs: clean up partx.8 manual
eject: inform if CD-ROM drive is not ready
wipefs: use symbolic value for markup mode
blkdev: add blkdev_scsi_type_to_name()
lsblk: use blkdev_scsi_type_to_name()

Quoted 11 lines · Sami Kerola
Quoted 10 lines
configure.ac +0 -0
index 2280e7e..13c9637 100644
@@ -80,6 +80,24 @@ AC_CANONICAL_HOST

=A0AC_C_CONST
=A0AC_C_VOLATILE
=A0AC_C_BIGENDIAN
+if test "$cross_compiling" =3D no; then
+ =A0if test "x$ac_cv_prog_cc_c99" =3D "xno" || test "x$ac_cv_prog_cc_c9=

9"

Quoted 3 lines
Quoted 3 lines

=3D "x"; then
+ =A0# We might be on RHEL5 with a git checkout and so broken
+ =A0# autoconf. Check if CC is gcc and if it bails when given -std=3Dgn=

u99.

Quoted 15 lines
Quoted 6 lines

+ =A0# If not, use that. =A0Yuck.
+ =A0 =A0if test "x$ac_cv_c_compiler_gnu" =3D "xyes"; then
+ =A0 =A0 =A0 CC=3D"$CC -std=3Dgnu99"
+ =A0 =A0 =A0 AC_RUN_IFELSE(
+ =A0 =A0 =A0 =A0 =A0[AC_LANG_PROGRAM([],[[
+ =A0return 0;

Quoted 8 lines

+ =A0 =A0 =A0]])],
+ =A0 =A0 =A0[],
+ =A0 =A0 =A0[AC_MSG_ERROR([Could not find a C99 compatible compiler])])
+ =A0 =A0else
+ =A0 =A0 =A0AC_MSG_ERROR([Could not find a C99 compatible compiler])
+ =A0 =A0fi
+ =A0fi
+fi

Quoted 2 lines

=A0AC_PROG_CC_C99 sounds really like a better solution, although I have =A0autoconf 2.68 on Fedora 16 :-(

I will leave the C99 update to someone who has better insight how not to shoot oneself to foot. In other words dropped from the most recent pull request.

Quoted 6 lines
Quoted 6 lines
misc-utils/blkid.c +0 -0
@@ -365,8 +365,10 @@ static int append_str(char **res, size_t *sz,
 const char *a, const char *b)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -1;
 
Quoted 6 lines

misc-utils/blkid.c static int append_str(char **res, size_t *sz, · line 370

Quoted 4 lines
misc-utils/blkid.c +2 -1
 =A0 =A0 =A0 str =3D realloc(str, len + 1);
- =A0 =A0 if (!str)
+ =A0 =A0 if (!str) {
+ =A0 =A0 =A0 =A0 =A0 =A0 free(res);

=A0 =A0 =A0 =A0free(*res);

This is fixed.

Quoted 6 lines
Quoted 6 lines
misc-utils/lsblk.c +0 -0
index 9e894ef..f9e05b6 100644
@@ -527,6 +527,12 @@ static char *get_type(struct blkdev_cxt *cxt)

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 type =3D "mo=

-disk"; break;

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 case 0x0e: /* TYPE_RBC */ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 type =3D "rb=

c"; break;

Quoted 2 lines
Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 default:
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Perhaps inc=

lude/scsi/scsi.h in

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* kernel gi=

t section 'DEVICE TYPES'

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* will know=

what was found. =A0*/

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sprintf(type, =

"0x%02x", x);

Quoted 5 lines
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;

=A0What about to add scsi_type_to_name() to lib/blkdev.c and add =A0SCSI_TYPE_* macros (TYPE_* sounds too generic) to include/blkdev.h =A0with fallbacks for too old /usr/include/scsi/scsi.h files.

I like this. Have a look of the second last patch which will add function to blkdev. Perhaps it reassembles to some extent what you where thinking of.

Quoted 5 lines
Quoted 5 lines
misc-utils/lsblk.c +5 -0
+static void set_exclusive(int *what, int how)
+{
+ =A0 =A0 if (*what =3D=3D ACT_NONE) {
+ =A0 =A0 =A0 =A0 =A0 =A0 *what =3D how;
+ =A0 =A0 =A0 =A0 =A0 =A0 return;
Quoted 8 lines
Quoted 5 lines

+ =A0 =A0 }
+ =A0 =A0 if (*what =3D=3D how)
+ =A0 =A0 =A0 =A0 =A0 =A0 return;
+ =A0 =A0 errx_mutually_exclusive("--{add,delete,show,list,raw,pairs}"); +}

=A0This is good idea, I guess we have the same problem on more places =A0where is the "mutually exclusive" error message.

With quick search I found the following files having some sort of option exclusiveness going on. I do not like to add that many changes to a branch which already has +10 patches, so I dropped the patch for now. The fix will be included to branch for the ongoing week, which hopefully has unified way to deal all of the exclusive options.

hwclock/hwclock.c
misc-utils/blkid.c
misc-utils/findmnt.c
misc-utils/lsblk.c
partx/partx.c
sys-utils/losetup.c
sys-utils/lscpu.c
sys-utils/mount.c
sys-utils/prlimit.c
sys-utils/wdctl.c

--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/

maintainer Applied
#4 lore raw
Quoted 6 lines · Sami Kerola

Sami Kerola (13):
setarch: do not use -1 as array index [cppcheck]
blkid: fix realloc memory leak [cppcheck]
uuidd: use output redirection which works [checkbashisms]
include: fix spurious list.h warnings
build: fix redundant redeclaration warnings

Quoted 8 lines

build: fix unused parameter warnings
sysfs: fix printf format warnings
include: fix void pointer arithmetics warnings
docs: clean up partx.8 manual
eject: inform if CD-ROM drive is not ready
wipefs: use symbolic value for markup mode
blkdev: add blkdev_scsi_type_to_name()
lsblk: use blkdev_scsi_type_to_name()

Merged, thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#5 lore raw
Quoted 3 lines · Karel Zak
Quoted 2 lines · Sami Kerola

blkdev: add blkdev_scsi_type_to_name()
lsblk: use blkdev_scsi_type_to_name()

I have modified this code. It seems better to return static strings from blkdev_scsi_type_to_name() (Please, don't use xalloc.h stuff in lib/ as we use the functions from lib/ in shared libraries.)

It seems better to have fallbacks for unknown SCSI types in applications (for example lsblk uses "part" or "disk").

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#6 lore raw
In reply to Karel Zak

D'ar lun 11 a viz Mezheven 2012 e 11 eur 48, « Karel Zak » he deus skrivet :

Quoted 23 lines · Sami Kerola
Quoted 22 lines
configure.ac +2 -0
index 2280e7e..13c9637 100644
@@ -80,6 +80,24 @@ AC_CANONICAL_HOST
 AC_C_CONST
 AC_C_VOLATILE
 AC_C_BIGENDIAN
+if test "$cross_compiling" = no; then
+  if test "x$ac_cv_prog_cc_c99" = "xno" || test "x$ac_cv_prog_cc_c99"

= "x"; then

configure.ac +11 -0
+  # We might be on RHEL5 with a git checkout and so broken
+  # autoconf. Check if CC is gcc and if it bails when given -std=gnu99.
+  # If not, use that.  Yuck.
+    if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
+       CC="$CC -std=gnu99"
+       AC_RUN_IFELSE(
+          [AC_LANG_PROGRAM([],[[
+  return 0;
+      ]])],
+      [],
+      [AC_MSG_ERROR([Could not find a C99 compatible compiler])])
Quoted 8 lines

configure.ac

Quoted 5 lines
configure.ac +5 -0
+    else
+      AC_MSG_ERROR([Could not find a C99 compatible compiler])
+    fi
+  fi
+fi

AC_PROG_CC_C99 sounds really like a better solution, although I have autoconf 2.68 on Fedora 16 :-(

This is also present in autoconf-2.68 (lib/autoconf/c.m4:1360)

Signature · 1 line
Beber
maintainer
#7 lore raw
Quoted 17 lines · Bertrand Jacquin

# We might be on RHEL5 with a git checkout and so broken

Quoted 16 lines
Quoted 15 lines
(quoted diff) +15 -0
+  # autoconf. Check if CC is gcc and if it bails when given -std=gnu99.
+  # If not, use that.  Yuck.
+    if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
+       CC="$CC -std=gnu99"
+       AC_RUN_IFELSE(
+          [AC_LANG_PROGRAM([],[[
+  return 0;
+      ]])],
+      [],
+      [AC_MSG_ERROR([Could not find a C99 compatible compiler])])
+    else
+      AC_MSG_ERROR([Could not find a C99 compatible compiler])
+    fi
+  fi
+fi
Quoted 4 lines
Quoted 2 lines

AC_PROG_CC_C99 sounds really like a better solution, although I have autoconf 2.68 on Fedora 16 :-(

This is also present in autoconf-2.68 (lib/autoconf/c.m4:1360)

It seems that AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60.

Anyway -- according to gnulib autoconf stuff -- there is an issue when AC_PROG_CC_C99 used together with AC_PROG_CC_STDC. For more details see gl_PROG_CC_C99 macro in coreutils or gnulib.

I think we can exist without AC_PROG_CC_C99 for now, it seems better to explicitly enable some gcc warnings by UL_ADD_WARN() than add special workaround for AC_PROG_CC_C99, etc.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com