Skip to contentSkip to conversation

pull: various removals and few fixes

PATCH Applied Sami Kerola 2 participants 17 messages Jul 31, 2017 – Aug 7, 2017 Util-Linux package

lore
Share & tools
lore
#0 lore raw

cover pull: various removals and few fixes

Hello,

Here's again rather random bunch of changes. First I thought total lines deleted would exceed lines added, but the agetty --compile-time addition pushed the balance otherway around. Oh well, that was a good try.

Perhaps the nicest change in this series is look(1) bash-completion update that pushes tab completion to make the usability of the command on next level. Assuming you have system word lists installed this is pretty easy to try, '. bash-completion/look ; look zo<tab tab>' and you get list of possibilities from Zoe to zorching. The next level of look(1) improvements should make optional [file] to be consumed from an environment variable, so that bash-completion would play together with user preferred word list. But that's something for next time.

Rest of the changes I assume to be pretty straightforward to review, so hopefully no need for lengthy text about them.

----------------------------------------------------------------
The following changes since commit 8df545592d73b67b0bf119732b52a5e4c0662ec4:
build: use --runstatedir instead of --localstatedir (2017-07-31 15:24:46 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git 2017wk30
for you to fetch changes up to 7677b5b502afd0c9436ce684bc38a8339a64e916:
agetty: fix invalid usage crash (2017-07-31 20:23:29 +0100)
----------------------------------------------------------------

Sami Kerola (9):
chfn, chsh: merge auth.h, islocal.h and libuser.h to ch-common.h
include: move pamfail.h to auth.c
vipw: use explicit_bzero() to clear buffer after copy
uuidparse: nil uuid have all bits set to zero
libuuid: use access(2) when checking /dev/random availability
bash-completion: look for look completions
agetty: remove dead DO_DEVFS_FIDDLING code segment
agetty: add --compile-time option
agetty: fix invalid usage crash

 bash-completion/look          |  13 +-
 include/Makemodule.am         |   1 -
 include/pamfail.h             |  26 ----
 libuuid/src/gen_uuid.c        |   5 +-
 login-utils/Makemodule.am     |   7 +-
 login-utils/auth.c            |  21 ++-
 login-utils/auth.h            |  13 --
 login-utils/ch-common.h       |  17 +++
 login-utils/chfn.c            |   4 -
 login-utils/chsh.c            |   4 -
 login-utils/islocal.c         |   2 +-
 login-utils/islocal.h         |   1 -
 login-utils/libuser.c         |   3 +-
 login-utils/libuser.h         |  14 --
 login-utils/vipw.c            |   3 +
 misc-utils/uuidparse.c        |   5 +-
 term-utils/agetty.8           |   3 +
 term-utils/agetty.c           | 296 ++++++++++++++++++++++++++++++++++++------
 tests/expected/uuid/uuidparse |   6 +-
 19 files changed, 320 insertions(+), 124 deletions(-)
 delete mode 100644 include/pamfail.h
 delete mode 100644 login-utils/auth.h
 delete mode 100644 login-utils/islocal.h
 delete mode 100644 login-utils/libuser.h
Signature · 1 line
2.13.3
#1 lore raw

PATCH 1/9 chfn, chsh: merge auth.h, islocal.h and libuser.h to ch-common.h

Merging header files is fine. Merging sources files ch-common.c is bad idea due linking needs, and differences in licences.

---
 login-utils/Makemodule.am |  7 ++-----
 login-utils/auth.c        |  2 +-
 login-utils/auth.h        | 13 -------------
 login-utils/ch-common.h   | 17 +++++++++++++++++
 login-utils/chfn.c        |  4 ----
 login-utils/chsh.c        |  4 ----
 login-utils/islocal.c     |  2 +-
 login-utils/islocal.h     |  1 -
 login-utils/libuser.c     |  3 +--
 login-utils/libuser.h     | 14 --------------
 10 files changed, 22 insertions(+), 45 deletions(-)
 delete mode 100644 login-utils/auth.h
 delete mode 100644 login-utils/islocal.h
 delete mode 100644 login-utils/libuser.h
login-utils/Makemodule.am +2 -5
index 67a0c98ec..2cc91b658 100644
@@ -90,20 +90,17 @@ if HAVE_LINUXPAM
 chfn_chsh_ldadd += -lpam_misc
 endif
 chfn_chsh_sources += \
-	login-utils/auth.c \
-	login-utils/auth.h
+	login-utils/auth.c
 endif # CHFN_CHSH_PASSWORD
 
 if HAVE_USER
 chfn_chsh_ldflags += $(LIBUSER_LIBS)
 chfn_chsh_cflags += $(LIBUSER_CFLAGS)
 chfn_chsh_sources+= \
-	login-utils/libuser.c \
-	login-utils/libuser.h
+	login-utils/libuser.c
 else
 chfn_chsh_sources += \
 	login-utils/islocal.c \
-	login-utils/islocal.h \
 	login-utils/setpwnam.c \
 	login-utils/setpwnam.h
 endif
login-utils/auth.c +1 -1
index aaf6c536b..68d4ea3b0 100644
@@ -7,7 +7,7 @@
  *   there is no warranty.
  *
  */
-#include "auth.h"
+#include "ch-common.h"
 #include "pamfail.h"
 
 int auth_pam(const char *service_name, uid_t uid, const char *username)
login-utils/auth.h deleted +0 -13
deleted file mode 100644
index bf7c36924..000000000
@@ -1,13 +0,0 @@
-/*
- *   auth.h -- PAM authorization code, common between chsh and chfn
- *   (c) 2012 by Cody Maloney <[email protected]>
- *
- *   this program is free software.  you can redistribute it and
- *   modify it under the terms of the gnu general public license.
- *   there is no warranty.
- *
- */
-
-#include <sys/types.h>
-
-extern int auth_pam(const char *service_name, uid_t uid, const char *username);
login-utils/ch-common.h +17 -0
index 7f70e50e1..e2b402cc2 100644
@@ -1,6 +1,23 @@
 #ifndef UTIL_LINUX_CH_COMMON_H
 #define UTIL_LINUX_CH_COMMON_H
 
+#include <sys/types.h>
+
 extern int illegal_passwd_chars(const char *str);
+extern int is_local(const char *user);
+
+/*
+ *   Utilize libuser to set a user attribute
+ *   (c) 2012 by Cody Maloney <[email protected]>
+ */
+
+extern int set_value_libuser(const char *service_name, const char *username,
+                        uid_t uid, const char *attr, const char *val);
+
+/*
+ *   PAM authorization code, common between chsh and chfn
+ *   (c) 2012 by Cody Maloney <[email protected]>
+ */
+extern int auth_pam(const char *service_name, uid_t uid, const char *username);
 
 #endif	/* UTIL_LINUX_CH_COMMON */
login-utils/chfn.c +0 -4
index c5312fa0c..d7d0d03f2 100644
@@ -35,7 +35,6 @@
 #include "c.h"
 #include "env.h"
 #include "closestream.h"
-#include "islocal.h"
 #include "nls.h"
 #include "setpwnam.h"
 #include "strutils.h"
@@ -51,9 +50,6 @@
 
 #ifdef HAVE_LIBUSER
 # include <libuser/user.h>
-# include "libuser.h"
-#elif CHFN_CHSH_PASSWORD
-# include "auth.h"
 #endif
 
 #ifdef HAVE_LIBREADLINE
login-utils/chsh.c +0 -4
index 4721c870e..cdbfbc405 100644
@@ -35,7 +35,6 @@
 #include "c.h"
 #include "env.h"
 #include "closestream.h"
-#include "islocal.h"
 #include "nls.h"
 #include "pathnames.h"
 #include "setpwnam.h"
@@ -52,9 +51,6 @@
 
 #ifdef HAVE_LIBUSER
 # include <libuser/user.h>
-# include "libuser.h"
-#elif CHFN_CHSH_PASSWORD
-# include "auth.h"
 #endif
 
 #ifdef HAVE_LIBREADLINE
login-utils/islocal.c +1 -1
index 7c4e775c1..5bfe61982 100644
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 
 #include "closestream.h"
-#include "islocal.h"
+#include "ch-common.h"
 #include "nls.h"
 #include "pathnames.h"
 
login-utils/islocal.h deleted +0 -1
deleted file mode 100644
index 2c5879906..000000000
@@ -1 +0,0 @@
-extern int is_local(const char *user);
login-utils/libuser.c +1 -2
index b11fadc1c..65538d7d4 100644
@@ -8,13 +8,12 @@
  *
  */
 
-#include "libuser.h"
+#include "ch-common.h"
 
 #include <grp.h>
 #include <libuser/user.h>
 #include <unistd.h>
 
-#include "auth.h"
 #include "c.h"
 #include "nls.h"
 
login-utils/libuser.h deleted +0 -14
deleted file mode 100644
index 7454b997e..000000000
@@ -1,14 +0,0 @@
-/*
- *   libuser.h -- Utilize libuser to set a user attribute
- *   (c) 2012 by Cody Maloney <[email protected]>
- *
- *   this program is free software.  you can redistribute it and
- *   modify it under the terms of the gnu general public license.
- *   there is no warranty.
- *
- */
-
-#include <sys/types.h>
-
-extern int set_value_libuser(const char *service_name, const char *username,
-			uid_t uid, const char *attr, const char *val);
Signature · 1 line
2.13.3
#4 lore raw

PATCH 2/9 include: move pamfail.h to auth.c

In reply to Sami Kerola

This removes one small header file, and makes inline function to static to only file it is used in.

---
 include/Makemodule.am |  1 -
 include/pamfail.h     | 26 --------------------------
 login-utils/auth.c    | 19 ++++++++++++++++++-
 3 files changed, 18 insertions(+), 28 deletions(-)
 delete mode 100644 include/pamfail.h
include/Makemodule.am +0 -1
index 237400b05..e9b1e3021 100644
@@ -33,7 +33,6 @@ dist_noinst_HEADERS += \
 	include/nls.h \
 	include/optutils.h \
 	include/pager.h \
-	include/pamfail.h \
 	include/partx.h \
 	include/path.h \
 	include/pathnames.h \
include/pamfail.h deleted +0 -26
deleted file mode 100644
index bb83b9404..000000000
@@ -1,26 +0,0 @@
-/*
- * No copyright is claimed.  This code is in the public domain; do with
- * it what you wish.
- *
- * Written by Karel Zak <[email protected]>
- */
-#ifndef UTIL_LINUX_PAMFAIL_H
-#include <security/pam_appl.h>
-#ifdef HAVE_SECURITY_PAM_MISC_H
-# include <security/pam_misc.h>
-#elif defined(HAVE_SECURITY_OPENPAM_H)
-# include <security/openpam.h>
-#endif
-#include "c.h"
-
-static inline int
-pam_fail_check(pam_handle_t *pamh, int retcode)
-{
-	if (retcode == PAM_SUCCESS)
-		return 0;
-	warnx("%s", pam_strerror(pamh, retcode));
-	pam_end(pamh, retcode);
-	return 1;
-}
-
-#endif /* UTIL_LINUX_PAMFAIL_H */
login-utils/auth.c +18 -1
index 68d4ea3b0..efbd5e8cb 100644
@@ -7,8 +7,25 @@
  *   there is no warranty.
  *
  */
+
+#include <security/pam_appl.h>
+#ifdef HAVE_SECURITY_PAM_MISC_H
+# include <security/pam_misc.h>
+#elif defined(HAVE_SECURITY_OPENPAM_H)
+# include <security/openpam.h>
+#endif
+
+#include "c.h"
 #include "ch-common.h"
-#include "pamfail.h"
+
+static int pam_fail_check(pam_handle_t *pamh, int retcode)
+{
+	if (retcode == PAM_SUCCESS)
+		return 0;
+	warnx("%s", pam_strerror(pamh, retcode));
+	pam_end(pamh, retcode);
+	return 1;
+}
 
 int auth_pam(const char *service_name, uid_t uid, const char *username)
 {
Signature · 1 line
2.13.3
#5 lore raw

PATCH 3/9 vipw: use explicit_bzero() to clear buffer after copy

In reply to Sami Kerola

This should make leaking end of /etc/shadow file more unlikely.

Notice that there is now way to tell to editors they should ensure none it does not leak any buffers, drop cores, and so on, when editing sensitive data. In short this change is addressing the issue only partially.

---
 login-utils/vipw.c | 3 +++
 1 file changed, 3 insertions(+)
login-utils/vipw.c +3 -0
index 5999d8d15..b7650de8b 100644
@@ -100,6 +100,9 @@ static void copyfile(int from, int to)
 
 	if (nr < 0)
 		pw_error(orig_file, 1, 1);
+#ifdef HAVE_EXPLICIT_BZERO
+	explicit_bzero(buf, sizeof(buf));
+#endif
 }
 
 static void pw_init(void)
Signature · 1 line
2.13.3
#6 lore raw

PATCH 4/9 uuidparse: nil uuid have all bits set to zero

In reply to Sami Kerola

The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.

Reference: https://tools.ietf.org/html/rfc4122#section-4.1.7

---
 misc-utils/uuidparse.c        | 5 ++++-
 tests/expected/uuid/uuidparse | 6 +++---
 2 files changed, 7 insertions(+), 4 deletions(-)
misc-utils/uuidparse.c +4 -1
index 49225ae2c..5fa34b23d 100644
@@ -195,7 +195,10 @@ static void fill_table_row(struct libscols_table *tb, char const *const uuid)
 			}
 			switch (type) {
 			case 0:
-				str = xstrdup(_("nil"));
+				if (strspn(uuid, "0-") == 36)
+					str = xstrdup(_("nil"));
+				else
+					str = xstrdup(_("unknown"));
 				break;
 			case 1:
 				str = xstrdup(_("time-based"));
tests/expected/uuid/uuidparse +3 -3
index 7fc64bcd2..c4959be8d 100644
@@ -6,20 +6,20 @@ UUID                                  VARIANT   TYPE       TIME
 00000000-0000-4000-0000-000000000000  NCS       random     
 00000000-0000-5000-0000-000000000000  NCS       sha1-based 
 00000000-0000-6000-0000-000000000000  NCS       unknown    
-00000000-0000-0000-8000-000000000000  DCE       nil        
+00000000-0000-0000-8000-000000000000  DCE       unknown    
 00000000-0000-2000-8000-000000000000  DCE       DCE        
 00000000-0000-3000-8000-000000000000  DCE       name-based 
 00000000-0000-4000-8000-000000000000  DCE       random     
 00000000-0000-5000-8000-000000000000  DCE       sha1-based 
 00000000-0000-6000-8000-000000000000  DCE       unknown    
-00000000-0000-0000-d000-000000000000  Microsoft nil        
+00000000-0000-0000-d000-000000000000  Microsoft unknown    
 00000000-0000-1000-d000-000000000000  Microsoft time-based 
 00000000-0000-2000-d000-000000000000  Microsoft DCE        
 00000000-0000-3000-d000-000000000000  Microsoft name-based 
 00000000-0000-4000-d000-000000000000  Microsoft random     
 00000000-0000-5000-d000-000000000000  Microsoft sha1-based 
 00000000-0000-6000-d000-000000000000  Microsoft unknown    
-00000000-0000-0000-f000-000000000000  other     nil        
+00000000-0000-0000-f000-000000000000  other     unknown    
 00000000-0000-1000-f000-000000000000  other     time-based 
 00000000-0000-2000-f000-000000000000  other     DCE        
 00000000-0000-3000-f000-000000000000  other     name-based 
Signature · 1 line
2.13.3
#7 lore raw

PATCH 5/9 libuuid: use access(2) when checking /dev/random availability

In reply to Sami Kerola

The access(2) is more lightwight than stat(2), and tells whether random device(s) can be read or not, unlike the earlier stat() call.

---
 libuuid/src/gen_uuid.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
libuuid/src/gen_uuid.c +2 -3
index 21e361293..7dafcaeed 100644
@@ -534,9 +534,8 @@ void uuid_generate_random(uuid_t out)
  */
 static int have_random_source(void)
 {
-	struct stat s;
-
-	return (!stat("/dev/random", &s) || !stat("/dev/urandom", &s));
+	return (access("/dev/random", R_OK) == 0 ||
+		access("/dev/urandom", R_OK) == 0);
 }
 
 
Signature · 1 line
2.13.3
#8 lore raw

PATCH 6/9 bash-completion: look for look completions

In reply to Sami Kerola

The look(1) uses positional arguments, where first one is a word from dictionary. It is reasonable to assume most of the time people search from system word lists so propose completions from there. The second argument is a dictionary file, that might invalidate the first input but that only happens to users who have an idea what the want without bash-completion.

---
 bash-completion/look | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
bash-completion/look +10 -3
index 303a7565a..feafe2379 100644
@@ -20,9 +20,16 @@ _look_module()
 			return 0
 			;;
 	esac
-	local IFS=$'\n'
-	compopt -o filenames
-	COMPREPLY=( $(compgen -f -- $cur) )
+	case $COMP_CWORD in
+		1)
+			COMPREPLY=( $(compgen -W "$(look "$cur")" -- $cur) )
+			;;
+		2)
+			local IFS=$'\n'
+			compopt -o filenames
+			COMPREPLY=( $(compgen -f -- $cur) )
+			;;
+	esac
 	return 0
 }
 complete -F _look_module look
Signature · 1 line
2.13.3
#9 lore raw

PATCH 7/9 agetty: remove dead DO_DEVFS_FIDDLING code segment

In reply to Sami Kerola

There is no ./configure option to enable this, and it is unlikely any distribution hot patching to enable fiddling when building package.

---
 term-utils/agetty.c | 39 ---------------------------------------
 1 file changed, 39 deletions(-)
term-utils/agetty.c +0 -39
index cc0cc3f62..a95da6f3d 100644
@@ -829,45 +829,6 @@ static void parse_args(int argc, char **argv, struct options *op)
 	if (argc > optind && argv[optind])
 		op->term = argv[optind];
 
-#ifdef DO_DEVFS_FIDDLING
-	/*
-	 * Some devfs junk, following Goswin Brederlow:
-	 *   turn ttyS<n> into tts/<n>
-	 *   turn tty<n> into vc/<n>
-	 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=72241
-	 */
-	if (op->tty && strlen(op->tty) < 90) {
-		char dev_name[100];
-		struct stat st;
-
-		if (strncmp(op->tty, "ttyS", 4) == 0) {
-			strcpy(dev_name, "/dev/");
-			strcat(dev_name, op->tty);
-			if (stat(dev_name, &st) < 0) {
-				strcpy(dev_name, "/dev/tts/");
-				strcat(dev_name, op->tty + 4);
-				if (stat(dev_name, &st) == 0) {
-					op->tty = strdup(dev_name + 5);
-					if (!op->tty)
-						log_err(_("failed to allocate memory: %m"));
-				}
-			}
-		} else if (strncmp(op->tty, "tty", 3) == 0) {
-			strcpy(dev_name, "/dev/");
-			strncat(dev_name, op->tty, 90);
-			if (stat(dev_name, &st) < 0) {
-				strcpy(dev_name, "/dev/vc/");
-				strcat(dev_name, op->tty + 3);
-				if (stat(dev_name, &st) == 0) {
-					op->tty = strdup(dev_name + 5);
-					if (!op->tty)
-						log_err(_("failed to allocate memory: %m"));
-				}
-			}
-		}
-	}
-#endif				/* DO_DEVFS_FIDDLING */
-
 	debug("exiting parseargs\n");
 }
 
Signature · 1 line
2.13.3
#10 lore raw

PATCH 8/9 agetty: add --compile-time option

In reply to Sami Kerola

This command has the most compile time #ifdef code. It is time to add an option to print what was defined when the command was compiled, so that debugging is easier.

---
 term-utils/agetty.8 |   3 +
 term-utils/agetty.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 254 insertions(+)
term-utils/agetty.8 +3 -0
index 23adff3b1..230c47cd5 100644
@@ -281,6 +281,9 @@ if the user has not yet commenced logging in.  After doing so the command will
 exit.  This feature might be unsupported on systems without Linux
 .BR inotify (7).
 .TP
+\-\-compile\-time
+Display compile time definitions.
+.TP
 \-\-version
 Display version information and exit.
 .TP
term-utils/agetty.c +251 -0

287 lines not on this page · raw message

Signature · 1 line
2.13.3
#13 lore raw

PATCH 9/9 agetty: fix invalid usage crash

In reply to Sami Kerola
$ agetty
agetty: not enough arguments: Success
Segmentation fault (core dumped)

Reference: 9325dbfd2018b2a3b510617f4aa13777fbbe23c3

---
 term-utils/agetty.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
term-utils/agetty.c +4 -2
index f06b9fc6e..d9e9548fa 100644
@@ -803,7 +803,8 @@ static void parse_args(int argc, char **argv, struct options *op)
 
 	if (argc < optind + 1) {
 		log_warn(_("not enough arguments"));
-		warn(_("not enough arguments"));
+		warnx(_("not enough arguments"));
+		errtryhelp(EXIT_FAILURE);
 	}
 
 	/* Accept "tty", "baudrate tty", and "tty baudrate". */
@@ -812,7 +813,8 @@ static void parse_args(int argc, char **argv, struct options *op)
 		parse_speeds(op, argv[optind++]);
 		if (argc < optind + 1) {
 			log_warn(_("not enough arguments"));
-			warn(_("not enough arguments"));
+			warnx(_("not enough arguments"));
+			exit(EXIT_FAILURE);
 		}
 		op->tty = argv[optind++];
 	} else {
Signature · 1 line
2.13.3
maintainer
#2 lore raw

Re: [PATCH 1/9] chfn, chsh: merge auth.h, islocal.h and libuser.h to ch-common.h

In reply to Sami Kerola
Quoted 17 lines · Sami Kerola
login-utils/Makemodule.am +1 -2
index 67a0c98ec..2cc91b658 100644
@@ -90,20 +90,17 @@ if HAVE_LINUXPAM
 chfn_chsh_ldadd += -lpam_misc
 endif
 chfn_chsh_sources += \
-	login-utils/auth.c \
-	login-utils/auth.h
+	login-utils/auth.c
 endif # CHFN_CHSH_PASSWORD
 
 if HAVE_USER
 chfn_chsh_ldflags += $(LIBUSER_LIBS)
 chfn_chsh_cflags += $(LIBUSER_CFLAGS)
 chfn_chsh_sources+= \

login-utils/Makemodule.am if HAVE_LINUXPAM · line 106

Quoted 10 lines
login-utils/Makemodule.am +1 -3
-	login-utils/libuser.c \
-	login-utils/libuser.h
+	login-utils/libuser.c
 else
 chfn_chsh_sources += \
 	login-utils/islocal.c \
-	login-utils/islocal.h \
 	login-utils/setpwnam.c \
 	login-utils/setpwnam.h
 endif

seems nowhere in the Makefile is our new ch-common.h

Quoted 11 lines
login-utils/chfn.c +0 -1
@@ -35,7 +35,6 @@
 #include "c.h"
 #include "env.h"
 #include "closestream.h"
-#include "islocal.h"
 #include "nls.h"
 #include "setpwnam.h"
 #include "strutils.h"

login-utils/chfn.c line 53

Quoted 7 lines
login-utils/chfn.c +0 -3
@@ -51,9 +50,6 @@
 
 #ifdef HAVE_LIBUSER
 # include <libuser/user.h>
-# include "libuser.h"
-#elif CHFN_CHSH_PASSWORD
-# include "auth.h"
 #endif

It would be better to include libuser in the ch-common.h if the function the header file depends on the library.

Frankly, I'm not sure if this patch improves readability of the code. Now we have to ways (pam and libuser) and both is pretty separated by .c and .h files. Not sure if merge it makes it better.

Karel

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

Re: [PATCH 8/9] agetty: add --compile-time option

In reply to Sami Kerola
Quoted 15 lines · Sami Kerola

This command has the most compile time #ifdef code. It is time to add an option to print what was defined when the command was compiled, so that debugging is easier.

---
 term-utils/agetty.8 |   3 +
 term-utils/agetty.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 254 insertions(+)
term-utils/agetty.8 +0 -0
index 23adff3b1..230c47cd5 100644

term-utils/agetty.8 if the user has not yet commenced logging in. After doing so the command will · line 285

Quoted 5 lines
term-utils/agetty.8 +2 -0
@@ -281,6 +281,9 @@ if the user has not yet commenced logging in.  After doing so the command will
 exit.  This feature might be unsupported on systems without Linux
 .BR inotify (7).
 .TP
+\-\-compile\-time
+Display compile time definitions.

I don't like the option name ;-)

term-utils/agetty.8 if the user has not yet commenced logging in. After doing so the command will

Quoted 7 lines
term-utils/agetty.8 +7 -0
+static void __attribute__((__noreturn__)) compile_time(void)
+{
+#ifdef B19200
+printf("%-30s: defined\n", "B19200");
+#else
+printf("%-30s: not in use\n", "B19200");
+#endif

This is overkill. I can imagine --list-speeds to list built-in speeds in format "<speed>\n"

static cost char *speeds[] = {

#ifdef B19200
    "B19200",

#endif
};

... and so on.

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef AGETTY_RELOAD
+printf("%-30s: defined\n", "AGETTY_RELOAD");
+#else
+printf("%-30s: not in use\n", "AGETTY_RELOAD");
+#endif

For this purpose we can use --version, see for example mount:

 $ mount -V
 mount from util-linux 2.28.2 (libmount 2.28.2: selinux, btrfs, force-mountinfo, assert, debug)

the same we can use for agetty to list *really important* enabled features, for example:

 $ agetty -V
 agetty from util-linux 2.31 (reload, issue, plymouth, debug)

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef CRTSCTS
+printf("%-30s: defined\n", "CRTSCTS");
+#else
+printf("%-30s: not in use\n", "CRTSCTS");
+#endif

not sure if this is important

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef DEBUGGING
+printf("%-30s: defined\n", "DEBUGGING");
+#else
+printf("%-30s: not in use\n", "DEBUGGING");
+#endif

ok

term-utils/agetty.8

Quoted 11 lines
term-utils/agetty.8 +11 -0
+#ifdef HAVE_GETDOMAINNAME
+printf("%-30s: defined\n", "HAVE_GETDOMAINNAME");
+#else
+printf("%-30s: not in use\n", "HAVE_GETDOMAINNAME");
+#endif
+
+#ifdef HAVE_LIBUTIL_H
+printf("%-30s: defined\n", "HAVE_LIBUTIL_H");
+#else
+printf("%-30s: not in use\n", "HAVE_LIBUTIL_H");
+#endif

unimportant

Quoted 7 lines
term-utils/agetty.8 +7 -0
+#ifdef HAVE_STRUCT_TERMIOS_C_LINE
+printf("%-30s: defined\n", "HAVE_STRUCT_TERMIOS_C_LINE");
+#else
+printf("%-30s: not in use\n", "HAVE_STRUCT_TERMIOS_C_LINE");
+#endif
+
+#ifdef HAVE_SYS_PARAM_H

term-utils/agetty.8

Quoted 10 lines
term-utils/agetty.8 +10 -0
+printf("%-30s: defined\n", "HAVE_SYS_PARAM_H");
+#else
+printf("%-30s: not in use\n", "HAVE_SYS_PARAM_H");
+#endif
+
+#ifdef HAVE_UTMP_H
+printf("%-30s: defined\n", "HAVE_UTMP_H");
+#else
+printf("%-30s: not in use\n", "HAVE_UTMP_H");
+#endif

really unimportant

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef HAVE_WIDECHAR
+printf("%-30s: defined\n", "HAVE_WIDECHAR");
+#else
+printf("%-30s: not in use\n", "HAVE_WIDECHAR");
+#endif

ok

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef ISSUE
+printf("%-30s: defined\n", "ISSUE");
+#else
+printf("%-30s: not in use\n", "ISSUE");
+#endif

ok

term-utils/agetty.8

Quoted 11 lines
term-utils/agetty.8 +10 -0
+#ifdef IUCLC
+printf("%-30s: defined\n", "IUCLC");
+#else
+printf("%-30s: not in use\n", "IUCLC");
+#endif
 
+#ifdef IUTF8
+printf("%-30s: defined\n", "IUTF8");
+#else
+printf("%-30s: not in use\n", "IUTF8");
+#endif

unimportant

term-utils/agetty.8

Quoted 11 lines
term-utils/agetty.8 +11 -0
+#ifdef KDGKBLED
+printf("%-30s: defined\n", "KDGKBLED");
+#else
+printf("%-30s: not in use\n", "KDGKBLED");
+#endif
+
+#ifdef KDGKBMODE
+printf("%-30s: defined\n", "KDGKBMODE");
+#else
+printf("%-30s: not in use\n", "KDGKBMODE");
+#endif

ok

Quoted 13 lines
term-utils/agetty.8 +13 -0
+#ifdef K_RAW
+printf("%-30s: defined\n", "K_RAW");
+#else
+printf("%-30s: not in use\n", "K_RAW");
+#endif
+
+#ifdef LOGIN_PROCESS
+printf("%-30s: defined\n", "LOGIN_PROCESS");
+#else
+printf("%-30s: not in use\n", "LOGIN_PROCESS");
+#endif
+
+#ifdef OLCUC

term-utils/agetty.8

Quoted 10 lines
term-utils/agetty.8 +10 -0
+printf("%-30s: defined\n", "OLCUC");
+#else
+printf("%-30s: not in use\n", "OLCUC");
+#endif
+
+#ifdef SYSV_STYLE
+printf("%-30s: defined\n", "SYSV_STYLE");
+#else
+printf("%-30s: not in use\n", "SYSV_STYLE");
+#endif

unimportant

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef USE_PLYMOUTH_SUPPORT
+printf("%-30s: defined\n", "USE_PLYMOUTH_SUPPORT");
+#else
+printf("%-30s: not in use\n", "USE_PLYMOUTH_SUPPORT");
+#endif

ok

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef USE_SYSLOG
+printf("%-30s: defined\n", "USE_SYSLOG");
+#else
+printf("%-30s: not in use\n", "USE_SYSLOG");
+#endif

ok

Quoted 7 lines
term-utils/agetty.8 +7 -0
+#ifdef XCASE
+printf("%-30s: defined\n", "XCASE");
+#else
+printf("%-30s: not in use\n", "XCASE");
+#endif
+
+#ifdef __FreeBSD_kernel__

term-utils/agetty.8

Quoted 10 lines
term-utils/agetty.8 +10 -0
+printf("%-30s: defined\n", "__FreeBSD_kernel__");
+#else
+printf("%-30s: not in use\n", "__FreeBSD_kernel__");
+#endif
+
+#ifdef __linux__
+printf("%-30s: defined\n", "__linux__");
+#else
+printf("%-30s: not in use\n", "__linux__");
+#endif

unimportant

Karel

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

Re: [PATCH 9/9] agetty: fix invalid usage crash

In reply to Sami Kerola
Quoted 25 lines · Sami Kerola
$ agetty
agetty: not enough arguments: Success
Segmentation fault (core dumped)

Reference: 9325dbfd2018b2a3b510617f4aa13777fbbe23c3

---
 term-utils/agetty.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
term-utils/agetty.c +2 -1
index f06b9fc6e..d9e9548fa 100644
@@ -803,7 +803,8 @@ static void parse_args(int argc, char **argv, struct options *op)
 
 	if (argc < optind + 1) {
 		log_warn(_("not enough arguments"));
-		warn(_("not enough arguments"));
+		warnx(_("not enough arguments"));
+		errtryhelp(EXIT_FAILURE);
 	}
 
 	/* Accept "tty", "baudrate tty", and "tty baudrate". */

term-utils/agetty.c static void parse_args(int argc, char **argv, struct options *op) · line 817

Quoted 6 lines
term-utils/agetty.c +2 -1
@@ -812,7 +813,8 @@ static void parse_args(int argc, char **argv, struct options *op)
 		parse_speeds(op, argv[optind++]);
 		if (argc < optind + 1) {
 			log_warn(_("not enough arguments"));
-			warn(_("not enough arguments"));
+			warnx(_("not enough arguments"));
+			exit(EXIT_FAILURE);

what about:

            errx(EXIT_FAILURE, _("not enough arguments"));

Karel

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

Re: [PATCH 1/9] chfn, chsh: merge auth.h, islocal.h and libuser.h to ch-common.h

In reply to Karel Zak
Quoted 3 lines · Karel Zak

Frankly, I'm not sure if this patch improves readability of the code. Now we have to ways (pam and libuser) and both is pretty separated by .c and .h files. Not sure if merge it makes it better.

Fair enough. This change is dropped from my 2017wk30 branch.

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
#15 lore raw

Re: [PATCH 9/9] agetty: fix invalid usage crash

In reply to Karel Zak
Quoted 11 lines · Karel Zak

term-utils/agetty.c static void parse_args(int argc, char **argv, struct options *op) · line 817

Quoted 7 lines · Sami Kerola
term-utils/agetty.c +2 -1
@@ -812,7 +813,8 @@ static void parse_args(int argc, char **argv, struct options *op)
 		parse_speeds(op, argv[optind++]);
 		if (argc < optind + 1) {
 			log_warn(_("not enough arguments"));
-			warn(_("not enough arguments"));
+			warnx(_("not enough arguments"));
+			exit(EXIT_FAILURE);

what about:

Quoted 1 line
            errx(EXIT_FAILURE, _("not enough arguments"));

That is better. Updates in my 2017wk30 branch.

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
#12 lore raw

Re: [PATCH 8/9] agetty: add --compile-time option

In reply to Karel Zak
Quoted 11 lines · Karel Zak
Quoted 10 lines · Sami Kerola

This command has the most compile time #ifdef code. It is time to add an option to print what was defined when the command was compiled, so that debugging is easier.

---
 term-utils/agetty.8 |   3 +
 term-utils/agetty.c | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 254 insertions(+)
Quoted 12 lines

term-utils/agetty.8 if the user has not yet commenced logging in. After doing so the command will · line 285

Quoted 10 lines
term-utils/agetty.8 +2 -0
index 23adff3b1..230c47cd5 100644
@@ -281,6 +281,9 @@ if the user has not yet commenced logging in.  After doing so the command will
 exit.  This feature might be unsupported on systems without Linux
 .BR inotify (7).
 .TP
+\-\-compile\-time
+Display compile time definitions.

I don't like the option name ;-)

It felt a bit sticky when proposing, but I'm clad that sent it anyway as you point out a lot better way.

Quoted 11 lines

term-utils/agetty.8 if the user has not yet commenced logging in. After doing so the command will

Quoted 7 lines
term-utils/agetty.8 +7 -0
+static void __attribute__((__noreturn__)) compile_time(void)
+{
+#ifdef B19200
+printf("%-30s: defined\n", "B19200");
+#else
+printf("%-30s: not in use\n", "B19200");
+#endif

This is overkill. I can imagine --list-speeds to list built-in speeds in format "<speed>\n"

Quoted 7 lines

static cost char *speeds[] = {

#ifdef B19200
    "B19200",

#endif
};

... and so on.

There is already speedlist, so how about reusing it. Here is a commit that adds the proposed option that way.

https://github.com/kerolasa/lelux-utiliteetit/commit/11841430c9b94d4f0246005a826a1c17a5af972d

Quoted 8 lines

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef AGETTY_RELOAD
+printf("%-30s: defined\n", "AGETTY_RELOAD");
+#else
+printf("%-30s: not in use\n", "AGETTY_RELOAD");
+#endif

For this purpose we can use --version, see for example mount:

Quoted 8 lines
 $ mount -V
 mount from util-linux 2.28.2 (libmount 2.28.2: selinux, btrfs, force-mountinfo, assert, debug)

the same we can use for agetty to list *really important* enabled features, for example:

 $ agetty -V
 agetty from util-linux 2.31 (reload, issue, plymouth, debug)

Oh yes, that is a lot nicer way. See below for the new version of the output. Primary reason I introduced output_version() is to avoid having the features[] array in scope when it is not needed.

https://github.com/kerolasa/lelux-utiliteetit/commit/63d94613a887c9a5f741d87bff4c7979293c4baf

Quoted 157 lines

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef CRTSCTS
+printf("%-30s: defined\n", "CRTSCTS");
+#else
+printf("%-30s: not in use\n", "CRTSCTS");
+#endif

not sure if this is important

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef DEBUGGING
+printf("%-30s: defined\n", "DEBUGGING");
+#else
+printf("%-30s: not in use\n", "DEBUGGING");
+#endif

ok

term-utils/agetty.8

Quoted 11 lines
term-utils/agetty.8 +11 -0
+#ifdef HAVE_GETDOMAINNAME
+printf("%-30s: defined\n", "HAVE_GETDOMAINNAME");
+#else
+printf("%-30s: not in use\n", "HAVE_GETDOMAINNAME");
+#endif
+
+#ifdef HAVE_LIBUTIL_H
+printf("%-30s: defined\n", "HAVE_LIBUTIL_H");
+#else
+printf("%-30s: not in use\n", "HAVE_LIBUTIL_H");
+#endif

unimportant

Quoted 7 lines
term-utils/agetty.8 +7 -0
+#ifdef HAVE_STRUCT_TERMIOS_C_LINE
+printf("%-30s: defined\n", "HAVE_STRUCT_TERMIOS_C_LINE");
+#else
+printf("%-30s: not in use\n", "HAVE_STRUCT_TERMIOS_C_LINE");
+#endif
+
+#ifdef HAVE_SYS_PARAM_H

term-utils/agetty.8

Quoted 10 lines
term-utils/agetty.8 +10 -0
+printf("%-30s: defined\n", "HAVE_SYS_PARAM_H");
+#else
+printf("%-30s: not in use\n", "HAVE_SYS_PARAM_H");
+#endif
+
+#ifdef HAVE_UTMP_H
+printf("%-30s: defined\n", "HAVE_UTMP_H");
+#else
+printf("%-30s: not in use\n", "HAVE_UTMP_H");
+#endif

really unimportant

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef HAVE_WIDECHAR
+printf("%-30s: defined\n", "HAVE_WIDECHAR");
+#else
+printf("%-30s: not in use\n", "HAVE_WIDECHAR");
+#endif

ok

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef ISSUE
+printf("%-30s: defined\n", "ISSUE");
+#else
+printf("%-30s: not in use\n", "ISSUE");
+#endif

ok

term-utils/agetty.8

Quoted 11 lines
term-utils/agetty.8 +10 -0
+#ifdef IUCLC
+printf("%-30s: defined\n", "IUCLC");
+#else
+printf("%-30s: not in use\n", "IUCLC");
+#endif
 
+#ifdef IUTF8
+printf("%-30s: defined\n", "IUTF8");
+#else
+printf("%-30s: not in use\n", "IUTF8");
+#endif

unimportant

term-utils/agetty.8

Quoted 11 lines
term-utils/agetty.8 +11 -0
+#ifdef KDGKBLED
+printf("%-30s: defined\n", "KDGKBLED");
+#else
+printf("%-30s: not in use\n", "KDGKBLED");
+#endif
+
+#ifdef KDGKBMODE
+printf("%-30s: defined\n", "KDGKBMODE");
+#else
+printf("%-30s: not in use\n", "KDGKBMODE");
+#endif

ok

Quoted 13 lines
term-utils/agetty.8 +13 -0
+#ifdef K_RAW
+printf("%-30s: defined\n", "K_RAW");
+#else
+printf("%-30s: not in use\n", "K_RAW");
+#endif
+
+#ifdef LOGIN_PROCESS
+printf("%-30s: defined\n", "LOGIN_PROCESS");
+#else
+printf("%-30s: not in use\n", "LOGIN_PROCESS");
+#endif
+
+#ifdef OLCUC

term-utils/agetty.8

Quoted 10 lines
term-utils/agetty.8 +10 -0
+printf("%-30s: defined\n", "OLCUC");
+#else
+printf("%-30s: not in use\n", "OLCUC");
+#endif
+
+#ifdef SYSV_STYLE
+printf("%-30s: defined\n", "SYSV_STYLE");
+#else
+printf("%-30s: not in use\n", "SYSV_STYLE");
+#endif

unimportant

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef USE_PLYMOUTH_SUPPORT
+printf("%-30s: defined\n", "USE_PLYMOUTH_SUPPORT");
+#else
+printf("%-30s: not in use\n", "USE_PLYMOUTH_SUPPORT");
+#endif

ok

term-utils/agetty.8

Quoted 5 lines
term-utils/agetty.8 +5 -0
+#ifdef USE_SYSLOG
+printf("%-30s: defined\n", "USE_SYSLOG");
+#else
+printf("%-30s: not in use\n", "USE_SYSLOG");
+#endif

ok

Quoted 7 lines
term-utils/agetty.8 +7 -0
+#ifdef XCASE
+printf("%-30s: defined\n", "XCASE");
+#else
+printf("%-30s: not in use\n", "XCASE");
+#endif
+
+#ifdef __FreeBSD_kernel__

term-utils/agetty.8

Quoted 10 lines
term-utils/agetty.8 +10 -0
+printf("%-30s: defined\n", "__FreeBSD_kernel__");
+#else
+printf("%-30s: not in use\n", "__FreeBSD_kernel__");
+#endif
+
+#ifdef __linux__
+printf("%-30s: defined\n", "__linux__");
+#else
+printf("%-30s: not in use\n", "__linux__");
+#endif

unimportant

Karel

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/