util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/19] compliancy fixes
@ 2012-10-14 20:20 Sami Kerola
  2012-10-14 20:20 ` [PATCH 01/19] last: stop using MAXHOSTNAMELEN Sami Kerola
                   ` (19 more replies)
  0 siblings, 20 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Hi Karel and others.

Here comes few patches.  This week I have done a little bit tidying up
from standards compliancy point of view.

The MAXHOSTNAMELEN are retiring static definition, and takes
sysconf(_SC_HOST_NAME_MAX) in use.  This make sense because sysconf() and
gethostname() are a pair, the later promises not to exceed what sysconf()
tells maximum to be.  Also if the allocated hostname string has space for
maximum + 1 char the gethostname() will null-terminate the string without
exceptions.

Manual fix is trivial, as well as sd-daemon fix.

The usleep(), index(), rindex(), gethostbyname() and utime() are all
found with cppcheck to be obsolete.  Here are Open Group notes.

http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap01.html#tag_22_01_01_04

Couple of these compliancy fixes are making code, and programs, a little
better.  For example I think after patch 0008 libmount is more readable,
and patch 0016 makes logger to allow IPv6 communications plus user to
define port by using /etc/service name.  That said some other patches in
this lot, such as 0019, does not add any other value than compliancy.


The following changes since commit dc3ea1335696434863c9ef4376858dcd4df6ec1b:

  libmount: fix umount file.img (2012-10-05 20:38:49 +0200)

are available in the git repository at:

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

for you to fetch changes up to 1081291888c800572615b7d4fc27ad65af05ad1d:

  fsck.cramfs: replace utime() with utimensat() (2012-10-13 15:50:22 +0100)

----------------------------------------------------------------
Sami Kerola (19):
     1  last: stop using MAXHOSTNAMELEN
     2  login: stop using MAXHOSTNAMELEN
     3  write: stop using MAXHOSTNAMELEN
     4  agetty: stop using MAXHOSTNAMELEN
     5  c.h: remove unnecessary MAXHOSTNAMELEN fallback definition
     6  docs: add line breaks to whereis.1
     7  sd-daemon: fix cppcheck warnings
     8  libmount: replace usleep with nanosleep
     9  include/all-io: replace usleep with nanosleep
    10  hwclock: replace usleep with nanosleep
    11  rtcwake: replace usleep with nanosleep
    12  agetty: replace usleep with nanosleep
    13  tailf: replace usleep with nanosleep
    14  include/usleep: remove remaining references to usleep
    15  libmount, eject: replace index() and rindex() with strrch() or strrchr()
    16  logger: replace gethostbyname() with getaddrinfo()
    17  agetty: replace gethostbyname() with getaddrinfo()
    18  build-sys: remove gethostbyname() check
    19  fsck.cramfs: replace utime() with utimensat()

 configure.ac             |  5 -----
 disk-utils/fsck.cramfs.c |  7 +++---
 include/Makemodule.am    |  1 -
 include/all-io.h         | 17 ++++++++++----
 include/c.h              | 11 ---------
 include/usleep.h         | 18 ---------------
 libmount/src/lock.c      | 16 ++++++++-----
 libmount/src/tab_parse.c |  4 ++--
 login-utils/last.c       | 19 +++++++---------
 login-utils/login.c      |  8 +++----
 misc-utils/logger.c      | 34 ++++++++++++++--------------
 misc-utils/sd-daemon.c   |  8 +++----
 misc-utils/whereis.1     |  4 ++--
 mount-deprecated/fstab.c |  1 -
 sys-utils/eject.c        |  2 +-
 sys-utils/hwclock-kd.c   |  6 +++--
 sys-utils/rtcwake.c      |  6 +++--
 term-utils/agetty.8      |  2 +-
 term-utils/agetty.c      | 58 +++++++++++++++++++++++++++++++++++-------------
 term-utils/write.c       |  7 ++++--
 text-utils/tailf.c       |  7 ++++--
 21 files changed, 126 insertions(+), 115 deletions(-)
 delete mode 100644 include/usleep.h



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

* [PATCH 01/19] last: stop using MAXHOSTNAMELEN
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-15  1:46   ` Mike Frysinger
  2012-10-14 20:20 ` [PATCH 02/19] login: " Sami Kerola
                   ` (18 subsequent siblings)
  19 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Use the sysconf(_SC_HOST_NAME_MAX) to determine maximum length of a
hostname.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/last.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index 77a890a..a3d5a85 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -418,22 +418,19 @@ addtty(char *ttyname) {
  */
 static void
 hostconv(char *arg) {
-	static int	first = 1;
-	static char	*hostdot,
-			name[MAXHOSTNAMELEN];
-	char	*argdot;
+	static char *hostdot;
+	static char *argdot;
+	static char *name;
 
 	if (!(argdot = strchr(arg, '.')))
 		return;
-	if (first) {
-		first = 0;
-		if (gethostname(name, sizeof(name)))
-			err(EXIT_FAILURE, _("gethostname failed"));
-
-		hostdot = strchr(name, '.');
-	}
+	name = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+	if (gethostname(name, sysconf(_SC_HOST_NAME_MAX)))
+		err(EXIT_FAILURE, _("gethostname failed"));
+	hostdot = strchr(name, '.');
 	if (hostdot && !strcmp(hostdot, argdot))
 		*argdot = '\0';
+	free(name);
 }
 
 /*
-- 
1.7.12.2


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

* [PATCH 02/19] login: stop using MAXHOSTNAMELEN
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
  2012-10-14 20:20 ` [PATCH 01/19] last: stop using MAXHOSTNAMELEN Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-14 20:20 ` [PATCH 03/19] write: " Sami Kerola
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Use the sysconf(_SC_HOST_NAME_MAX) to determine maximum length of a
hostname.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/login.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/login-utils/login.c b/login-utils/login.c
index 8ae5266..8cf6865 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -109,7 +109,7 @@ struct login_context {
 	char		vcsan[VCS_PATH_MAX];
 #endif
 
-	char		thishost[MAXHOSTNAMELEN + 1];	/* this machine */
+	char		*thishost;			/* this machine */
 	char		*thisdomain;			/* this machine domain */
 	char		*hostname;			/* remote machine */
 	char		hostaddress[16];		/* remote address */
@@ -209,13 +209,13 @@ static void __attribute__ ((__noreturn__)) sleepexit(int eval)
 
 static const char *get_thishost(struct login_context *cxt, const char **domain)
 {
-	if (!*cxt->thishost) {
-		if (gethostname(cxt->thishost, sizeof(cxt->thishost))) {
+	if (!cxt->thishost) {
+		cxt->thishost = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+		if (gethostname(cxt->thishost, sysconf(_SC_HOST_NAME_MAX))) {
 			if (domain)
 				*domain = NULL;
 			return NULL;
 		}
-		cxt->thishost[sizeof(cxt->thishost) -1] = '\0';
 		cxt->thisdomain = strchr(cxt->thishost, '.');
 		if (cxt->thisdomain)
 			*cxt->thisdomain++ = '\0';
-- 
1.7.12.2


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

* [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
  2012-10-14 20:20 ` [PATCH 01/19] last: stop using MAXHOSTNAMELEN Sami Kerola
  2012-10-14 20:20 ` [PATCH 02/19] login: " Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-15  2:12   ` Mike Frysinger
  2012-10-14 20:20 ` [PATCH 04/19] agetty: " Sami Kerola
                   ` (16 subsequent siblings)
  19 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Use the sysconf(_SC_HOST_NAME_MAX) to determine maximum length of a
hostname.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/write.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/term-utils/write.c b/term-utils/write.c
index 6c746b4..29b684b 100644
--- a/term-utils/write.c
+++ b/term-utils/write.c
@@ -63,6 +63,7 @@
 #include "carefulputc.h"
 #include "closestream.h"
 #include "nls.h"
+#include "xalloc.h"
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out);
 void search_utmp(char *, char *, char *, uid_t);
@@ -312,7 +313,7 @@ void do_write(char *tty, char *mytty, uid_t myuid)
 	char *login, *pwuid, *nows;
 	struct passwd *pwd;
 	time_t now;
-	char path[PATH_MAX], host[MAXHOSTNAMELEN], line[512];
+	char path[PATH_MAX], *host, line[512];
 
 	/* Determine our login name(s) before the we reopen() stdout */
 	if ((pwd = getpwuid(myuid)) != NULL)
@@ -332,7 +333,8 @@ void do_write(char *tty, char *mytty, uid_t myuid)
 	signal(SIGHUP, done);
 
 	/* print greeting */
-	if (gethostname(host, sizeof(host)) < 0)
+	host = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+	if (gethostname(host, sysconf(_SC_HOST_NAME_MAX)) < 0)
 		strcpy(host, "???");
 	now = time((time_t *) NULL);
 	nows = ctime(&now);
@@ -344,6 +346,7 @@ void do_write(char *tty, char *mytty, uid_t myuid)
 	else
 		printf(_("Message from %s@%s on %s at %s ..."),
 		       login, host, mytty, nows + 11);
+	free(host);
 	printf("\r\n");
 
 	while (fgets(line, sizeof(line), stdin) != NULL)
-- 
1.7.12.2


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

* [PATCH 04/19] agetty: stop using MAXHOSTNAMELEN
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (2 preceding siblings ...)
  2012-10-14 20:20 ` [PATCH 03/19] write: " Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-14 20:20 ` [PATCH 05/19] c.h: remove unnecessary MAXHOSTNAMELEN fallback definition Sami Kerola
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Use the sysconf(_SC_HOST_NAME_MAX) to determine maximum length of a
hostname.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/agetty.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 4e23135..754a43f 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1293,12 +1293,14 @@ static void do_prompt(struct options *op, struct termios *tp)
 	}
 #endif /* KDGKBLED */
 	if ((op->flags & F_NOHOSTNAME) == 0) {
-		char hn[MAXHOSTNAMELEN + 1];
-		if (gethostname(hn, sizeof(hn)) == 0) {
+		char *hn;
+		hn = malloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+		if (!hn)
+			log_err(_("failed to allocate memory: %m"));
+		if (gethostname(hn, sysconf(_SC_HOST_NAME_MAX)) == 0) {
 			struct hostent *ht;
 			char *dot = strchr(hn, '.');
 
-			hn[MAXHOSTNAMELEN] = '\0';
 			if ((op->flags & F_LONGHNAME) == 0) {
 				if (dot)
 					*dot = '\0';
@@ -1309,6 +1311,7 @@ static void do_prompt(struct options *op, struct termios *tp)
 				write_all(STDOUT_FILENO, hn, strlen(hn));
 			write_all(STDOUT_FILENO, " ", 1);
 		}
+		free(hn);
 	}
 	if (op->autolog == (char*)0) {
 		/* Always show login prompt. */
@@ -1732,7 +1735,7 @@ static void output_iface_ip(struct ifaddrs *addrs, const char *iface, sa_family_
 
 static void output_ip(sa_family_t family)
 {
-	char host[MAXHOSTNAMELEN + 1];
+	char *host;
 	struct addrinfo hints, *info = NULL;
 
 	memset(&hints, 0, sizeof(hints));
@@ -1740,7 +1743,10 @@ static void output_ip(sa_family_t family)
 	if (family == AF_INET6)
 		hints.ai_flags = AI_V4MAPPED;
 
-	if (gethostname(host, sizeof(host)) == 0
+	host = malloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+	if (!host)
+		log_err(_("failed to allocate memory: %m"));
+	if (gethostname(host, sysconf(_SC_HOST_NAME_MAX)) == 0
 	    && getaddrinfo(host, NULL, &hints, &info) == 0
 	    && info) {
 
@@ -1760,6 +1766,7 @@ static void output_ip(sa_family_t family)
 
 		freeaddrinfo(info);
 	}
+	free(host);
 }
 
 /*
@@ -1814,25 +1821,30 @@ static void output_special_char(unsigned char c, struct options *op,
 		break;
 	case 'o':
 	{
-		char domainname[MAXHOSTNAMELEN+1];
+		char *domainname;
+		domainname = malloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+		if (!domainname)
+			log_err(_("failed to allocate memory: %m"));
 #ifdef HAVE_GETDOMAINNAME
-		if (getdomainname(domainname, sizeof(domainname)))
+		if (getdomainname(domainname, sysconf(_SC_HOST_NAME_MAX)))
 #endif
 		strcpy(domainname, "unknown_domain");
-		domainname[sizeof(domainname)-1] = '\0';
 		printf("%s", domainname);
 		break;
 	}
 	case 'O':
 	{
 		char *dom = "unknown_domain";
-		char host[MAXHOSTNAMELEN+1];
+		char *host;
 		struct addrinfo hints, *info = NULL;
 
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_flags = AI_CANONNAME;
 
-		if (gethostname(host, sizeof(host)) ||
+		host = malloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+		if (!host)
+			log_err(_("failed to allocate memory: %m"));
+		if (gethostname(host, sysconf(_SC_HOST_NAME_MAX)) ||
 		    getaddrinfo(host, NULL, &hints, &info) ||
 		    info == NULL)
 			fputs(dom, stdout);
@@ -1844,6 +1856,7 @@ static void output_special_char(unsigned char c, struct options *op,
 			fputs(dom, stdout);
 			freeaddrinfo(info);
 		}
+		free(host);
 		break;
 	}
 	case 'd':
-- 
1.7.12.2


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

* [PATCH 05/19] c.h: remove unnecessary MAXHOSTNAMELEN fallback definition
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (3 preceding siblings ...)
  2012-10-14 20:20 ` [PATCH 04/19] agetty: " Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-14 20:20 ` [PATCH 06/19] docs: add line breaks to whereis.1 Sami Kerola
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 include/c.h | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/include/c.h b/include/c.h
index 64c0138..125ec62 100644
--- a/include/c.h
+++ b/include/c.h
@@ -224,17 +224,6 @@ static inline int dirfd(DIR *d)
 #endif
 
 /*
- * Fallback for MAXHOSTNAMELEN
- */
-#ifndef MAXHOSTNAMELEN
-# ifdef HOST_NAME_MAX
-#  define MAXHOSTNAMELEN HOST_NAME_MAX
-# else
-#  define MAXHOSTNAMELEN 64
-# endif
-#endif
-
-/*
  * Constant strings for usage() functions. For more info see
  * Documentation/howto-usage-function.txt and sys-utils/arch.c
  */
-- 
1.7.12.2


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

* [PATCH 06/19] docs: add line breaks to whereis.1
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (4 preceding siblings ...)
  2012-10-14 20:20 ` [PATCH 05/19] c.h: remove unnecessary MAXHOSTNAMELEN fallback definition Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-14 20:20 ` [PATCH 07/19] sd-daemon: fix cppcheck warnings Sami Kerola
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Fix to tools script checkmans.sh warning.

testing: /home/src/util-linux/misc-utils/whereis.1
:120: warning [p 1, 10.8i, div `an-div', 0.0i]: can't break line

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/whereis.1 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/misc-utils/whereis.1 b/misc-utils/whereis.1
index 988462f..f7f7d29 100644
--- a/misc-utils/whereis.1
+++ b/misc-utils/whereis.1
@@ -117,9 +117,9 @@ environment variable (since version 2.21).
 .TP 20
 /{bin,sbin,etc}
 .TP
-/usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,X386,TeX,g++-include}
+/usr/{lib,\:bin,\:old,\:new,\:local,\:games,\:include,\:etc,\:src,\:man,\:sbin,\:X386,\:TeX,\:g++-include}
 .TP
-/usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs}
+/usr/local/{X386,\:TeX,\:X11,\:include,\:lib,\:man,\:etc,\:bin,\:games,\:emacs}
 .SH "SEE ALSO"
 .BR chdir (2V)
 .SH BUGS
-- 
1.7.12.2


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

* [PATCH 07/19] sd-daemon: fix cppcheck warnings
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (5 preceding siblings ...)
  2012-10-14 20:20 ` [PATCH 06/19] docs: add line breaks to whereis.1 Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-14 22:10   ` Dave Reisner
  2012-10-14 20:20 ` [PATCH 08/19] libmount: replace usleep with nanosleep Sami Kerola
                   ` (12 subsequent siblings)
  19 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

[misc-utils/sd-daemon.c:91]: (style) Checking if unsigned variable 'l' is \
less than zero.
[misc-utils/sd-daemon.c:254]: (warning) Comparison of a boolean \
expression with an integer.
[misc-utils/sd-daemon.c:363]: (style) Checking if unsigned variable \
'length' is less than zero.
[misc-utils/sd-daemon.c:366]: (style) Checking if unsigned variable \
'length' is less than zero.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/sd-daemon.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/misc-utils/sd-daemon.c b/misc-utils/sd-daemon.c
index 763e079..21399e2 100644
--- a/misc-utils/sd-daemon.c
+++ b/misc-utils/sd-daemon.c
@@ -88,7 +88,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
                 goto finish;
         }
 
-        if (!p || *p || l <= 0) {
+	if (!p || *p || l == 0) {
                 r = -EINVAL;
                 goto finish;
         }
@@ -251,7 +251,7 @@ static int sd_is_socket_internal(int fd, int type, int listening) {
                 if (l != sizeof(accepting))
                         return -EINVAL;
 
-                if (!accepting != !listening)
+		if ((!accepting) != (!listening))
                         return 0;
         }
 
@@ -360,10 +360,10 @@ _sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *p
                 return 0;
 
         if (path) {
-                if (length <= 0)
+		if (length == 0)
                         length = strlen(path);
 
-                if (length <= 0)
+		if (length == 0)
                         /* Unnamed socket */
                         return l == offsetof(struct sockaddr_un, sun_path);
 
-- 
1.7.12.2


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

* [PATCH 08/19] libmount: replace usleep with nanosleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (6 preceding siblings ...)
  2012-10-14 20:20 ` [PATCH 07/19] sd-daemon: fix cppcheck warnings Sami Kerola
@ 2012-10-14 20:20 ` Sami Kerola
  2012-10-15  2:14   ` Mike Frysinger
  2012-10-14 20:21 ` [PATCH 09/19] include/all-io: " Sami Kerola
                   ` (11 subsequent siblings)
  19 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:20 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libmount/src/lock.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libmount/src/lock.c b/libmount/src/lock.c
index b149b6f..5245720 100644
--- a/libmount/src/lock.c
+++ b/libmount/src/lock.c
@@ -597,7 +597,6 @@ void __attribute__((__noreturn__)) sig_handler(int sig)
 int test_lock(struct libmnt_test *ts, int argc, char *argv[])
 {
 	time_t synctime = 0;
-	unsigned int usecs;
 	struct timeval tv;
 	const char *datafile = NULL;
 	int verbose = 0, loops = 0, l, idx = 1;
@@ -645,9 +644,10 @@ int test_lock(struct libmnt_test *ts, int argc, char *argv[])
 	if (synctime) {
 		gettimeofday(&tv, NULL);
 		if (synctime && synctime - tv.tv_sec > 1) {
-			usecs = ((synctime - tv.tv_sec) * 1000000UL) -
-						(1000000UL - tv.tv_usec);
-			usleep(usecs);
+			struct timespec waittime;
+			waittime.tv_sec = synctime - tv.tv_sec;
+			waittime.tv_nsec =  1000000000L - (1000 * tv.tv_usec);
+			nanosleep(&waittime, NULL);
 		}
 	}
 
@@ -672,8 +672,12 @@ int test_lock(struct libmnt_test *ts, int argc, char *argv[])
 		 * simulate this via short sleep -- it's also enough to make
 		 * concurrent processes happy.
 		 */
-		if (synctime)
-			usleep(25000);
+		if (synctime) {
+			struct timespec waittime;
+			waittime.tv_sec = 0;
+			waittime.tv_nsec = 25000000;
+			nanosleep(&waittime, NULL);
+		}
 	}
 
 	return 0;
-- 
1.7.12.2


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

* [PATCH 09/19] include/all-io: replace usleep with nanosleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (7 preceding siblings ...)
  2012-10-14 20:20 ` [PATCH 08/19] libmount: replace usleep with nanosleep Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 10/19] hwclock: " Sami Kerola
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 include/all-io.h | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/include/all-io.h b/include/all-io.h
index 38a760f..ed4f879 100644
--- a/include/all-io.h
+++ b/include/all-io.h
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
+#include <time.h>
 
 static inline int write_all(int fd, const void *buf, size_t count)
 {
@@ -18,8 +19,12 @@ static inline int write_all(int fd, const void *buf, size_t count)
 				buf = (void *) ((char *) buf + tmp);
 		} else if (errno != EINTR && errno != EAGAIN)
 			return -1;
-		if (errno == EAGAIN)	/* Try later, *sigh* */
-			usleep(10000);
+		if (errno == EAGAIN) {	/* Try later, *sigh* */
+			struct timespec waittime;
+			waittime.tv_sec = 0;
+			waittime.tv_nsec = 10000000;
+			nanosleep(&waittime, NULL);
+		}
 	}
 	return 0;
 }
@@ -38,8 +43,12 @@ static inline int fwrite_all(const void *ptr, size_t size,
 				ptr = (void *) ((char *) ptr + (tmp * size));
 		} else if (errno != EINTR && errno != EAGAIN)
 			return -1;
-		if (errno == EAGAIN)	/* Try later, *sigh* */
-			usleep(10000);
+		if (errno == EAGAIN) {	/* Try later, *sigh* */
+			struct timespec waittime;
+			waittime.tv_sec = 0;
+			waittime.tv_nsec = 10000000;
+			nanosleep(&waittime, NULL);
+		}
 	}
 	return 0;
 }
-- 
1.7.12.2


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

* [PATCH 10/19] hwclock: replace usleep with nanosleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (8 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 09/19] include/all-io: " Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 11/19] rtcwake: " Sami Kerola
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/hwclock-kd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys-utils/hwclock-kd.c b/sys-utils/hwclock-kd.c
index bfe50dc..c000024 100644
--- a/sys-utils/hwclock-kd.c
+++ b/sys-utils/hwclock-kd.c
@@ -12,7 +12,6 @@
 # include <unistd.h>
 
 # include "nls.h"
-# include "usleep.h"
 
 /* Get defines for KDGHWCLK and KDSHWCLK (m68k) */
 # include <linux/kd.h>
@@ -68,7 +67,10 @@ static int synchronize_to_clock_tick_kd(void)
 		 *  A2000 RTCs and simply hangs after some time. Inserting a
 		 *  sleep helps."
 		 */
-		usleep(1);
+		struct timespec waittime;
+		waittime.tv_sec = 0;
+		waittime.tv_nsec = 1000;
+		nanosleep(&waittime, NULL);
 
 		if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
 			warn(_("KDGHWCLK ioctl to read time failed in loop"));
-- 
1.7.12.2


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

* [PATCH 11/19] rtcwake: replace usleep with nanosleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (9 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 10/19] hwclock: " Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 12/19] agetty: " Sami Kerola
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/rtcwake.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index a1fd6dc..08f1c11 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -38,7 +38,6 @@
 #include "nls.h"
 #include "xalloc.h"
 #include "pathnames.h"
-#include "usleep.h"
 #include "strutils.h"
 #include "c.h"
 #include "closestream.h"
@@ -390,6 +389,7 @@ int main(int argc, char **argv)
 	int		t;
 	int		fd;
 	time_t		alarm = 0;
+	struct timespec	waittime;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -550,7 +550,9 @@ int main(int argc, char **argv)
 				program_invocation_short_name, suspend, devname,
 				ctime(&alarm));
 		fflush(stdout);
-		usleep(10 * 1000);
+		waittime.tv_sec = 0;
+		waittime.tv_nsec = 10000000;
+		nanosleep(&waittime, NULL);
 	}
 
 	if (strcmp(suspend, "no") == 0) {
-- 
1.7.12.2


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

* [PATCH 12/19] agetty: replace usleep with nanosleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (10 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 11/19] rtcwake: " Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 13/19] tailf: " Sami Kerola
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/agetty.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 754a43f..244ea29 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1383,7 +1383,10 @@ static char *get_logname(struct options *op, struct termios *tp, struct chardata
 
 				/* Do not report trivial like EINTR/EIO errors. */
 				if (errno == EINTR || errno == EAGAIN) {
-					usleep(1000);
+					struct timespec waittime;
+					waittime.tv_sec = 0;
+					waittime.tv_nsec = 1000000;
+					nanosleep(&waittime, NULL);
 					continue;
 				}
 				switch (errno) {
-- 
1.7.12.2


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

* [PATCH 13/19] tailf: replace usleep with nanosleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (11 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 12/19] agetty: " Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 14/19] include/usleep: remove remaining references to usleep Sami Kerola
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 text-utils/tailf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/text-utils/tailf.c b/text-utils/tailf.c
index 9571645..d76d53d 100644
--- a/text-utils/tailf.c
+++ b/text-utils/tailf.c
@@ -39,10 +39,10 @@
 #ifdef HAVE_INOTIFY_INIT
 #include <sys/inotify.h>
 #endif
+#include <time.h>
 
 #include "nls.h"
 #include "xalloc.h"
-#include "usleep.h"
 #include "strutils.h"
 #include "c.h"
 #include "closestream.h"
@@ -133,8 +133,11 @@ static void
 watch_file(const char *filename, off_t *size)
 {
 	do {
+		struct timespec waittime;
+		waittime.tv_sec = 0;
+		waittime.tv_nsec = 250000000;
 		roll_file(filename, size);
-		usleep(250000);
+		nanosleep(&waittime, NULL);
 	} while(1);
 }
 
-- 
1.7.12.2


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

* [PATCH 14/19] include/usleep: remove remaining references to usleep
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (12 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 13/19] tailf: " Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 15/19] libmount, eject: replace index() and rindex() with strrch() or strrchr() Sami Kerola
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

POSIX.1-2001 declares usleep is obsolete.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 configure.ac             |  1 -
 include/Makemodule.am    |  1 -
 include/usleep.h         | 18 ------------------
 mount-deprecated/fstab.c |  1 -
 4 files changed, 21 deletions(-)
 delete mode 100644 include/usleep.h

diff --git a/configure.ac b/configure.ac
index 9d2f589..d94f271 100644
--- a/configure.ac
+++ b/configure.ac
@@ -326,7 +326,6 @@ AC_CHECK_FUNCS([ \
 	strtoull \
 	sysconf \
 	updwtmp \
-	usleep \
 	warn \
 	warnx \
 ])
diff --git a/include/Makemodule.am b/include/Makemodule.am
index 9f9b78e..bef118f 100644
--- a/include/Makemodule.am
+++ b/include/Makemodule.am
@@ -38,7 +38,6 @@ dist_noinst_HEADERS += \
 	include/sysfs.h \
 	include/tt.h \
 	include/ttyutils.h \
-	include/usleep.h \
 	include/wholedisk.h \
 	include/widechar.h \
 	include/xalloc.h \
diff --git a/include/usleep.h b/include/usleep.h
deleted file mode 100644
index f64477c..0000000
--- a/include/usleep.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef UTIL_LINUX_USLEEP_H
-#define UTIL_LINUX_USLEEP_H
-
-#ifndef HAVE_USLEEP
-/*
- * This function is marked obsolete in POSIX.1-2001 and removed in
- * POSIX.1-2008. It is replaced with nanosleep().
- */
-# define usleep(x) \
-	do { \
-		struct timespec xsleep; \
-		xsleep.tv_sec = x / 1000 / 1000; \
-		xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \
-		nanosleep(&xsleep, NULL); \
-	} while (0)
-#endif
-
-#endif /* UTIL_LINUX_USLEEP_H */
diff --git a/mount-deprecated/fstab.c b/mount-deprecated/fstab.c
index 47159a3..18ae909 100644
--- a/mount-deprecated/fstab.c
+++ b/mount-deprecated/fstab.c
@@ -19,7 +19,6 @@
 #include "fsprobe.h"
 #include "pathnames.h"
 #include "nls.h"
-#include "usleep.h"
 #include "strutils.h"
 
 #define streq(s, t)	(strcmp ((s), (t)) == 0)
-- 
1.7.12.2


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

* [PATCH 15/19] libmount, eject: replace index() and rindex() with strrch() or strrchr()
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (13 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 14/19] include/usleep: remove remaining references to usleep Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-15  2:14   ` Mike Frysinger
  2012-10-14 20:21 ` [PATCH 16/19] logger: replace gethostbyname() with getaddrinfo() Sami Kerola
                   ` (4 subsequent siblings)
  19 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Both index() and rindex() are legacy functions which may be withdrawn in
a future.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/index.html
Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/rindex.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libmount/src/tab_parse.c | 4 ++--
 sys-utils/eject.c        | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index 463c884..2cae750 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -362,14 +362,14 @@ next_line:
 		if (fgets(buf, sizeof(buf), f) == NULL)
 			return -EINVAL;
 		++*nlines;
-		s = index (buf, '\n');
+		s = strchr (buf, '\n');
 		if (!s) {
 			/* Missing final newline?  Otherwise extremely */
 			/* long line - assume file was corrupted */
 			if (feof(f)) {
 				DBG(TAB, mnt_debug_h(tb,
 					"%s: no final newline",	filename));
-				s = index (buf, '\0');
+				s = strchr (buf, '\0');
 			} else {
 				DBG(TAB, mnt_debug_h(tb,
 					"%s:%d: missing newline at line",
diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 1a5b834..5d5d7b1 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -499,7 +499,7 @@ static int read_speed(const char *devname)
 	if (!f)
 		err(EXIT_FAILURE, _("cannot open %s"), _PATH_PROC_CDROMINFO);
 
-	name = rindex(devname, '/') + 1;
+	name = strrchr(devname, '/') + 1;
 
 	while (name && !feof(f)) {
 		char line[512];
-- 
1.7.12.2


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

* [PATCH 16/19] logger: replace gethostbyname() with getaddrinfo()
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (14 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 15/19] libmount, eject: replace index() and rindex() with strrch() or strrchr() Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 17/19] agetty: " Sami Kerola
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The gethostbyname() is legacy function which may be withdrawn in a
future.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyname.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/logger.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 6f9edc2..ecdbfe3 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -59,7 +59,6 @@
 #include <syslog.h>
 
 static int optd = 0;
-static uint16_t udpport = 514;
 
 static int decode(char *name, CODE *codetab)
 {
@@ -119,24 +118,25 @@ myopenlog(const char *sock) {
 }
 
 static int
-udpopenlog(const char *servername, uint16_t port) {
-	int fd;
-	struct sockaddr_in s_addr;
-	struct hostent *serverhost;
-
-	if ((serverhost = gethostbyname(servername)) == NULL )
-		errx(EXIT_FAILURE, _("unable to resolve '%s'"), servername);
-
-	if ((fd = socket(AF_INET, SOCK_DGRAM , 0)) == -1)
+udpopenlog(const char *servername, const char *port) {
+	int fd, errcode;
+	struct addrinfo hints, *res;
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_socktype = SOCK_DGRAM;
+	hints.ai_family = AF_UNSPEC;
+
+	errcode = getaddrinfo(servername, port, &hints, &res);
+	if (errcode != 0)
+		errx(EXIT_FAILURE, _("getaddrinfo %s:%s: %s"), servername, port,
+		     gai_strerror(errcode));
+	if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1)
 		err(EXIT_FAILURE, _("socket"));
 
-	memcpy(&s_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
-        s_addr.sin_family=AF_INET;
-        s_addr.sin_port=htons(port);
-
-        if (connect(fd, (struct sockaddr *) &s_addr, sizeof(s_addr)) == -1)
+	if (connect(fd, res->ai_addr, res->ai_addrlen) == -1)
 		err(EXIT_FAILURE, _("connect"));
 
+	freeaddrinfo(res);
 	return fd;
 }
 static void
@@ -201,6 +201,7 @@ main(int argc, char **argv) {
 	char *tag, buf[1024];
 	char *usock = NULL;
 	char *udpserver = NULL;
+	char *udpport = NULL;
 	int LogSock = -1;
 
 	static const struct option longopts[] = {
@@ -257,8 +258,7 @@ main(int argc, char **argv) {
 			udpserver = optarg;
 			break;
 		case 'P':		/* change udp port */
-			udpport = strtou16_or_err(optarg,
-						_("invalid port number argument"));
+			udpport = optarg;
 			break;
 		case 'V':
 			printf(_("%s from %s\n"), program_invocation_short_name,
-- 
1.7.12.2


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

* [PATCH 17/19] agetty: replace gethostbyname() with getaddrinfo()
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (15 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 16/19] logger: replace gethostbyname() with getaddrinfo() Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 18/19] build-sys: remove gethostbyname() check Sami Kerola
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The gethostbyname() is legacy function which may be withdrawn in a
future.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyname.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/agetty.8 |  2 +-
 term-utils/agetty.c | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/term-utils/agetty.8 b/term-utils/agetty.8
index e400ec8..e51017d 100644
--- a/term-utils/agetty.8
+++ b/term-utils/agetty.8
@@ -215,7 +215,7 @@ no hostname at all will be shown.
 \-\-long\-hostname
 By default the hostname is only printed until the first dot.  With
 this option enabled, the full qualified hostname by gethostname()
-or if not found by gethostbyname() is shown.
+or if not found by getaddrinfo() is shown.
 .TP
 \-\-version
 Output version information and exit.
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 244ea29..ac7c16c 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -1298,17 +1298,29 @@ static void do_prompt(struct options *op, struct termios *tp)
 		if (!hn)
 			log_err(_("failed to allocate memory: %m"));
 		if (gethostname(hn, sysconf(_SC_HOST_NAME_MAX)) == 0) {
-			struct hostent *ht;
 			char *dot = strchr(hn, '.');
 
 			if ((op->flags & F_LONGHNAME) == 0) {
 				if (dot)
 					*dot = '\0';
 				write_all(STDOUT_FILENO, hn, strlen(hn));
-			} else if (dot == NULL && (ht = gethostbyname(hn)))
-				write_all(STDOUT_FILENO, ht->h_name, strlen(ht->h_name));
-			else
+			} else if (dot == NULL) {
+				struct addrinfo *res, hints;
+				memset(&hints, 0, sizeof(hints));
+				hints.ai_flags = AI_CANONNAME;
+				if (!getaddrinfo(hn, NULL, &hints, &res)) {
+					write_all(STDOUT_FILENO,
+						  res->ai_canonname,
+						  strlen(res->ai_canonname));
+					freeaddrinfo(res);
+				} else {
+					freeaddrinfo(res);
+					goto printhn;
+				}
+			} else {
+ printhn:
 				write_all(STDOUT_FILENO, hn, strlen(hn));
+			}
 			write_all(STDOUT_FILENO, " ", 1);
 		}
 		free(hn);
-- 
1.7.12.2


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

* [PATCH 18/19] build-sys: remove gethostbyname() check
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (16 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 17/19] agetty: " Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-14 20:21 ` [PATCH 19/19] fsck.cramfs: replace utime() with utimensat() Sami Kerola
  2012-10-22  9:07 ` [PATCH 00/19] compliancy fixes Karel Zak
  19 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Removed as unnecessary, there are no references to gethostbyname() in
code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 configure.ac | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index d94f271..075bfba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -340,10 +340,6 @@ AC_CHECK_MEMBER(struct sockaddr.sa_len,
 	 #include <sys/socket.h>])
 
 SOCKET_LIBS=
-AC_SEARCH_LIBS([gethostbyname], [nsl],
-	[if test x"$ac_cv_search_gethostbyname" != x"none required"; then
-		SOCKET_LIBS="$SOCKET_LIBS -lnsl";
-	 fi])
 AC_SEARCH_LIBS([socket], [socket],
 	[if test x"$ac_cv_search_socket" != x"none required"; then
 		SOCKET_LIBS="$SOCKET_LIBS -lsocket";
-- 
1.7.12.2


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

* [PATCH 19/19] fsck.cramfs: replace utime() with utimensat()
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (17 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 18/19] build-sys: remove gethostbyname() check Sami Kerola
@ 2012-10-14 20:21 ` Sami Kerola
  2012-10-15  2:17   ` Mike Frysinger
  2012-10-22  9:07 ` [PATCH 00/19] compliancy fixes Karel Zak
  19 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-14 20:21 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The utime() function is marked obsolescent.

References: http://pubs.opengroup.org/onlinepubs/9699919799/functions/utime.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 disk-utils/fsck.cramfs.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c
index b39d231..3e2c8bb 100644
--- a/disk-utils/fsck.cramfs.c
+++ b/disk-utils/fsck.cramfs.c
@@ -45,7 +45,6 @@
 #include <errno.h>
 #include <string.h>
 #include <getopt.h>
-#include <utime.h>
 #include <fcntl.h>
 #include <zlib.h>
 
@@ -405,7 +404,7 @@ static void do_uncompress(char *path, int fd, unsigned long offset,
 
 static void change_file_status(char *path, struct cramfs_inode *i)
 {
-	struct utimbuf epoch = { 0, 0 };
+	struct timespec epoch = { 0, 0 };
 
 	if (euid == 0) {
 		if (lchown(path, i->uid, i->gid) < 0)
@@ -417,8 +416,8 @@ static void change_file_status(char *path, struct cramfs_inode *i)
 	}
 	if (S_ISLNK(i->mode))
 		return;
-	if (utime(path, &epoch) < 0)
-		err(FSCK_EX_ERROR, _("utime failed: %s"), path);
+	if (utimensat(path, &epoch, 0) < 0)
+		err(FSCK_EX_ERROR, _("utimensat failed: %s"), path);
 }
 
 static void do_directory(char *path, struct cramfs_inode *i)
-- 
1.7.12.2


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

* Re: [PATCH 07/19] sd-daemon: fix cppcheck warnings
  2012-10-14 20:20 ` [PATCH 07/19] sd-daemon: fix cppcheck warnings Sami Kerola
@ 2012-10-14 22:10   ` Dave Reisner
  2012-10-15  8:32     ` Sami Kerola
  0 siblings, 1 reply; 36+ messages in thread
From: Dave Reisner @ 2012-10-14 22:10 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Oct 14, 2012 at 09:20:58PM +0100, Sami Kerola wrote:
> [misc-utils/sd-daemon.c:91]: (style) Checking if unsigned variable 'l' is \
> less than zero.
> [misc-utils/sd-daemon.c:254]: (warning) Comparison of a boolean \
> expression with an integer.
> [misc-utils/sd-daemon.c:363]: (style) Checking if unsigned variable \
> 'length' is less than zero.
> [misc-utils/sd-daemon.c:366]: (style) Checking if unsigned variable \
> 'length' is less than zero.
> 
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
>  misc-utils/sd-daemon.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/misc-utils/sd-daemon.c b/misc-utils/sd-daemon.c
> index 763e079..21399e2 100644
> --- a/misc-utils/sd-daemon.c
> +++ b/misc-utils/sd-daemon.c

This file comes directly from the systemd tree. I think it'd be better
to submit the fix there first.

Either way, there's whitespace errors in this patch (tabs rather than
spaces).

> @@ -88,7 +88,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
>                  goto finish;
>          }
>  
> -        if (!p || *p || l <= 0) {
> +	if (!p || *p || l == 0) {
>                  r = -EINVAL;
>                  goto finish;
>          }
> @@ -251,7 +251,7 @@ static int sd_is_socket_internal(int fd, int type, int listening) {
>                  if (l != sizeof(accepting))
>                          return -EINVAL;
>  
> -                if (!accepting != !listening)
> +		if ((!accepting) != (!listening))
>                          return 0;
>          }
>  
> @@ -360,10 +360,10 @@ _sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *p
>                  return 0;
>  
>          if (path) {
> -                if (length <= 0)
> +		if (length == 0)
>                          length = strlen(path);
>  
> -                if (length <= 0)
> +		if (length == 0)
>                          /* Unnamed socket */
>                          return l == offsetof(struct sockaddr_un, sun_path);
>  
> -- 
> 1.7.12.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 01/19] last: stop using MAXHOSTNAMELEN
  2012-10-14 20:20 ` [PATCH 01/19] last: stop using MAXHOSTNAMELEN Sami Kerola
@ 2012-10-15  1:46   ` Mike Frysinger
  0 siblings, 0 replies; 36+ messages in thread
From: Mike Frysinger @ 2012-10-15  1:46 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

[-- Attachment #1: Type: Text/Plain, Size: 1132 bytes --]

On Sunday 14 October 2012 16:20:52 Sami Kerola wrote:
> --- a/login-utils/last.c
> +++ b/login-utils/last.c
> @@ -418,22 +418,19 @@ addtty(char *ttyname) {
>   */
>  static void
>  hostconv(char *arg) {
> -	static int	first = 1;
> -	static char	*hostdot,
> -			name[MAXHOSTNAMELEN];
> -	char	*argdot;
> +	static char *hostdot;
> +	static char *argdot;
> +	static char *name;
> 
>  	if (!(argdot = strchr(arg, '.')))
>  		return;
> -	if (first) {
> -		first = 0;
> -		if (gethostname(name, sizeof(name)))
> -			err(EXIT_FAILURE, _("gethostname failed"));
> -
> -		hostdot = strchr(name, '.');
> -	}
> +	name = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
> +	if (gethostname(name, sysconf(_SC_HOST_NAME_MAX)))
> +		err(EXIT_FAILURE, _("gethostname failed"));
> +	hostdot = strchr(name, '.');
>  	if (hostdot && !strcmp(hostdot, argdot))
>  		*argdot = '\0';
> +	free(name);
>  }

marking argdot static doesn't make sense

the way you're rewritten things also doesn't make sense to have "name" be 
static.  i'd go so far as to say it's wrong.  keep the existing "first" logic.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-14 20:20 ` [PATCH 03/19] write: " Sami Kerola
@ 2012-10-15  2:12   ` Mike Frysinger
       [not found]     ` <20121015152558.GK18377@x2.net.home>
  0 siblings, 1 reply; 36+ messages in thread
From: Mike Frysinger @ 2012-10-15  2:12 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

[-- Attachment #1: Type: Text/Plain, Size: 359 bytes --]

On Sunday 14 October 2012 16:20:54 Sami Kerola wrote:
> +	host = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
> +	if (gethostname(host, sysconf(_SC_HOST_NAME_MAX)) < 0)

sysconf() isn't labeled pure or anything, so it'd be better imo to store this 
in a local var so you don't waste time calling it twice.
	long len = sysconf(...);
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 08/19] libmount: replace usleep with nanosleep
  2012-10-14 20:20 ` [PATCH 08/19] libmount: replace usleep with nanosleep Sami Kerola
@ 2012-10-15  2:14   ` Mike Frysinger
  0 siblings, 0 replies; 36+ messages in thread
From: Mike Frysinger @ 2012-10-15  2:14 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

[-- Attachment #1: Type: Text/Plain, Size: 269 bytes --]

On Sunday 14 October 2012 16:20:59 Sami Kerola wrote:
> POSIX.1-2001 declares usleep is obsolete.

this is true, but it seems like a better answer would be to add a usleep test 
to configure and provide a local fallback using nanosleep if it doesn't exist.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 15/19] libmount, eject: replace index() and rindex() with strrch() or strrchr()
  2012-10-14 20:21 ` [PATCH 15/19] libmount, eject: replace index() and rindex() with strrch() or strrchr() Sami Kerola
@ 2012-10-15  2:14   ` Mike Frysinger
  0 siblings, 0 replies; 36+ messages in thread
From: Mike Frysinger @ 2012-10-15  2:14 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

[-- Attachment #1: Type: Text/Plain, Size: 193 bytes --]

On Sunday 14 October 2012 16:21:06 Sami Kerola wrote:
> Both index() and rindex() are legacy functions which may be withdrawn in
> a future.

Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 19/19] fsck.cramfs: replace utime() with utimensat()
  2012-10-14 20:21 ` [PATCH 19/19] fsck.cramfs: replace utime() with utimensat() Sami Kerola
@ 2012-10-15  2:17   ` Mike Frysinger
  2012-10-15  8:36     ` Sami Kerola
  0 siblings, 1 reply; 36+ messages in thread
From: Mike Frysinger @ 2012-10-15  2:17 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

[-- Attachment #1: Type: Text/Plain, Size: 211 bytes --]

On Sunday 14 October 2012 16:21:10 Sami Kerola wrote:
> +	if (utimensat(path, &epoch, 0) < 0)

err, did you test this at all ?  utimensat() takes 4 args one of which is a 
reference file descriptor.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 07/19] sd-daemon: fix cppcheck warnings
  2012-10-14 22:10   ` Dave Reisner
@ 2012-10-15  8:32     ` Sami Kerola
  0 siblings, 0 replies; 36+ messages in thread
From: Sami Kerola @ 2012-10-15  8:32 UTC (permalink / raw)
  To: util-linux

On Sun, Oct 14, 2012 at 11:10 PM, Dave Reisner <d@falconindy.com> wrote:
> On Sun, Oct 14, 2012 at 09:20:58PM +0100, Sami Kerola wrote:
>> [misc-utils/sd-daemon.c:91]: (style) Checking if unsigned variable 'l' is \
>> less than zero.
>> [misc-utils/sd-daemon.c:254]: (warning) Comparison of a boolean \
>> expression with an integer.
>> [misc-utils/sd-daemon.c:363]: (style) Checking if unsigned variable \
>> 'length' is less than zero.
>> [misc-utils/sd-daemon.c:366]: (style) Checking if unsigned variable \
>> 'length' is less than zero.
>>
>> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
>> ---
>>  misc-utils/sd-daemon.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/misc-utils/sd-daemon.c b/misc-utils/sd-daemon.c
>> index 763e079..21399e2 100644
>> --- a/misc-utils/sd-daemon.c
>> +++ b/misc-utils/sd-daemon.c
>
> This file comes directly from the systemd tree. I think it'd be better
> to submit the fix there first.
>
> Either way, there's whitespace errors in this patch (tabs rather than
> spaces).

Hi Dave,

OK, I will send the patch there and remove it from my branch. Thank
you for review.

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

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

* Re: [PATCH 19/19] fsck.cramfs: replace utime() with utimensat()
  2012-10-15  2:17   ` Mike Frysinger
@ 2012-10-15  8:36     ` Sami Kerola
  2012-10-15 17:39       ` Mike Frysinger
  0 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-15  8:36 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux

On Mon, Oct 15, 2012 at 3:17 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Sunday 14 October 2012 16:21:10 Sami Kerola wrote:
>> +     if (utimensat(path, &epoch, 0) < 0)
>
> err, did you test this at all ?  utimensat() takes 4 args one of which is a
> reference file descriptor.

Hi Mike and others,

I thought I did, but what ever I did where partly unsuccessful. Thank
you for all the feedback so far, I will adjust my branches
accordingly. This will probably take few evenings.

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

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

* Re: [PATCH 19/19] fsck.cramfs: replace utime() with utimensat()
  2012-10-15  8:36     ` Sami Kerola
@ 2012-10-15 17:39       ` Mike Frysinger
  0 siblings, 0 replies; 36+ messages in thread
From: Mike Frysinger @ 2012-10-15 17:39 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux

[-- Attachment #1: Type: Text/Plain, Size: 519 bytes --]

On Monday 15 October 2012 04:36:43 Sami Kerola wrote:
> On Mon, Oct 15, 2012 at 3:17 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> > On Sunday 14 October 2012 16:21:10 Sami Kerola wrote:
> >> +     if (utimensat(path, &epoch, 0) < 0)
> > 
> > err, did you test this at all ?  utimensat() takes 4 args one of which is
> > a reference file descriptor.
> 
> I thought I did, but what ever I did where partly unsuccessful.

cramfs isn't built by default, so you'll need to pass the right configure flag
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
       [not found]     ` <20121015152558.GK18377@x2.net.home>
@ 2012-10-18 20:06       ` Sami Kerola
  2012-10-22  6:01         ` Mike Frysinger
  0 siblings, 1 reply; 36+ messages in thread
From: Sami Kerola @ 2012-10-18 20:06 UTC (permalink / raw)
  To: Karel Zak; +Cc: Mike Frysinger, util-linux

Hello Mike and Karel,

Executive summary; try II is available at github.

The following changes since commit df0f2ad7633b3e2cc830298239cbaaa656e724cd:

  lib/loopdev: check for /sys (2012-10-17 11:51:10 +0200)

are available in the git repository at:

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

for you to fetch changes up to 1ada6eeb7046bc2fec71b244f404028ef8d9e158:

  build-sys: remove gethostbyname() check (2012-10-18 20:23:16 +0100)

----------------------------------------------------------------
Sami Kerola (17):
      include/env: add get_hostname_max() inline function
      include/env: unify indentation
      login: stop using MAXHOSTNAMELEN
      write: stop using MAXHOSTNAMELEN
      agetty: stop using MAXHOSTNAMELEN
      docs: add line breaks to whereis.1
      libmount: replace usleep with nanosleep
      include/all-io: replace usleep with nanosleep
      hwclock: replace usleep with nanosleep
      rtcwake: replace usleep with nanosleep
      agetty: replace usleep with nanosleep
      tailf: replace usleep with nanosleep
      include/usleep: remove remaining references to usleep
      libmount, eject: replace index() and rindex() with strrch() or strrchr()
      logger: replace gethostbyname() with getaddrinfo()
      agetty: replace gethostbyname() with getaddrinfo()
      build-sys: remove gethostbyname() check


And then to detailed comments.

On Mon, Oct 15, 2012 at 2:46 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Sunday 14 October 2012 16:20:52 Sami Kerola wrote:
>> --- a/login-utils/last.c
>> +++ b/login-utils/last.c
>> @@ -418,22 +418,19 @@ addtty(char *ttyname) {
>>   */
>>  static void
>>  hostconv(char *arg) {
>> -     static int      first = 1;
>> -     static char     *hostdot,
>> -                     name[MAXHOSTNAMELEN];
>> -     char    *argdot;
>> +     static char *hostdot;
>> +     static char *argdot;
>> +     static char *name;
>>
>>       if (!(argdot = strchr(arg, '.')))
>>               return;
>> -     if (first) {
>> -             first = 0;
>> -             if (gethostname(name, sizeof(name)))
>> -                     err(EXIT_FAILURE, _("gethostname failed"));
>> -
>> -             hostdot = strchr(name, '.');
>> -     }
>> +     name = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
>> +     if (gethostname(name, sysconf(_SC_HOST_NAME_MAX)))
>> +             err(EXIT_FAILURE, _("gethostname failed"));
>> +     hostdot = strchr(name, '.');
>>       if (hostdot && !strcmp(hostdot, argdot))
>>               *argdot = '\0';
>> +     free(name);
>>  }
>
> marking argdot static doesn't make sense
>
> the way you're rewritten things also doesn't make sense to have "name"
> be static.  i'd go so far as to say it's wrong.  keep the existing
> "first" logic.

I had another look of the last(1) code, and came to conclusion I need to
drop the patch.  It seems source of this command would benefit from major
rewrite clean up, but as it is marked as deprecated I do not feel there
is point doing that.  Maybe some day this implementation of last will be
found being deprecated long enough that it can be removed.


On Mon, Oct 15, 2012 at 3:14 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Sunday 14 October 2012 16:20:59 Sami Kerola wrote:
>> POSIX.1-2001 declares usleep is obsolete.
>
> this is true, but it seems like a better answer would be to add a
> usleep test to configure and provide a local fallback using nanosleep
> if it doesn't exist.

Is that necessary?  There has been for example in old mount since March
2007[1] nanosleep() call, and I cannot remember anyone complaining it
causing problems.

[1] commit dc8fdc57cd3ba0658cf4ab05031695c2d2965f93


On Mon, Oct 15, 2012 at 4:25 PM, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Oct 14, 2012 at 10:12:49PM -0400, Mike Frysinger wrote:
>> On Sunday 14 October 2012 16:20:54 Sami Kerola wrote:
>> > +   host = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
>> > +   if (gethostname(host, sysconf(_SC_HOST_NAME_MAX)) < 0)
>>
>> sysconf() isn't labeled pure or anything, so it'd be better imo to
>> store this
>> in a local var so you don't waste time calling it twice.
>>       long len = sysconf(...);
>
>  I agree.
>
>  IMHO it would be nice to add somewhere to the include/ directory a
>  robust function that always returns the size. Something like:
>
>  static inline size_t get_hostname_max(void)
>  {
>     long len = sysconf(_SC_HOST_NAME_MAX);
>
>     if (len > 0)
>         return len;
>
>     return 64;
>  }

Yes, that seems right.  I added the function to include/env.h which is
perhaps a bit strange file for it, but I did not want to add 'yet another
single inline function file' and I with quick looking I could not find
any other file that would have been more suitable.

https://github.com/kerolasa/lelux-utiliteetit/commit/351ec5992e42556051cb303361b962247fa1f752


On Mon, Oct 15, 2012 at 6:39 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Monday 15 October 2012 04:36:43 Sami Kerola wrote:
>> On Mon, Oct 15, 2012 at 3:17 AM, Mike Frysinger <vapier@gentoo.org>
>> wrote:
>> > On Sunday 14 October 2012 16:21:10 Sami Kerola wrote:
>> >> +     if (utimensat(path, &epoch, 0) < 0)
>> >
>> > err, did you test this at all ?  utimensat() takes 4 args one of
>> > which is
>> > a reference file descriptor.
>>
>> I thought I did, but what ever I did where partly unsuccessful.
>
> cramfs isn't built by default, so you'll need to pass the right
> configure flag

*sigh* I see.  And I dropped the patch.

I wonder if anyone is ever reaching code that requires INCLUDE_FS_TESTS
defined.  Should there be a configure --enable-fs-crams-tests switch?  If
that sort of switch is added it should perhaps be included when
--enable-most-builds is set.  Comments, opinions?

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

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-18 20:06       ` Sami Kerola
@ 2012-10-22  6:01         ` Mike Frysinger
  2012-10-22  8:06           ` Karel Zak
  0 siblings, 1 reply; 36+ messages in thread
From: Mike Frysinger @ 2012-10-22  6:01 UTC (permalink / raw)
  To: kerolasa; +Cc: Karel Zak, util-linux

[-- Attachment #1: Type: Text/Plain, Size: 3108 bytes --]

On Thursday 18 October 2012 16:06:28 Sami Kerola wrote:
> On Mon, Oct 15, 2012 at 3:14 AM, Mike Frysinger wrote:
> > On Sunday 14 October 2012 16:20:59 Sami Kerola wrote:
> >> POSIX.1-2001 declares usleep is obsolete.
> > 
> > this is true, but it seems like a better answer would be to add a
> > usleep test to configure and provide a local fallback using nanosleep
> > if it doesn't exist.
> 
> Is that necessary?  There has been for example in old mount since March
> 2007[1] nanosleep() call, and I cannot remember anyone complaining it
> causing problems.
> 
> [1] commit dc8fdc57cd3ba0658cf4ab05031695c2d2965f93

i think you misinterpreted my objection.  i don't have a problem with calling 
nanosleep() -- when it makes sense.  replacing a simple call to a function 
that, while no longer part of the latest standard, was mandated for many many 
years, and will most likely never be removed from C libraries that have 
already been providing it (since it'd be an ABI break), with a more 
complicated call for no real reason is pointless imo.  further, you'd be 
fighting a losing battle: developers will most likely be working & testing on a 
glibc system where usleep does exist and works fine, so they won't notice if it 
were added again.

hence i suggested a trivial middle ground that is future proof and doesn't 
penalize systems that do include usleep (i.e. glibc i.e. what the majority of 
people run): if you actually have a system that lacks usleep, then add usleep 
to the AC_CHECK_FUNCS tests in configure.ac, and then add the simple 
replacement to include/c.h:
#ifndef HAVE_USLEEP
static inline int usleep(useconds_t usec)
{
	struct timespec waittime;
	waittime.tv_sec = usec / 1000000L;
	waittime.tv_nsec =  (usec % 1000000L) * 1000;
	return nanosleep(&waittime, NULL);
}
#endif

now everything should "just work".

> On Mon, Oct 15, 2012 at 6:39 PM, Mike Frysinger wrote:
> > On Monday 15 October 2012 04:36:43 Sami Kerola wrote:
> >> On Mon, Oct 15, 2012 at 3:17 AM, Mike Frysinger wrote:
> >> > On Sunday 14 October 2012 16:21:10 Sami Kerola wrote:
> >> >> +     if (utimensat(path, &epoch, 0) < 0)
> >> > 
> >> > err, did you test this at all ?  utimensat() takes 4 args one of
> >> > which is
> >> > a reference file descriptor.
> >> 
> >> I thought I did, but what ever I did where partly unsuccessful.
> > 
> > cramfs isn't built by default, so you'll need to pass the right
> > configure flag
> 
> *sigh* I see.  And I dropped the patch.
> 
> I wonder if anyone is ever reaching code that requires INCLUDE_FS_TESTS
> defined.  Should there be a configure --enable-fs-crams-tests switch?  If
> that sort of switch is added it should perhaps be included when
> --enable-most-builds is set.  Comments, opinions?

i would add a new check target to disk-utils/Makemodule.am

check_PROGRAMS += test_mkfs.cramfs
test_mkfs_cramfs_SOURCES = $(mkfs_cramfs_SOURCES)
test_mkfs_cramfs_LDADD = $(mkfs_cramfs_LDADD)
test_mkfs_cramfs_CFLAGS = -DINCLUDE_FS_TESTS

then see what happens when you run `make check` ...
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-22  6:01         ` Mike Frysinger
@ 2012-10-22  8:06           ` Karel Zak
  2012-10-22  8:09             ` Karel Zak
  2012-10-22 20:03             ` Mike Frysinger
  0 siblings, 2 replies; 36+ messages in thread
From: Karel Zak @ 2012-10-22  8:06 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: kerolasa, util-linux

On Mon, Oct 22, 2012 at 02:01:01AM -0400, Mike Frysinger wrote:
> On Thursday 18 October 2012 16:06:28 Sami Kerola wrote:
> > On Mon, Oct 15, 2012 at 3:14 AM, Mike Frysinger wrote:
> > > On Sunday 14 October 2012 16:20:59 Sami Kerola wrote:
> > >> POSIX.1-2001 declares usleep is obsolete.
> > > 
> > > this is true, but it seems like a better answer would be to add a
> > > usleep test to configure and provide a local fallback using nanosleep
> > > if it doesn't exist.
> > 
> > Is that necessary?  There has been for example in old mount since March
> > 2007[1] nanosleep() call, and I cannot remember anyone complaining it
> > causing problems.
> > 
> > [1] commit dc8fdc57cd3ba0658cf4ab05031695c2d2965f93
> 
> i think you misinterpreted my objection.  i don't have a problem with calling 
> nanosleep() -- when it makes sense.  replacing a simple call to a function 
> that, while no longer part of the latest standard, was mandated for many many 
> years, and will most likely never be removed from C libraries that have 
> already been providing it (since it'd be an ABI break), with a more 
> complicated call for no real reason is pointless imo.  further, you'd be 
> fighting a losing battle: developers will most likely be working & testing on a 
> glibc system where usleep does exist and works fine, so they won't notice if it 
> were added again.
> 
> hence i suggested a trivial middle ground that is future proof and doesn't 
> penalize systems that do include usleep (i.e. glibc i.e. what the majority of 
> people run): if you actually have a system that lacks usleep, then add usleep 
> to the AC_CHECK_FUNCS tests in configure.ac, and then add the simple 
> replacement to include/c.h:
> #ifndef HAVE_USLEEP
> static inline int usleep(useconds_t usec)
> {
> 	struct timespec waittime;
> 	waittime.tv_sec = usec / 1000000L;
> 	waittime.tv_nsec =  (usec % 1000000L) * 1000;
> 	return nanosleep(&waittime, NULL);
> }
> #endif
> 
> now everything should "just work".

Exactly this solution we use for now (since 2009):

$ cat include/usleep.h

#ifndef UTIL_LINUX_USLEEP_H
#define UTIL_LINUX_USLEEP_H

#ifndef HAVE_USLEEP
/*
 * This function is marked obsolete in POSIX.1-2001 and removed in
 * POSIX.1-2008. It is replaced with nanosleep().
 */
# define usleep(x) \
	do { \
		struct timespec xsleep; \
		xsleep.tv_sec = x / 1000 / 1000; \
		xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \
		nanosleep(&xsleep, NULL); \
	} while (0)
#endif

#endif /* UTIL_LINUX_USLEEP_H */


... so I don't think we have to check change anything.

> > On Mon, Oct 15, 2012 at 6:39 PM, Mike Frysinger wrote:
> > > On Monday 15 October 2012 04:36:43 Sami Kerola wrote:
> > >> On Mon, Oct 15, 2012 at 3:17 AM, Mike Frysinger wrote:
> > >> > On Sunday 14 October 2012 16:21:10 Sami Kerola wrote:
> > >> >> +     if (utimensat(path, &epoch, 0) < 0)
> > >> > 
> > >> > err, did you test this at all ?  utimensat() takes 4 args one of
> > >> > which is
> > >> > a reference file descriptor.
> > >> 
> > >> I thought I did, but what ever I did where partly unsuccessful.
> > > 
> > > cramfs isn't built by default, so you'll need to pass the right
> > > configure flag
> > 
> > *sigh* I see.  And I dropped the patch.
> > 
> > I wonder if anyone is ever reaching code that requires INCLUDE_FS_TESTS
> > defined.  Should there be a configure --enable-fs-crams-tests switch?  If
> > that sort of switch is added it should perhaps be included when
> > --enable-most-builds is set.  Comments, opinions?
> 
> i would add a new check target to disk-utils/Makemodule.am
> 
> check_PROGRAMS += test_mkfs.cramfs
> test_mkfs_cramfs_SOURCES = $(mkfs_cramfs_SOURCES)
> test_mkfs_cramfs_LDADD = $(mkfs_cramfs_LDADD)
> test_mkfs_cramfs_CFLAGS = -DINCLUDE_FS_TESTS

 Good point. Fixed.

    Karel

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

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-22  8:06           ` Karel Zak
@ 2012-10-22  8:09             ` Karel Zak
  2012-10-22 20:03             ` Mike Frysinger
  1 sibling, 0 replies; 36+ messages in thread
From: Karel Zak @ 2012-10-22  8:09 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: kerolasa, util-linux

On Mon, Oct 22, 2012 at 10:06:24AM +0200, Karel Zak wrote:
> ... so I don't think we have to check change anything.

  s/check//

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

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

* Re: [PATCH 00/19] compliancy fixes
  2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
                   ` (18 preceding siblings ...)
  2012-10-14 20:21 ` [PATCH 19/19] fsck.cramfs: replace utime() with utimensat() Sami Kerola
@ 2012-10-22  9:07 ` Karel Zak
  19 siblings, 0 replies; 36+ messages in thread
From: Karel Zak @ 2012-10-22  9:07 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Oct 14, 2012 at 09:20:51PM +0100, Sami Kerola wrote:
>      1  last: stop using MAXHOSTNAMELEN
>      2  login: stop using MAXHOSTNAMELEN
>      3  write: stop using MAXHOSTNAMELEN
>      4  agetty: stop using MAXHOSTNAMELEN
>      5  c.h: remove unnecessary MAXHOSTNAMELEN fallback definition

Applied, I did some changes to the code:

    - get_hostname_max() moved to c.h
    - added xgethostname() to xalloc.h to avoid duplicate code.

>      6  docs: add line breaks to whereis.1

>      7  sd-daemon: fix cppcheck warnings

ignored

>      8  libmount: replace usleep with nanosleep
>      9  include/all-io: replace usleep with nanosleep
>     10  hwclock: replace usleep with nanosleep
>     11  rtcwake: replace usleep with nanosleep
>     12  agetty: replace usleep with nanosleep
>     13  tailf: replace usleep with nanosleep
>     14  include/usleep: remove remaining references to usleep

 it seems unnecessary as we already have a fallback solution for
 systems without usleep()

 I have moved the fallbcack from include/usleep.h to include/c.h.

>     15  libmount, eject: replace index() and rindex() with strrch() or strrchr()
>     16  logger: replace gethostbyname() with getaddrinfo()
>     17  agetty: replace gethostbyname() with getaddrinfo()
>     18  build-sys: remove gethostbyname() check

 applied

>     19  fsck.cramfs: replace utime() with utimensat()

 I have add fsck.cramfs to check_PROGRAMS.

    Karel

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

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-22  8:06           ` Karel Zak
  2012-10-22  8:09             ` Karel Zak
@ 2012-10-22 20:03             ` Mike Frysinger
  2012-10-22 20:22               ` Karel Zak
  1 sibling, 1 reply; 36+ messages in thread
From: Mike Frysinger @ 2012-10-22 20:03 UTC (permalink / raw)
  To: Karel Zak; +Cc: kerolasa, util-linux

[-- Attachment #1: Type: Text/Plain, Size: 3019 bytes --]

On Monday 22 October 2012 04:06:24 Karel Zak wrote:
> On Mon, Oct 22, 2012 at 02:01:01AM -0400, Mike Frysinger wrote:
> > On Thursday 18 October 2012 16:06:28 Sami Kerola wrote:
> > > On Mon, Oct 15, 2012 at 3:14 AM, Mike Frysinger wrote:
> > > > On Sunday 14 October 2012 16:20:59 Sami Kerola wrote:
> > > >> POSIX.1-2001 declares usleep is obsolete.
> > > > 
> > > > this is true, but it seems like a better answer would be to add a
> > > > usleep test to configure and provide a local fallback using nanosleep
> > > > if it doesn't exist.
> > > 
> > > Is that necessary?  There has been for example in old mount since March
> > > 2007[1] nanosleep() call, and I cannot remember anyone complaining it
> > > causing problems.
> > > 
> > > [1] commit dc8fdc57cd3ba0658cf4ab05031695c2d2965f93
> > 
> > i think you misinterpreted my objection.  i don't have a problem with
> > calling nanosleep() -- when it makes sense.  replacing a simple call to
> > a function that, while no longer part of the latest standard, was
> > mandated for many many years, and will most likely never be removed from
> > C libraries that have already been providing it (since it'd be an ABI
> > break), with a more complicated call for no real reason is pointless
> > imo.  further, you'd be fighting a losing battle: developers will most
> > likely be working & testing on a glibc system where usleep does exist
> > and works fine, so they won't notice if it were added again.
> > 
> > hence i suggested a trivial middle ground that is future proof and
> > doesn't penalize systems that do include usleep (i.e. glibc i.e. what
> > the majority of people run): if you actually have a system that lacks
> > usleep, then add usleep to the AC_CHECK_FUNCS tests in configure.ac, and
> > then add the simple replacement to include/c.h:
> > #ifndef HAVE_USLEEP
> > static inline int usleep(useconds_t usec)
> > {
> > 
> > 	struct timespec waittime;
> > 	waittime.tv_sec = usec / 1000000L;
> > 	waittime.tv_nsec =  (usec % 1000000L) * 1000;
> > 	return nanosleep(&waittime, NULL);
> > 
> > }
> > #endif
> > 
> > now everything should "just work".
> 
> Exactly this solution we use for now (since 2009):

heh.  too fast!

> $ cat include/usleep.h
> 
> #ifndef UTIL_LINUX_USLEEP_H
> #define UTIL_LINUX_USLEEP_H
> 
> #ifndef HAVE_USLEEP
> /*
>  * This function is marked obsolete in POSIX.1-2001 and removed in
>  * POSIX.1-2008. It is replaced with nanosleep().
>  */
> # define usleep(x) \
> 	do { \
> 		struct timespec xsleep; \
> 		xsleep.tv_sec = x / 1000 / 1000; \
> 		xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \
> 		nanosleep(&xsleep, NULL); \
> 	} while (0)
> #endif
> 
> #endif /* UTIL_LINUX_USLEEP_H */

if you were to do something like:
	int foo = 10;
	usleep(foo++);

this define macro would misbehave because it expands x twice.  not that the 
current code base does.

> ... so I don't think we have to check change anything.

indeed
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 03/19] write: stop using MAXHOSTNAMELEN
  2012-10-22 20:03             ` Mike Frysinger
@ 2012-10-22 20:22               ` Karel Zak
  0 siblings, 0 replies; 36+ messages in thread
From: Karel Zak @ 2012-10-22 20:22 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: kerolasa, util-linux

On Mon, Oct 22, 2012 at 04:03:01PM -0400, Mike Frysinger wrote:
> if you were to do something like:
> 	int foo = 10;
> 	usleep(foo++);
> 
> this define macro would misbehave because it expands x twice.  not that the 
> current code base does.

 Yes, I moved the fallback to c.h as inline function this morning.

    Karel


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

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

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

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-14 20:20 [PATCH 00/19] compliancy fixes Sami Kerola
2012-10-14 20:20 ` [PATCH 01/19] last: stop using MAXHOSTNAMELEN Sami Kerola
2012-10-15  1:46   ` Mike Frysinger
2012-10-14 20:20 ` [PATCH 02/19] login: " Sami Kerola
2012-10-14 20:20 ` [PATCH 03/19] write: " Sami Kerola
2012-10-15  2:12   ` Mike Frysinger
     [not found]     ` <20121015152558.GK18377@x2.net.home>
2012-10-18 20:06       ` Sami Kerola
2012-10-22  6:01         ` Mike Frysinger
2012-10-22  8:06           ` Karel Zak
2012-10-22  8:09             ` Karel Zak
2012-10-22 20:03             ` Mike Frysinger
2012-10-22 20:22               ` Karel Zak
2012-10-14 20:20 ` [PATCH 04/19] agetty: " Sami Kerola
2012-10-14 20:20 ` [PATCH 05/19] c.h: remove unnecessary MAXHOSTNAMELEN fallback definition Sami Kerola
2012-10-14 20:20 ` [PATCH 06/19] docs: add line breaks to whereis.1 Sami Kerola
2012-10-14 20:20 ` [PATCH 07/19] sd-daemon: fix cppcheck warnings Sami Kerola
2012-10-14 22:10   ` Dave Reisner
2012-10-15  8:32     ` Sami Kerola
2012-10-14 20:20 ` [PATCH 08/19] libmount: replace usleep with nanosleep Sami Kerola
2012-10-15  2:14   ` Mike Frysinger
2012-10-14 20:21 ` [PATCH 09/19] include/all-io: " Sami Kerola
2012-10-14 20:21 ` [PATCH 10/19] hwclock: " Sami Kerola
2012-10-14 20:21 ` [PATCH 11/19] rtcwake: " Sami Kerola
2012-10-14 20:21 ` [PATCH 12/19] agetty: " Sami Kerola
2012-10-14 20:21 ` [PATCH 13/19] tailf: " Sami Kerola
2012-10-14 20:21 ` [PATCH 14/19] include/usleep: remove remaining references to usleep Sami Kerola
2012-10-14 20:21 ` [PATCH 15/19] libmount, eject: replace index() and rindex() with strrch() or strrchr() Sami Kerola
2012-10-15  2:14   ` Mike Frysinger
2012-10-14 20:21 ` [PATCH 16/19] logger: replace gethostbyname() with getaddrinfo() Sami Kerola
2012-10-14 20:21 ` [PATCH 17/19] agetty: " Sami Kerola
2012-10-14 20:21 ` [PATCH 18/19] build-sys: remove gethostbyname() check Sami Kerola
2012-10-14 20:21 ` [PATCH 19/19] fsck.cramfs: replace utime() with utimensat() Sami Kerola
2012-10-15  2:17   ` Mike Frysinger
2012-10-15  8:36     ` Sami Kerola
2012-10-15 17:39       ` Mike Frysinger
2012-10-22  9:07 ` [PATCH 00/19] compliancy fixes Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).