public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] uuidd: ensure pid file is wrote when it is requested
@ 2014-05-25 10:59 Sami Kerola
  2014-05-25 10:59 ` [PATCH 2/4] uuidd: set options to be mutually exclusive Sami Kerola
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sami Kerola @ 2014-05-25 10:59 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Earlier for example this 'uuidd --pid /dev/full' worked, now error is
printed about truncating not being possible for character device and
assuming someone would write pid to full disk it should not be go by
unnoticed.

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

diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index c626105..5730919 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -338,10 +338,12 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
 
 		if (pidfile_path) {
 			sprintf(reply_buf, "%8d\n", getpid());
-			ignore_result( ftruncate(fd_pidfile, 0) );
+			if (ftruncate(fd_pidfile, 0))
+				err(EXIT_FAILURE, _("could not truncate file: %s"), pidfile_path);
 			write_all(fd_pidfile, reply_buf, strlen(reply_buf));
 			if (fd_pidfile > 1)
-				close(fd_pidfile); /* Unlock the pid file */
+				if (close_fd(fd_pidfile) != 0) /* Unlock the pid file */
+					err(EXIT_FAILURE, _("write failed: %s"), pidfile_path);
 		}
 
 	}
-- 
1.9.3


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

* [PATCH 2/4] uuidd: set options to be mutually exclusive
  2014-05-25 10:59 [PATCH 1/4] uuidd: ensure pid file is wrote when it is requested Sami Kerola
@ 2014-05-25 10:59 ` Sami Kerola
  2014-05-26  9:50   ` Karel Zak
  2014-05-25 10:59 ` [PATCH 3/4] uuidgen: use type definitions from uuid.h Sami Kerola
  2014-05-25 10:59 ` [PATCH 4/4] uuidd: do not mix signed type and unsigned code Sami Kerola
  2 siblings, 1 reply; 6+ messages in thread
From: Sami Kerola @ 2014-05-25 10:59 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

--pid     || --no-pid
--debug   || --quiet
--timeout || --socket-activation
--random  || --time

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/uuidd.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index 5730919..1f4a38b 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -37,6 +37,7 @@ extern int optind;
 #include "c.h"
 #include "closestream.h"
 #include "strutils.h"
+#include "optutils.h"
 
 #ifdef HAVE_LIBSYSTEMD
 # include <systemd/sd-daemon.h>
@@ -510,6 +511,14 @@ int main(int argc, char **argv)
 		{"help", no_argument, NULL, 'h'},
 		{NULL, 0, NULL, 0}
 	};
+	static const ul_excl_t excl[] = {
+		{ 'P', 'p' },
+		{ 'S', 'T' },
+		{ 'd', 'q' },
+		{ 'r', 't' },
+		{ 0 }
+	};
+	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -519,6 +528,7 @@ int main(int argc, char **argv)
 	while ((c =
 		getopt_long(argc, argv, "p:s:T:krtn:PFSdqVh", longopts,
 			    NULL)) != -1) {
+		err_exclusive_options(c, longopts, excl, excl_st);
 		switch (c) {
 		case 'd':
 			uuidd_cxt.debug = 1;
@@ -576,9 +586,6 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (no_pid && pidfile_path_param && !uuidd_cxt.quiet)
-		warnx(_("Both --pid and --no-pid specified. Ignoring --no-pid."));
-
 	if (!no_pid && !pidfile_path_param)
 		pidfile_path = UUIDD_PIDFILE_PATH;
 	else if (pidfile_path_param)
-- 
1.9.3


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

* [PATCH 3/4] uuidgen: use type definitions from uuid.h
  2014-05-25 10:59 [PATCH 1/4] uuidd: ensure pid file is wrote when it is requested Sami Kerola
  2014-05-25 10:59 ` [PATCH 2/4] uuidd: set options to be mutually exclusive Sami Kerola
@ 2014-05-25 10:59 ` Sami Kerola
  2014-05-25 10:59 ` [PATCH 4/4] uuidd: do not mix signed type and unsigned code Sami Kerola
  2 siblings, 0 replies; 6+ messages in thread
From: Sami Kerola @ 2014-05-25 10:59 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

There is no need to re-invent wheel.

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

diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 450e26a..0c844d2 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -26,9 +26,6 @@ extern int optind;
 #include "c.h"
 #include "closestream.h"
 
-#define DO_TYPE_TIME	1
-#define DO_TYPE_RANDOM	2
-
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
 	fputs(_("\nUsage:\n"), out);
@@ -68,10 +65,10 @@ main (int argc, char *argv[])
 	while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
 		switch (c) {
 		case 't':
-			do_type = DO_TYPE_TIME;
+			do_type = UUID_TYPE_DCE_TIME;
 			break;
 		case 'r':
-			do_type = DO_TYPE_RANDOM;
+			do_type = UUID_TYPE_DCE_RANDOM;
 			break;
 		case 'V':
 			printf(UTIL_LINUX_VERSION);
@@ -83,10 +80,10 @@ main (int argc, char *argv[])
 		}
 
 	switch (do_type) {
-	case DO_TYPE_TIME:
+	case UUID_TYPE_DCE_TIME:
 		uuid_generate_time(uu);
 		break;
-	case DO_TYPE_RANDOM:
+	case UUID_TYPE_DCE_RANDOM:
 		uuid_generate_random(uu);
 		break;
 	default:
-- 
1.9.3


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

* [PATCH 4/4] uuidd: do not mix signed type and unsigned code
  2014-05-25 10:59 [PATCH 1/4] uuidd: ensure pid file is wrote when it is requested Sami Kerola
  2014-05-25 10:59 ` [PATCH 2/4] uuidd: set options to be mutually exclusive Sami Kerola
  2014-05-25 10:59 ` [PATCH 3/4] uuidgen: use type definitions from uuid.h Sami Kerola
@ 2014-05-25 10:59 ` Sami Kerola
  2 siblings, 0 replies; 6+ messages in thread
From: Sami Kerola @ 2014-05-25 10:59 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Both the strtou32_or_err() and alarm() expect timeout to be unsigned.

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

diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index 1f4a38b..f728e2e 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -59,7 +59,7 @@ extern int optind;
 
 /* server loop control structure */
 struct uuidd_cxt_t {
-	int	timeout;
+	uint32_t	timeout;
 	unsigned int	debug: 1,
 			quiet: 1,
 			no_fork: 1,
@@ -366,7 +366,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
 
 	while (1) {
 		fromlen = sizeof(from_addr);
-		if (uuidd_cxt->timeout > 0)
+		if (uuidd_cxt->timeout != 0)
 			alarm(uuidd_cxt->timeout);
 		ns = accept(s, (struct sockaddr *) &from_addr, &fromlen);
 		alarm(0);
-- 
1.9.3


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

* Re: [PATCH 2/4] uuidd: set options to be mutually exclusive
  2014-05-25 10:59 ` [PATCH 2/4] uuidd: set options to be mutually exclusive Sami Kerola
@ 2014-05-26  9:50   ` Karel Zak
  2014-05-26 15:49     ` Sami Kerola
  0 siblings, 1 reply; 6+ messages in thread
From: Karel Zak @ 2014-05-26  9:50 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, May 25, 2014 at 11:59:38AM +0100, Sami Kerola wrote:
> --pid     || --no-pid
> --debug   || --quiet
> --timeout || --socket-activation

 timeout and socket-activation are not mutually exclusive

    Karel

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

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

* Re: [PATCH 2/4] uuidd: set options to be mutually exclusive
  2014-05-26  9:50   ` Karel Zak
@ 2014-05-26 15:49     ` Sami Kerola
  0 siblings, 0 replies; 6+ messages in thread
From: Sami Kerola @ 2014-05-26 15:49 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

On 26 May 2014 10:50, Karel Zak <kzak@redhat.com> wrote:
> On Sun, May 25, 2014 at 11:59:38AM +0100, Sami Kerola wrote:
>> --pid     || --no-pid
>> --debug   || --quiet
>> --timeout || --socket-activation
>
>  timeout and socket-activation are not mutually exclusive

That exclusion is removed, and should be merged from my branch 'uuid'.

https://github.com/kerolasa/lelux-utiliteetit/commit/e4faf6484719061f41624d135beb93ca821045c6

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

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

end of thread, other threads:[~2014-05-26 15:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-25 10:59 [PATCH 1/4] uuidd: ensure pid file is wrote when it is requested Sami Kerola
2014-05-25 10:59 ` [PATCH 2/4] uuidd: set options to be mutually exclusive Sami Kerola
2014-05-26  9:50   ` Karel Zak
2014-05-26 15:49     ` Sami Kerola
2014-05-25 10:59 ` [PATCH 3/4] uuidgen: use type definitions from uuid.h Sami Kerola
2014-05-25 10:59 ` [PATCH 4/4] uuidd: do not mix signed type and unsigned code Sami Kerola

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