public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [pull] chkdupexe, a bug, version numbers and bashisms
@ 2012-03-20 19:27 Sami Kerola
  2012-03-30 15:04 ` Karel Zak
  0 siblings, 1 reply; 13+ messages in thread
From: Sami Kerola @ 2012-03-20 19:27 UTC (permalink / raw)
  To: util-linux

Hi,

This pull has couple patches which are worth while to mention.

The first patch reimplements chkdupexe in C.  Whole point of doing
that is to get rid of dependency to perl, as there where nothing else
that needed it.  It is questionable if this version is good enough.
If not perhaps others can chip in get the command better or more
useful.

The setterm patch fixes a bug, which is almost year old
faa0548de47df5691cf56dd49daaba8dbc89d34a and part of couple release.
Sorry.

First of the pg patches changes version number from old cvs(?) line
to config.h version.  I wonder if the G.  Ritter's copyright year
mark up be updated as well?

Finally I started to check shell scripts with checkbashisms.  IMHO
making POSIX bourne shell compliant makes sense, as one cannot know
if /bin/sh is dash (Debian Almquist shell) on some systems.  In best
case the /bin/sh really is dash, and these patches make scripts run
slightly quicker.


The following changes since commit 9895daca9cb9611b6565434d29619f0d28ea9e81:

  fsck: tiny coding style fix (2012-03-20 11:22:09 +0100)

are available in the git repository at:

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

for you to fetch changes up to 34337b125ddfa961ccc001dd51c5fb076ff7202a:

  tools: ko-release: make scripts bourne sh compliant [checkbashisms]
(2012-03-20 20:24:42 +0100)

----------------------------------------------------------------
Sami Kerola (31):
      chkdupexe: reimplement command in C
      mountpoint: add --version & align with howto-usage-function.txt
      findmnt: add --version & align with howto-usage-function.txt
      findfs: add --version & align with howto-usage-function.txt
      setterm: correct manual page reference
      partx: add --version option
      addpart: align with util-linux coding standards
      delpart: align with util-linux coding standards
      raw: align with howto-usage-function.txt
      raw: add long options and version printing
      raw: use symbolic exit numbers
      raw: use libc error printing facilities
      raw: use pathnames.h for file locations
      raw: check numeric user inputs
      raw: clean up coding style
      pg: correct version printing in help screen
      pg: align with howto-usage-function.txt
      fsck.cramfs: add long options
      fsck.minix: use symbolic exit codes
      fsck.minix: use rpmatch() for yes/no question
      fsck.minix: align with howto-usage-function.txt
      fsck.minix: clean up coding style
      fsck.minix: fix printf format warning
      swaplabel: add --version and align with howto-usage-function.txt
      fallocate: add --version and align with howto-usage-function.txt
      findmnt: remove dublicate usage() line
      fstrim: add --version and align with howto-usage-function.txt
      reset: make scripts bourne sh compliant [checkbashisms]
      tools: checkconfig.sh: make scripts bourne sh compliant [checkbashisms]
      tools: config-gen: make scripts bourne sh compliant [checkbashisms]
      tools: ko-release: make scripts bourne sh compliant [checkbashisms]

 configure.ac                  |    4 -
 disk-utils/fsck.cramfs.c      |   32 +-
 disk-utils/fsck.minix.c       |  781 ++++++++++++++++++++---------------------
 disk-utils/raw.c              |  266 +++++++-------
 disk-utils/swaplabel.c        |   26 +-
 include/pathnames.h           |    9 +
 misc-utils/Makefile.am        |    6 +-
 misc-utils/chkdupexe.1        |   43 ++-
 misc-utils/chkdupexe.c        |  307 ++++++++++++++++
 misc-utils/chkdupexe.pl       |  120 -------
 misc-utils/findfs.c           |   23 +-
 misc-utils/findmnt.c          |   17 +-
 partx/Makefile.am             |    2 +
 partx/addpart.c               |   78 ++--
 partx/delpart.c               |   73 ++--
 partx/partx.c                 |    6 +-
 sys-utils/fallocate.c         |   21 +-
 sys-utils/fstrim.c            |   21 +-
 sys-utils/mountpoint.c        |   19 +-
 term-utils/reset              |    6 +-
 term-utils/reset.033c         |    2 +-
 term-utils/setterm.c          |    2 +-
 text-utils/pg.c               |   45 ++-
 tools/checkconfig.sh          |    6 +-
 tools/config-gen              |    5 +-
 tools/config-gen-functions.sh |    2 +-
 tools/ko-release-gen          |    8 +-
 tools/ko-release-push         |    2 +-
 28 files changed, 1143 insertions(+), 789 deletions(-)
 create mode 100644 misc-utils/chkdupexe.c
 delete mode 100755 misc-utils/chkdupexe.pl
 mode change 100644 => 100755 term-utils/reset

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [pull] chkdupexe, a bug, version numbers and bashisms
  2012-03-20 19:27 [pull] chkdupexe, a bug, version numbers and bashisms Sami Kerola
@ 2012-03-30 15:04 ` Karel Zak
  2012-04-01 18:19   ` Sami Kerola
  0 siblings, 1 reply; 13+ messages in thread
From: Karel Zak @ 2012-03-30 15:04 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux


 Merged, but

On Tue, Mar 20, 2012 at 08:27:01PM +0100, Sami Kerola wrote:
> Sami Kerola (31):
>       chkdupexe: reimplement command in C

please, send the new chkdupexe to mailing list for review.

>       addpart: align with util-linux coding standards
>       delpart: align with util-linux coding standards

Fixed...

         if ((fd = open(argv[1], O_RDONLY)) < 0)
                err(EXIT_FAILURE, "%s", argv[1]);
         ...
         err(EXIT_FAILURE, "BLKPG");

"%s", "BLKPG" are not usable error messages.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [pull] chkdupexe, a bug, version numbers and bashisms
  2012-03-30 15:04 ` Karel Zak
@ 2012-04-01 18:19   ` Sami Kerola
  2012-04-01 18:19     ` [PATCH 1/3] tests: hwclock: locate ntpdate by using path Sami Kerola
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Sami Kerola @ 2012-04-01 18:19 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

On Fri, Mar 30, 2012 at 17:04, Karel Zak <kzak@redhat.com> wrote:
>
>  Merged, but

Thank you for merge and message clarifications.

> On Tue, Mar 20, 2012 at 08:27:01PM +0100, Sami Kerola wrote:
>> Sami Kerola (31):
>>       chkdupexe: reimplement command in C
>
> please, send the new chkdupexe to mailing list for review.

Sound fair.  The incoming chkdupexe, and other two small fixes, are
also available in the git repository at:

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

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/3] tests: hwclock: locate ntpdate by using path
  2012-04-01 18:19   ` Sami Kerola
@ 2012-04-01 18:19     ` Sami Kerola
  2012-04-02 11:22       ` Karel Zak
  2012-04-01 18:19     ` [PATCH 2/3] script: error in usage() output Sami Kerola
  2012-04-01 18:19     ` [PATCH 3/3] chkdupexe: reimplement command in C Sami Kerola
  2 siblings, 1 reply; 13+ messages in thread
From: Sami Kerola @ 2012-04-01 18:19 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 tests/ts/hwclock/systohc |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/ts/hwclock/systohc b/tests/ts/hwclock/systohc
index f58d07e..401ee93 100755
--- a/tests/ts/hwclock/systohc
+++ b/tests/ts/hwclock/systohc
@@ -24,7 +24,8 @@ NTP_SERVER="0.fedora.pool.ntp.org"
 ts_init "$*"
 ts_skip_nonroot
 
-[ -x "/usr/sbin/ntpdate" ] || ts_skip "cannot find ntpdate command"
+PATH='/usr/sbin:/usr/bin:/sbin:/bin'
+type ntpdate >/dev/null 2>&1 || ts_skip "cannot find ntpdate command"
 
 set -o pipefail
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/3] script: error in usage() output
  2012-04-01 18:19   ` Sami Kerola
  2012-04-01 18:19     ` [PATCH 1/3] tests: hwclock: locate ntpdate by using path Sami Kerola
@ 2012-04-01 18:19     ` Sami Kerola
  2012-04-02 11:27       ` Karel Zak
  2012-04-01 18:19     ` [PATCH 3/3] chkdupexe: reimplement command in C Sami Kerola
  2 siblings, 1 reply; 13+ messages in thread
From: Sami Kerola @ 2012-04-01 18:19 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Error originates to commit 3ff526391fb5c6b33418dc9cfec31c2ff9b4792e
which is bit more than year, and part or releases v2.20 & v2.21.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/script.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 0d891b8..effedac 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -133,7 +133,7 @@ usage(FILE *out)
 	fputs(_("\nOptions:\n"), out);
 	fputs(_(" -a, --append            append the output\n"
 		" -c, --command <command> run command rather than interactive shell\n"
-		" -r, --return            return exit code of the child process\n"
+		" -e, --return            return exit code of the child process\n"
 		" -f, --flush             run flush after each write\n"
 		"     --force             use output file even when it is a link\n"
 		" -q, --quiet             be quiet\n"
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/3] chkdupexe: reimplement command in C
  2012-04-01 18:19   ` Sami Kerola
  2012-04-01 18:19     ` [PATCH 1/3] tests: hwclock: locate ntpdate by using path Sami Kerola
  2012-04-01 18:19     ` [PATCH 2/3] script: error in usage() output Sami Kerola
@ 2012-04-01 18:19     ` Sami Kerola
  2012-04-02 11:10       ` Karel Zak
  2 siblings, 1 reply; 13+ messages in thread
From: Sami Kerola @ 2012-04-01 18:19 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The new version of the command is nearly identical to old.  Major
differences are:

* New output is a little rough what comes to alignment.  This is
  flagged as FIXME item in source.
* The command is much quicker than perl implementation which used
  to exec ls -ldU.
* Size of chkdupexe binary is about five times bigger than perl
  script.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 configure.ac            |    4 -
 include/pathnames.h     |    2 +
 misc-utils/Makefile.am  |    6 +-
 misc-utils/chkdupexe.1  |   43 ++++++-
 misc-utils/chkdupexe.c  |  307 +++++++++++++++++++++++++++++++++++++++++++++++
 misc-utils/chkdupexe.pl |  120 ------------------
 6 files changed, 351 insertions(+), 131 deletions(-)
 create mode 100644 misc-utils/chkdupexe.c
 delete mode 100755 misc-utils/chkdupexe.pl

diff --git a/configure.ac b/configure.ac
index 2140bc5..2abf214 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,9 +114,6 @@ UL_SET_ARCH(M68K, m68*)
 UL_SET_ARCH(MIPS, mips*)
 UL_SET_ARCH(HPPA, hppa*)
 
-dnl script chkdupexe requires perl
-AC_PATH_PROG(PERL, perl)
-
 AC_SYS_LARGEFILE
 
 AM_GNU_GETTEXT_VERSION([0.14.1])
@@ -1223,7 +1220,6 @@ libuuid/uuid.pc
 login-utils/Makefile
 man/ru/Makefile
 misc-utils/Makefile
-misc-utils/chkdupexe:misc-utils/chkdupexe.pl
 mount/Makefile
 partx/Makefile
 po/Makefile.in
diff --git a/include/pathnames.h b/include/pathnames.h
index 299d922..a3d05ec 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -25,6 +25,8 @@
 #undef _PATH_DEFPATH_ROOT
 #define	_PATH_DEFPATH_ROOT	"/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
 
+#define _PATH_CHKDUPEXE		"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11/bin:/usr/bin/X11:/usr/local/X11/bin:/usr/TeX/bin:/usr/tex/bin:/usr/games:/usr/local/games"
+
 #define _PATH_SECURETTY		"/etc/securetty"
 #define _PATH_WTMPLOCK		"/etc/wtmplock"
 
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am
index acf2c9d..200b1da 100644
--- a/misc-utils/Makefile.am
+++ b/misc-utils/Makefile.am
@@ -8,19 +8,17 @@ usrsbin_exec_PROGRAMS =
 
 usrbin_exec_PROGRAMS = \
 	cal \
+	chkdupexe \
 	logger \
 	look \
 	mcookie \
 	namei \
 	whereis
 
+chkdupexe_SOURCES = chkdupexe.c $(top_srcdir)/lib/strutils.c
 logger_SOURCES = logger.c $(top_srcdir)/lib/strutils.c
 mcookie_SOURCES = mcookie.c $(top_srcdir)/lib/md5.c
 
-usrbin_exec_SCRIPTS = chkdupexe
-
-CLEANFILES = chkdupexe
-
 dist_man_MANS = \
 	cal.1 \
 	chkdupexe.1 \
diff --git a/misc-utils/chkdupexe.1 b/misc-utils/chkdupexe.1
index dd3664a..dc2ffb7 100644
--- a/misc-utils/chkdupexe.1
+++ b/misc-utils/chkdupexe.1
@@ -2,6 +2,7 @@
 .\" Created: Sat Mar 11 18:19:44 1995 by faith@cs.unc.edu
 .\" Revised: Sat Mar 11 19:07:05 1995 by faith@cs.unc.edu
 .\" Revised: Wed Jul  5 01:56:26 1995 by shields@tembel.org
+.\" Revised: Wed Mar 14 21:08:59 2012 by kerolasa@iki.fi
 .\" Copyright 1995 Rickard E. Faith (faith@cs.unc.edu)
 .\" 
 .\" Permission is granted to make and distribute verbatim copies of this
@@ -24,15 +25,51 @@
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
 .\" 
-.TH CHKDUPEXE 1 "March 1995" "util-linux" "User Commands"
+.TH CHKDUPEXE 1 "March 2012" "util-linux" "User Commands"
 .SH NAME
 chkdupexe \- find duplicate executables
 .SH SYNOPSIS
 .B chkdupexe
+[options]
 .SH DESCRIPTION
 .B chkdupexe
 will scan the union of $PATH and a hardcoded list of common locations
 for binaries.  It will report dangling symlinks and duplicately-named
 binaries.
-.SH AUTHOR
-Nicolai Langfeldt, Michael Shields.
+.SH OPTIONS
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help and exit.
+.SH NOTES
+.IP "The hardcoded locations directories are:" 7
+.br
+/bin
+.br
+/sbin
+.br
+/usr/bin
+.br
+/usr/sbin
+.br
+/usr/local/bin
+.br
+/usr/local/sbin
+.br
+/usr/X11/bin
+.br
+/usr/bin/X11
+.br
+/usr/local/X11/bin
+.br
+/usr/TeX/bin
+.br
+/usr/tex/bin
+.br
+/usr/games
+.br
+/usr/local/games
+.SH AUTHORS
+Nicolai Langfeldt, Michael Shields, Sami Kerola.
diff --git a/misc-utils/chkdupexe.c b/misc-utils/chkdupexe.c
new file mode 100644
index 0000000..9dca5e4
--- /dev/null
+++ b/misc-utils/chkdupexe.c
@@ -0,0 +1,307 @@
+/* chkdupexe - find duplicate executables
+ * Copyright 2012 Sami Kerola <kerolasa@iki.fi>
+ *
+ * This is replacement of chkdupexe.pl.  The following persons where
+ * listed as developers of the perl version of the command.
+ *
+ * Copyright 1993 Nicolai Langfeldt. janl@math.uio.no
+ * Modified 1995-07-04 Michael Shields <shields@tembel.org>
+ * Modified 1996-02-16 Nicolai Langfeldt (janl@math.uio.no)
+ *
+ * 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 the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <assert.h>
+#include <dirent.h>
+#include <getopt.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "c.h"
+#include "nls.h"
+#include "pathnames.h"
+#include "strutils.h"
+#include "xalloc.h"
+
+#define INIT_EXEC_NRO 1024
+
+struct search_paths {
+	char *dir;
+	struct search_paths *next;
+};
+struct execs {
+	struct search_paths *path;
+	char *file;
+};
+
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
+{
+	fprintf(out, USAGE_HEADER);
+	fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
+	fprintf(out, USAGE_OPTIONS);
+	fprintf(out, USAGE_HELP);
+	fprintf(out, USAGE_VERSION);
+	fprintf(out, USAGE_MAN_TAIL("chkdupexe(1)"));
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+static struct dirent *xreaddir(DIR * dp)
+{
+	struct dirent *d;
+	assert(dp);
+	while ((d = readdir(dp))) {
+		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+			continue;
+		/* blacklist here? */
+		break;
+	}
+	return d;
+}
+
+static int is_uniq_path(struct search_paths *sp, char *needle)
+{
+	struct search_paths *browse;
+	for (browse = sp; browse->next != NULL; browse = browse->next)
+		if (strcmp(browse->dir, needle) == 0)
+			return 0;
+	return 1;
+}
+
+struct search_paths *add_paths(struct search_paths *sp,
+			       struct search_paths *sp_continue, char *ent)
+{
+	struct search_paths *fill;
+	char *colon;
+
+	if (sp_continue != NULL)
+		fill = sp_continue;
+	else
+		fill = sp;
+	while ((colon = strchr(ent, ':')) != NULL) {
+		*colon = '\0';
+		if (is_uniq_path(sp, ent)) {
+			fill->dir = xstrdup(ent);
+			fill->next = xmalloc(sizeof(struct search_paths));
+			fill = fill->next;
+			fill->next = NULL;
+			fill->dir = NULL;
+		}
+		ent = colon + 1;
+	}
+	return fill;
+}
+
+static void create_paths(struct search_paths *sp)
+{
+	char *ent;
+	struct search_paths *sp_continue = sp;
+
+	ent = getenv("PATH");
+	if (ent != NULL) {
+		ent = xstrdup(ent);
+		sp_continue = add_paths(sp, NULL, ent);
+		free(ent);
+	}
+	ent = xstrdup(_PATH_CHKDUPEXE);
+	add_paths(sp, sp_continue, ent);
+	free(ent);
+	return;
+}
+
+static unsigned long browse_path(struct search_paths *sp,
+				 struct execs ***orig_el)
+{
+	struct search_paths *sp_next;
+	DIR *dir;
+	struct dirent *d;
+	struct execs **el = *orig_el;
+	unsigned long nel = 0, allocated = INIT_EXEC_NRO;
+
+	for (sp_next = sp; sp_next->next != NULL; sp_next = sp_next->next) {
+		dir = opendir(sp_next->dir);
+		while (dir != NULL && (d = xreaddir(dir))) {
+			if (d->d_type == DT_LNK) {
+				struct stat statbuf;
+				int s;
+				char *fp;
+				xasprintf(&fp, "%s/%s", sp_next->dir, d->d_name);
+				s = stat(fp, &statbuf);
+				if (s < 0)
+					printf(_("Dangling symlink: %s\n"), fp);
+				free(fp);
+			}
+			if (d->d_type == DT_REG) {
+				el[nel] = xmalloc(sizeof(struct execs));
+				el[nel]->path = sp_next;
+				el[nel]->file = xstrdup(d->d_name);
+				nel++;
+				if (allocated < nel) {
+					allocated *= 2;
+					el = xrealloc(el,
+						      (sizeof(struct execs *)
+						       * allocated));
+				}
+			}
+		}
+		closedir(dir);
+	}
+	*orig_el = el;
+	return nel;
+}
+
+static int exec_name_cmp(const void *restrict x, const void *restrict y)
+{
+	struct execs *a = *(struct execs * const *)x;
+	struct execs *b = *(struct execs * const *)y;
+	return strcmp(a->file, b->file);
+}
+
+static int found_ent(struct execs *a)
+{
+	/* FIXME: this function should probably use lib/tt.c */
+	char *ap;
+	struct stat as;
+	int ret;
+	char md[11];
+	struct passwd *login;
+	struct group *group;
+	/* lenght ds[13] usually works, but there is hu_HU locale
+	 * which has 4 letters in month abbreviation, so better to
+	 * have few chars extra. */
+	char ds[17];
+	struct timeval now;
+	time_t then, curtime;
+	struct tm *tm;
+
+	gettimeofday(&now, NULL);
+	curtime = now.tv_sec;
+	xasprintf(&ap, "%s/%s", a->path->dir, a->file);
+	ret = stat(ap, &as);
+	if (ret < 0) {
+		warn(_("cannot stat file %s"), ap);
+		return -1;
+	}
+	then = as.st_mtime;
+	tm = localtime(&(as.st_mtime));
+	strmode(as.st_mode, md);
+	/* FIXME: use namei uid/gid caching. Add necessary functions
+	 * to to lib.  */
+	login = getpwuid(as.st_uid);
+	group = getgrgid(as.st_gid);
+
+	printf("%s %zu", md, as.st_nlink);
+	if (login != NULL)
+		printf(" %s", login->pw_name);
+	else
+		printf(" %du", as.st_uid);
+	if (group != NULL)
+		printf(" %s", group->gr_name);
+	else
+		printf(" %du", as.st_gid);
+	printf(" %8zu", as.st_size);
+	/* Just like 'ls -l' print time, if file mtime is newer than
+	 * 6 months.  The 6 x 31 is not quite right, but perhaps
+	 * good enough(?) */
+	if ((curtime - (6 * 31 * 24 * 60 * 60)) < then)
+		strftime(ds, sizeof(ds), "%b %e %H:%M", tm);
+	else
+		strftime(ds, sizeof(ds), "%b %e  %Y", tm);
+	printf(" %s %s\n", ds, ap);
+
+	free(ap);
+	return 0;
+}
+
+static void print_dublicates(struct execs **el, unsigned long nel)
+{
+	unsigned long i;
+
+	qsort(el, (size_t) nel, sizeof(struct execs *), exec_name_cmp);
+	for (i = 1; i < nel; i++) {
+		if (strcmp(el[i - 1]->file, el[i]->file) == 0) {
+			if (found_ent(el[i - 1]) == 0)
+				found_ent(el[i]);
+		}
+	}
+	return;
+}
+
+static void cleanup(struct search_paths *sp_orig, struct execs **el,
+		    unsigned long nel)
+{
+	struct search_paths *sp = sp_orig;
+	struct search_paths *prev = NULL;
+	unsigned long i;
+	do {
+		free(sp->dir);
+		if (prev != NULL)
+			free(prev);
+		prev = sp;
+		sp = sp->next;
+	} while (sp != NULL);
+	free(prev);
+	for (i = 0; i < nel; i++) {
+		free(el[i]->file);
+		free(el[i]);
+	}
+	free(el);
+	return;
+}
+
+int main(int argc, char **argv)
+{
+	struct search_paths *sp;
+	struct execs **el;
+	unsigned long nel;
+	int c;
+	static const struct option longopts[] = {
+		{"version", no_argument, NULL, 'V'},
+		{"help", no_argument, NULL, 'h'},
+		{NULL, 0, NULL, 0}
+	};
+
+	setlocale(LC_ALL, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+
+	while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+		switch (c) {
+		case 'V':
+			printf(UTIL_LINUX_VERSION);
+			return EXIT_SUCCESS;
+		case 'h':
+			usage(stdout);
+		default:
+			usage(stderr);
+		}
+
+	sp = xmalloc(sizeof(struct search_paths));
+	sp->dir = NULL;
+	sp->next = NULL;
+	el = xmalloc(sizeof(struct execs *) * INIT_EXEC_NRO);
+
+	create_paths(sp);
+	nel = browse_path(sp, &el);	/* prints dangling symlinks, if detected */
+	print_dublicates(el, nel);
+	cleanup(sp, el, nel);
+
+	return EXIT_SUCCESS;
+}
diff --git a/misc-utils/chkdupexe.pl b/misc-utils/chkdupexe.pl
deleted file mode 100755
index c2c2384..0000000
--- a/misc-utils/chkdupexe.pl
+++ /dev/null
@@ -1,120 +0,0 @@
-#!@PERL@ -w
-#
-# chkdupexe version 2.1.1
-#
-# Simple script to look for and list duplicate executables and dangling
-# symlinks in the system executable directories.
-#
-# Copyright 1993 Nicolai Langfeldt. janl@math.uio.no
-#  Distribute under gnu copyleft (included in perl package) 
-#
-# Modified 1995-07-04 Michael Shields <shields@tembel.org>
-#     Don't depend on GNU ls.
-#     Cleanups.
-#     Merge together $ENV{'PATH'} and $execdirs.
-#     Don't break if there are duplicates in $PATH.
-#
-# Modified 1996-02-16 Nicolai Langfeldt (janl@math.uio.no).
-#     I was thinking admins would edit the $execdirs list to suit their
-#     machine(s) when I wrote this.  This is ofcourse not the case, thus
-#     Michaels fixes.  And my fixes to his :-)
-#     - Working duplicate dirs detection.
-#     - Added more checks
-#     - Took out $PATH from the list of checked directories and added a
-#	check for $execdirs and $PATH consistency instead
-#     - Made it possible to run with perl -w
-
-$execdirs='/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin '.
-  '/usr/X11/bin /usr/bin/X11 /usr/local/X11/bin '.
-  '/usr/TeX/bin /usr/tex/bin /usr/games '.
-  '/usr/local/games';
-
-# Turn off buffering for the output channel.
-$|=1;
-
-# Values from /usr/include/linux/errno.h.  Existence of linux/errno.ph is not
-# something to count on... :-(
-$ENOENT=2;
-
-%didthis=();
-
-foreach $dir (split(/\s+/, "$execdirs"), "\0", split(/:/, $ENV{PATH})) {
-
-  if ($dir eq "\0") { $checkingpath = 1; next; }
-
-  # It's like this: One directory corresponds to one $device,$inode tuple
-  # If a symlink points to a directory we already checked that directory
-  # will have the same $device,$inode tuple.
-
-  # Does this directory have any real exstence outside the ravings of
-  # symlinks pointing hither and dither?
-  ($device,$inode)=stat($dir); 
-  if (!defined($device)) {
-    # Nonexistant directory, or dangling symlink?
-    ($dum)=lstat($dir);
-    next if $! == $ENOENT;
-    if (!$dum) {
-      print "Dangling symlink: $dir\n";
-      next;
-    }
-    warn "Nonexistent directory: $dir\n" if ($checkingpath);
-    next;
-  }
-
-  if (!-d _) {
-    print "Not a directory: $dir\n";
-    next;
-  }
-
-  next if defined($didthis{$device,$inode});
-
-  $didthis{$device,$inode}=1;
-
-  chdir($dir) || die "Could not chdir $dir: $!\n";
-# This would give us the true directory name, do we want that?
-#  chop($dir=`pwd`);
-  opendir(DIR,".") || 
-    die "NUTS! Personaly I think your perl or filesystem is broken.\n".
-      "I've done all sorts of checks on $dir, and now I can't open it!\n";
-  foreach $_ (readdir(DIR)) {
-    lstat($_);
-    if (-l _) {
-      ($dum)=stat($_);
-      print "Dangling symlink: $dir/$_\n" unless defined($dum);
-      next;
-    }
-    next unless -f _ && -x _;	# Only handle regular executable files
-    if (defined($count{$_})) {
-      $progs{$_}.=" $dir/$_";
-      $count{$_}++;
-    } else {
-      $progs{$_}="$dir/$_";
-      $count{$_}=1;
-    }
-  }
-  closedir(DIR);
-}
-
-open(LS,"| xargs -r ls -ldU");
-while (($prog,$paths)=each %progs) {
-  print LS "$paths\n" if ($count{$prog}>1);
-}
-close(LS);
-
-exit 0;
-
-@unchecked=();
-# Check if the users PATH contains something I've not checked. The site admin
-# might want to know about inconsistencies in user PATHs and chkdupexec 
-# configuration
-foreach $dir (split(/:/,$ENV{'PATH'})) {
-  ($device,$inode)=stat($dir);
-  next unless defined($device);
-  next if defined($didthis{$device,$inode});
-  push(@unchecked,$dir);
-  $didthis{$device,$inode}=1;
-}
-
-print "Warning: Your path contains these directories which chkdupexe has not checked:\n",join(',',@unchecked),
-  ".\nPlease review the execdirs list in chkdupexe.\n"
-    if ($#unchecked>=$[);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] chkdupexe: reimplement command in C
  2012-04-01 18:19     ` [PATCH 3/3] chkdupexe: reimplement command in C Sami Kerola
@ 2012-04-02 11:10       ` Karel Zak
  2012-04-02 11:53         ` Sami Kerola
  2012-04-02 12:22         ` Pádraig Brady
  0 siblings, 2 replies; 13+ messages in thread
From: Karel Zak @ 2012-04-02 11:10 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux, Pádraig Brady

On Sun, Apr 01, 2012 at 08:19:32PM +0200, Sami Kerola wrote:
> The new version of the command is nearly identical to old.  Major
> differences are:
> 
> * New output is a little rough what comes to alignment.  This is
>   flagged as FIXME item in source.
> * The command is much quicker than perl implementation which used
>   to exec ls -ldU.
> * Size of chkdupexe binary is about five times bigger than perl
>   script.

I have doubts about chkdupexe, do we really need this command?

 * it provides very rarely used functionality (for example nobody
   complains that the command is missing in Fedora/RHEL ;-)

 * it seems that you can replace it by

    ls $(echo "$PATH" | tr : ' ') | sort | uniq -d

   or we can extend which(1) or so...


 I see two possible ways:

 1) mark chkdupexe as deprecated and remove it from distros

 2) or add new command (lspath ?) and get much more information from
 $PATH (like duplicates, per-directory stats, per-owner stats,
 per-device stats, selinux summary, suids, etc.) and make chkdupexe as
 alias to the new command (just for backward compatibility).

 If 2) makes sense then it would be better to have it in coreutils ;-)


 CC: Padraig

 ... let's flame :-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] tests: hwclock: locate ntpdate by using path
  2012-04-01 18:19     ` [PATCH 1/3] tests: hwclock: locate ntpdate by using path Sami Kerola
@ 2012-04-02 11:22       ` Karel Zak
  0 siblings, 0 replies; 13+ messages in thread
From: Karel Zak @ 2012-04-02 11:22 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Apr 01, 2012 at 08:19:30PM +0200, Sami Kerola wrote:
>  tests/ts/hwclock/systohc |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] script: error in usage() output
  2012-04-01 18:19     ` [PATCH 2/3] script: error in usage() output Sami Kerola
@ 2012-04-02 11:27       ` Karel Zak
  0 siblings, 0 replies; 13+ messages in thread
From: Karel Zak @ 2012-04-02 11:27 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Apr 01, 2012 at 08:19:31PM +0200, Sami Kerola wrote:
> Error originates to commit 3ff526391fb5c6b33418dc9cfec31c2ff9b4792e
> which is bit more than year, and part or releases v2.20 & v2.21.

Wouldn't be possible to write a tools/checkusage script to check
long_options[] and getopt_long() with usage() ?

>  term-utils/script.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] chkdupexe: reimplement command in C
  2012-04-02 11:10       ` Karel Zak
@ 2012-04-02 11:53         ` Sami Kerola
  2012-04-02 12:12           ` Karel Zak
  2012-04-04 10:24           ` Karel Zak
  2012-04-02 12:22         ` Pádraig Brady
  1 sibling, 2 replies; 13+ messages in thread
From: Sami Kerola @ 2012-04-02 11:53 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Pádraig Brady

On Mon, Apr 2, 2012 at 13:10, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Apr 01, 2012 at 08:19:32PM +0200, Sami Kerola wrote:
>> The new version of the command is nearly identical to old.  Major
>> differences are:
>>
>> * New output is a little rough what comes to alignment.  This is
>>   flagged as FIXME item in source.
>> * The command is much quicker than perl implementation which used
>>   to exec ls -ldU.
>> * Size of chkdupexe binary is about five times bigger than perl
>>   script.
>
> I have doubts about chkdupexe, do we really need this command?
>
>  * it provides very rarely used functionality (for example nobody
>   complains that the command is missing in Fedora/RHEL ;-)
>
>  * it seems that you can replace it by
>
>    ls $(echo "$PATH" | tr : ' ') | sort | uniq -d
>
>   or we can extend which(1) or so...
>
>
>  I see two possible ways:
>
>  1) mark chkdupexe as deprecated and remove it from distros
>
>  2) or add new command (lspath ?) and get much more information from
>  $PATH (like duplicates, per-directory stats, per-owner stats,
>  per-device stats, selinux summary, suids, etc.) and make chkdupexe as
>  alias to the new command (just for backward compatibility).
>
>  If 2) makes sense then it would be better to have it in coreutils ;-)
>
>
>  CC: Padraig
>
>  ... let's flame :-)

I am in favour of removal. As you said few, if anyone, is using this
command and to be honest I do not know why I would use it. Duplicated
commands in path are more likely to be intentional than interesting.
Perhaps extended 'lspath' might be more useful, but again I'm
struggling to come up with real use case, and the fact that existing
tools allow quite easily do similar things. For example find suid bit
executables.

find $(echo $PATH | tr ':' ' ') -mindepth 1 -maxdepth 1  -perm -u+s

Besides isn't the path polluted enough with all sort of legacy things?
Shouldn't removing of crud be considered virtue?

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] chkdupexe: reimplement command in C
  2012-04-02 11:53         ` Sami Kerola
@ 2012-04-02 12:12           ` Karel Zak
  2012-04-04 10:24           ` Karel Zak
  1 sibling, 0 replies; 13+ messages in thread
From: Karel Zak @ 2012-04-02 12:12 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux, Pádraig Brady

On Mon, Apr 02, 2012 at 01:53:23PM +0200, Sami Kerola wrote:
> I am in favour of removal. As you said few, if anyone, is using this
> command and to be honest I do not know why I would use it. Duplicated

I agree ... so, we need --enable-chkdupexe (disabled by default)
and Documentation/deprecated.txt entry ;-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] chkdupexe: reimplement command in C
  2012-04-02 11:10       ` Karel Zak
  2012-04-02 11:53         ` Sami Kerola
@ 2012-04-02 12:22         ` Pádraig Brady
  1 sibling, 0 replies; 13+ messages in thread
From: Pádraig Brady @ 2012-04-02 12:22 UTC (permalink / raw)
  To: Karel Zak; +Cc: Sami Kerola, util-linux

On 04/02/2012 12:10 PM, Karel Zak wrote:
> On Sun, Apr 01, 2012 at 08:19:32PM +0200, Sami Kerola wrote:
>> The new version of the command is nearly identical to old.  Major
>> differences are:
>>
>> * New output is a little rough what comes to alignment.  This is
>>   flagged as FIXME item in source.
>> * The command is much quicker than perl implementation which used
>>   to exec ls -ldU.
>> * Size of chkdupexe binary is about five times bigger than perl
>>   script.
> 
> I have doubts about chkdupexe, do we really need this command?
> 
>  * it provides very rarely used functionality (for example nobody
>    complains that the command is missing in Fedora/RHEL ;-)
> 
>  * it seems that you can replace it by
> 
>     ls $(echo "$PATH" | tr : ' ') | sort | uniq -d
> 
>    or we can extend which(1) or so...
> 
> 
>  I see two possible ways:
> 
>  1) mark chkdupexe as deprecated and remove it from distros

I notice it's no longer on my Fedora 15 distro at least.

>  2) or add new command (lspath ?) and get much more information from
>  $PATH (like duplicates, per-directory stats, per-owner stats,
>  per-device stats, selinux summary, suids, etc.) and make chkdupexe as
>  alias to the new command (just for backward compatibility).

Possible but unlikely

>  If 2) makes sense then it would be better to have it in coreutils ;-)

I'd vote for 1.
Note I actually wrote a very similar tool as part of fslint, called findsn.
It has different modes of operation, but the default is the same as chkdupexe.

$ ~/git/util-linux/misc-utils/chkdupexe.pl
Dangling symlink: /usr/bin/openoffice.org
-rwxr-xr-x. 1 root    root    86360 Feb  8  2011 /usr/bin/bc
-rwxrwxr-x. 1 padraig padraig  1767 Apr 11  2007 /home/padraig/bin/bc
-rwxr-xr-x. 1 root    root    50616 Aug 25  2011 /usr/bin/timeout
-rwxrwxr-x. 1 padraig padraig  2141 Oct 29  2009 /home/padraig/bin/timeout
-rwxr-xr-x. 1 root    root    51176 Feb  8  2011 /usr/bin/truncate
-rwxrwxr-x. 1 padraig padraig  1273 Dec 16  2005 /home/padraig/bin/truncate

$ fslint/findsn
-rwxr-xr-x. 1 root    root    86360 Feb  8  2011 /usr/bin/bc
-rwxrwxr-x. 1 padraig padraig  1767 Apr 11  2007 /home/padraig/bin/bc
lrwxrwxrwx. 1 root    root        2 May 13  2011 /bin/ex -> vi
lrwxrwxrwx. 1 root    root        3 May 22  2011 /usr/bin/ex -> vim
-rwxr-xr-x. 1 root    root    50616 Aug 25  2011 /usr/bin/timeout
-rwxrwxr-x. 1 padraig padraig  2141 Oct 29  2009 /home/padraig/bin/timeout
-rwxr-xr-x. 1 root    root    51176 Feb  8  2011 /usr/bin/truncate
-rwxrwxr-x. 1 padraig padraig  1273 Dec 16  2005 /home/padraig/bin/truncate

$ ./fslint/findbl $(fslint/supprt/getffp)
/usr/bin/openoffice.org -> /usr/lib64/libreoffice/program/libreoffice

cheers,
Pádraig.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] chkdupexe: reimplement command in C
  2012-04-02 11:53         ` Sami Kerola
  2012-04-02 12:12           ` Karel Zak
@ 2012-04-04 10:24           ` Karel Zak
  1 sibling, 0 replies; 13+ messages in thread
From: Karel Zak @ 2012-04-04 10:24 UTC (permalink / raw)
  To: kerolasa, Pádraig Brady; +Cc: util-linux, Sami Kerola

On Mon, Apr 02, 2012 at 01:53:23PM +0200, Sami Kerola wrote:
> I am in favour of removal. As you said few, if anyone, is using this

On Mon, Apr 02, 2012 at 01:22:15PM +0100, Pádraig Brady wrote:
> >  1) mark chkdupexe as deprecated and remove it from distros
> 
> I'd vote for 1.

  Done.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-04-04 10:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-20 19:27 [pull] chkdupexe, a bug, version numbers and bashisms Sami Kerola
2012-03-30 15:04 ` Karel Zak
2012-04-01 18:19   ` Sami Kerola
2012-04-01 18:19     ` [PATCH 1/3] tests: hwclock: locate ntpdate by using path Sami Kerola
2012-04-02 11:22       ` Karel Zak
2012-04-01 18:19     ` [PATCH 2/3] script: error in usage() output Sami Kerola
2012-04-02 11:27       ` Karel Zak
2012-04-01 18:19     ` [PATCH 3/3] chkdupexe: reimplement command in C Sami Kerola
2012-04-02 11:10       ` Karel Zak
2012-04-02 11:53         ` Sami Kerola
2012-04-02 12:12           ` Karel Zak
2012-04-04 10:24           ` Karel Zak
2012-04-02 12:22         ` Pádraig Brady

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox