* [PATCH 1/8] last: display input file in usage() according to command name
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-13 11:29 ` [PATCH 2/8] nologin: require /etc/nologin.txt to be file Sami Kerola
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Default depends on whether the executable is called 'lastb' or something
else.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/last.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 8d82c10..dbfa8ae 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -543,7 +543,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(const struct last_control *ctl, FILE *out)
{
fputs(USAGE_HEADER, out);
fprintf(out, _(
@@ -557,7 +557,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -a, --hostlast display hostnames in the last column\n"), out);
fputs(_(" -d, --dns translate the IP number back into a hostname\n"), out);
fprintf(out,
- _(" -f, --file <file> use a specific file instead of %s\n"), _PATH_WTMP);
+ _(" -f, --file <file> use a specific file instead of %s\n"), ctl->lastb ? _PATH_BTMP : _PATH_WTMP);
fputs(_(" -F, --fulltimes print full login and logout times and dates\n"), out);
fputs(_(" -i, --ip display IP numbers in numbers-and-dots notation\n"), out);
fputs(_(" -n, --limit <number> how many lines to show\n"), out);
@@ -911,7 +911,10 @@ int main(int argc, char **argv)
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
-
+ /*
+ * Which file do we want to read?
+ */
+ ctl.lastb = strcmp(program_invocation_short_name, "lastb") == 0 ? 1 : 0;
while ((c = getopt_long(argc, argv,
"hVf:n:RxadFit:p:s:0123456789w", long_opts, NULL)) != -1) {
@@ -919,7 +922,7 @@ int main(int argc, char **argv)
switch(c) {
case 'h':
- usage(stdout);
+ usage(&ctl, stdout);
break;
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -979,7 +982,7 @@ int main(int argc, char **argv)
ctl.time_fmt = which_time_format(optarg);
break;
default:
- usage(stderr);
+ usage(&ctl, stderr);
break;
}
}
@@ -987,10 +990,6 @@ int main(int argc, char **argv)
if (optind < argc)
ctl.show = argv + optind;
- /*
- * Which file do we want to read?
- */
- ctl.lastb = strcmp(program_invocation_short_name, "lastb") == 0 ? 1 : 0;
if (!files) {
files = xmalloc(sizeof(char *));
files[nfiles++] = xstrdup(ctl.lastb ? _PATH_BTMP : _PATH_WTMP);
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 2/8] nologin: require /etc/nologin.txt to be file
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
2015-10-13 11:29 ` [PATCH 1/8] last: display input file in usage() according to command name Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-13 11:29 ` [PATCH 3/8] libuuid: add uuid_generate_file() function Sami Kerola
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
This makes silly practical jokes impossible, like for example symlinking
/dev/null or dev/random to /etc/nologin.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/nologin.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/login-utils/nologin.c b/login-utils/nologin.c
index 3be50ca..0a06ef8 100644
--- a/login-utils/nologin.c
+++ b/login-utils/nologin.c
@@ -3,6 +3,7 @@
*/
#include <stdio.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
@@ -38,6 +39,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
int main(int argc, char *argv[])
{
int c, fd;
+ struct stat st;
static const struct option longopts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
@@ -63,7 +65,8 @@ int main(int argc, char *argv[])
}
fd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
- if (fd >= 0) {
+ c = fstat(fd, &st);
+ if (fd >= 0 && !c && S_ISREG(st.st_mode)) {
char buf[BUFSIZ];
ssize_t rd;
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/8] libuuid: add uuid_generate_file() function
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
2015-10-13 11:29 ` [PATCH 1/8] last: display input file in usage() according to command name Sami Kerola
2015-10-13 11:29 ` [PATCH 2/8] nologin: require /etc/nologin.txt to be file Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-16 9:18 ` Karel Zak
2015-10-13 11:29 ` [PATCH 4/8] tests: add uuidgen check Sami Kerola
` (4 subsequent siblings)
7 siblings, 1 reply; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
The uuid_generate_file() allows generating UUID using input file, and thus
leading to stable output. Purpose of this function is to have a facility
that allows tests to be wrote.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
libuuid/man/uuid_generate.3 | 11 +++++++++++
libuuid/src/gen_uuid.c | 21 +++++++++++++++++++++
libuuid/src/libuuid.sym | 8 ++++++++
libuuid/src/uuid.h | 2 ++
4 files changed, 42 insertions(+)
diff --git a/libuuid/man/uuid_generate.3 b/libuuid/man/uuid_generate.3
index 19904d7..53045c0 100644
--- a/libuuid/man/uuid_generate.3
+++ b/libuuid/man/uuid_generate.3
@@ -41,6 +41,7 @@ uuid_generate_time_safe \- create a new unique UUID value
.BI "void uuid_generate_random(uuid_t " out );
.BI "void uuid_generate_time(uuid_t " out );
.BI "int uuid_generate_time_safe(uuid_t " out );
+.BI "int uuid_generate_file(uuid_t " out ", const char " *path ");"
.fi
.SH DESCRIPTION
The
@@ -100,11 +101,21 @@ the universe according to Carl Sagan's
The new UUID can reasonably be considered unique among all UUIDs created
on the local system, and among UUIDs created on other systems in the past
and in the future.
+.sp
+The
+.B uuid_generate_file
+function will read up to 16 bytes from beginning of a file as a not-random
+source of UUID. Purpose of this function is to provide a facility that will
+always return the same UUID, and thus is ideal for testing.
.SH RETURN VALUE
The newly created UUID is returned in the memory location pointed to by
.IR out .
.B uuid_generate_time_safe
returns zero if the UUID has been generated in a safe manner, \-1 otherwise.
+The
+.B uuid_generate_file
+will return zero for success, or 1 when errno indicates an error with file
+defined by path.
.SH "CONFORMING TO"
OSF DCE 1.1
.SH AUTHOR
diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c
index 4d60997..cf164fb 100644
--- a/libuuid/src/gen_uuid.c
+++ b/libuuid/src/gen_uuid.c
@@ -551,3 +551,24 @@ void uuid_generate(uuid_t out)
else
uuid_generate_time(out);
}
+
+/*
+ * Generate file-based UUID and store it to @out. Useful for testing.
+ *
+ */
+int uuid_generate_file(uuid_t out, const char *path)
+{
+ int fd;
+ uuid_t buf = { 0 };
+ struct uuid uu = { 0 };
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return 1;
+ if ((read(fd, &buf, sizeof(buf))) < 0)
+ return 1;
+ close(fd);
+ uuid_unpack(buf, &uu);
+ uuid_pack(&uu, out);
+ return 0;
+}
diff --git a/libuuid/src/libuuid.sym b/libuuid/src/libuuid.sym
index 28a2076..ead4046 100644
--- a/libuuid/src/libuuid.sym
+++ b/libuuid/src/libuuid.sym
@@ -34,6 +34,14 @@ global:
uuid_generate_time_safe;
} UUID_1.0;
+/*
+ * version(s) since util-linux 2.28
+ */
+UUID_2.28 {
+global:
+ uuid_generate_file;
+} UUID_2.20;
+
/*
* __uuid_* this is not part of the official API, this is
diff --git a/libuuid/src/uuid.h b/libuuid/src/uuid.h
index 30bd4c0..f3f117a 100644
--- a/libuuid/src/uuid.h
+++ b/libuuid/src/uuid.h
@@ -52,6 +52,7 @@ typedef unsigned char uuid_t[16];
/* UUID Type definitions */
#define UUID_TYPE_DCE_TIME 1
#define UUID_TYPE_DCE_RANDOM 4
+#define UUID_TYPE_DCE_FILE 8
/* Allow UUID constants to be defined */
#ifdef __GNUC__
@@ -80,6 +81,7 @@ extern void uuid_generate(uuid_t out);
extern void uuid_generate_random(uuid_t out);
extern void uuid_generate_time(uuid_t out);
extern int uuid_generate_time_safe(uuid_t out);
+extern int uuid_generate_file(uuid_t out, const char *path);
/* isnull.c */
extern int uuid_is_null(const uuid_t uu);
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 3/8] libuuid: add uuid_generate_file() function
2015-10-13 11:29 ` [PATCH 3/8] libuuid: add uuid_generate_file() function Sami Kerola
@ 2015-10-16 9:18 ` Karel Zak
0 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2015-10-16 9:18 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Tue, Oct 13, 2015 at 12:29:09PM +0100, Sami Kerola wrote:
> The uuid_generate_file() allows generating UUID using input file, and thus
> leading to stable output. Purpose of this function is to have a facility
> that allows tests to be wrote.
Well, if you want to generate non-random stuff then it seems enough
to modify __uuid_generate_random() and __uuid_generate_time()
to return non-random stuff on -DLIBUUID_ENABLE_TEST.
The problem is that things like get_clock(), pack, unpack, parse and
unparse functions will be still untested.
What about to support random UUIDs in our tests and modify
the __uuid_generate functions to copy unpacked raw result to any
file? Something like:
int __uuid_generate_time(uuid_t out, int *num)
{
... generate struct uu as usually ...
#ifdef LIBUUID_ENABLE_TEST
ts_path = genenv("LIBUUID_TEST_PATH");
if (ts_path)
write_raw_uuid(uu, ts_path);
#endif
return ret;
}
where write_uraw_uuid() is function to write struct uuid to the
<ts_path>/<pid>.
Then we can write
test_uuid --random|--time <file>
this program
1/ ask libuuid for a new UUID
2/ unparse and unpack to get struct uuid
3/ write struct uuid to the <file> by write_uraw_uuid()
and in the shell script we can by diff -u compare $LIBUUID_TEST_PATH/<pid>
with <file>.
The <pid> is also possible to use to check if UUID has been really
generated by uuidd. (It would be nice to have two sub-tests, one with
uuidd and one without uuid.)
Note that uuid_unpack() is not exported by library API, so you have to
link libuuid/src/unpack.c directly to the test_uuid.c.
(It would be also possible to analyze struct uuid from
$LIBUUID_TEST_PATH to make sure that for example get_node_id() works
as expected, etc... but this is not urgent.)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/8] tests: add uuidgen check
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
` (2 preceding siblings ...)
2015-10-13 11:29 ` [PATCH 3/8] libuuid: add uuid_generate_file() function Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-13 11:29 ` [PATCH 5/8] tests: add uuidd check Sami Kerola
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=yes, Size: 5579 bytes --]
This check will try functionality of uuidgen, leaving out the validation
uuid's are truly unique.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/Makemodule.am | 5 +++++
misc-utils/uuidgen.c | 24 ++++++++++++++++++++++++
tests/commands.sh | 1 +
tests/expected/uuid/uuidgen | 6 ++++++
tests/ts/uuid/0x00000000 | Bin 0 -> 16 bytes
tests/ts/uuid/0xdeadbeef | 1 +
tests/ts/uuid/0xffffffff | 1 +
tests/ts/uuid/uuidgen | 30 ++++++++++++++++++++++++++++++
8 files changed, 68 insertions(+)
create mode 100644 tests/expected/uuid/uuidgen
create mode 100644 tests/ts/uuid/0x00000000
create mode 100644 tests/ts/uuid/0xdeadbeef
create mode 100644 tests/ts/uuid/0xffffffff
create mode 100755 tests/ts/uuid/uuidgen
diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
index e7949d0..2fbaa01 100644
--- a/misc-utils/Makemodule.am
+++ b/misc-utils/Makemodule.am
@@ -85,6 +85,11 @@ dist_man_MANS += misc-utils/uuidgen.1
uuidgen_SOURCES = misc-utils/uuidgen.c
uuidgen_LDADD = $(LDADD) libuuid.la
uuidgen_CFLAGS = $(AM_CFLAGS) -I$(ul_libuuid_incdir)
+
+check_PROGRAMS += test_uuidgen
+test_uuidgen_SOURCES = $(uuidgen_SOURCES)
+test_uuidgen_LDADD = $(uuidgen_LDADD)
+test_uuidgen_CFLAGS = -DTEST_UUIDGEN $(uuidgen_CFLAGS)
endif
if BUILD_UUIDD
diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 40b00ff..912b4a9 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -28,6 +28,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(_("Create a new UUID value.\n"), out);
fputs(USAGE_OPTIONS, out);
+#ifdef TEST_UUIDGEN
+ fputs( " --file <file> generate <file> based uuid", out);
+#endif
fputs(_(" -r, --random generate random-based uuid\n"
" -t, --time generate time-based uuid\n"
" -V, --version output version information and exit\n"
@@ -44,8 +47,17 @@ main (int argc, char *argv[])
int do_type = 0;
char str[37];
uuid_t uu;
+#ifdef TEST_UUIDGEN
+ char *file;
+ enum {
+ OPT_FILE = CHAR_MAX + 1
+ };
+#endif
static const struct option longopts[] = {
+#ifdef TEST_UUIDGEN
+ {"file", required_argument, NULL, OPT_FILE},
+#endif
{"random", no_argument, NULL, 'r'},
{"time", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'V'},
@@ -60,6 +72,12 @@ main (int argc, char *argv[])
while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
switch (c) {
+#ifdef TEST_UUIDGEN
+ case OPT_FILE:
+ do_type = UUID_TYPE_DCE_FILE;
+ file = optarg;
+ break;
+#endif
case 't':
do_type = UUID_TYPE_DCE_TIME;
break;
@@ -76,6 +94,12 @@ main (int argc, char *argv[])
}
switch (do_type) {
+#ifdef TEST_UUIDGEN
+ case UUID_TYPE_DCE_FILE:
+ if (uuid_generate_file(uu, file))
+ err(EXIT_FAILURE, "%s", file);
+ break;
+#endif
case UUID_TYPE_DCE_TIME:
uuid_generate_time(uu);
break;
diff --git a/tests/commands.sh b/tests/commands.sh
index 737918f..6878650 100644
--- a/tests/commands.sh
+++ b/tests/commands.sh
@@ -30,6 +30,7 @@ TS_HELPER_SCRIPT="$top_builddir/test_script"
TS_HELPER_SIGRECEIVE="$top_builddir/test_sigreceive"
TS_HELPER_STRUTILS="$top_builddir/test_strutils"
TS_HELPER_SYSINFO="$top_builddir/test_sysinfo"
+TS_HELPER_UUIDGEN="$top_builddir/test_uuidgen"
# paths to commands
TS_CMD_ADDPART=${TS_CMD_ADDPART:-"$top_builddir/addpart"}
diff --git a/tests/expected/uuid/uuidgen b/tests/expected/uuid/uuidgen
new file mode 100644
index 0000000..257e4df
--- /dev/null
+++ b/tests/expected/uuid/uuidgen
@@ -0,0 +1,6 @@
+00000000-0000-0000-0000-000000000000
+return value: 0
+deadface-cafe-babe-feed-baadbeeff00d
+return value: 0
+ffffffff-ffff-ffff-ffff-ffffffffffff
+return value: 0
diff --git a/tests/ts/uuid/0x00000000 b/tests/ts/uuid/0x00000000
new file mode 100644
index 0000000000000000000000000000000000000000..01d633b27e8ea9b17084fc911d0c8cc43a4170a9
GIT binary patch
literal 16
KcmZQzKm`B*5C8!H
literal 0
HcmV?d00001
diff --git a/tests/ts/uuid/0xdeadbeef b/tests/ts/uuid/0xdeadbeef
new file mode 100644
index 0000000..11c64c5
--- /dev/null
+++ b/tests/ts/uuid/0xdeadbeef
@@ -0,0 +1 @@
+ÞúÎÊþº¾þíº¾ïð
**
\ No newline at end of file
diff --git a/tests/ts/uuid/0xffffffff b/tests/ts/uuid/0xffffffff
new file mode 100644
index 0000000..13ff23b
--- /dev/null
+++ b/tests/ts/uuid/0xffffffff
@@ -0,0 +1 @@
+ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
\ No newline at end of file
diff --git a/tests/ts/uuid/uuidgen b/tests/ts/uuid/uuidgen
new file mode 100755
index 0000000..ec1fcaf
--- /dev/null
+++ b/tests/ts/uuid/uuidgen
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="uuidgen"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_HELPER_UUIDGEN"
+
+$TS_HELPER_UUIDGEN --file $TS_SELF/0x00000000 > $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+$TS_HELPER_UUIDGEN --file $TS_SELF/0xdeadbeef >> $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+$TS_HELPER_UUIDGEN --file $TS_SELF/0xffffffff >> $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+
+ts_finalize
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 5/8] tests: add uuidd check
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
` (3 preceding siblings ...)
2015-10-13 11:29 ` [PATCH 4/8] tests: add uuidgen check Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-13 11:29 ` [PATCH 6/8] ctrlaltdel: improve error messaging Sami Kerola
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
This check will try functionality of uuidd, leaving out the validation
uuid's are truly unique.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/Makemodule.am | 5 +++++
misc-utils/uuidd.c | 16 ++++++++++++++++
tests/commands.sh | 1 +
tests/expected/uuid/uuidd | 7 +++++++
tests/ts/uuid/uuidd | 33 +++++++++++++++++++++++++++++++++
5 files changed, 62 insertions(+)
create mode 100644 tests/expected/uuid/uuidd
create mode 100755 tests/ts/uuid/uuidd
diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
index 2fbaa01..b8e04fc 100644
--- a/misc-utils/Makemodule.am
+++ b/misc-utils/Makemodule.am
@@ -106,6 +106,11 @@ systemdsystemunit_DATA += \
misc-utils/uuidd.service \
misc-utils/uuidd.socket
endif
+
+check_PROGRAMS += test_uuidd2
+test_uuidd2_SOURCES = $(uuidd_SOURCES)
+test_uuidd2_LDADD = $(uuidd_LDADD)
+test_uuidd2_CFLAGS = -DTEST_UUIDD $(uuidd_CFLAGS)
endif # BUILD_UUIDD
PATHFILES += \
diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index 4b5bf00..03d94d7 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -331,6 +331,12 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
POLLFD_SIGNAL = 0,
POLLFD_SOCKET
};
+#ifdef TEST_UUIDD
+ const char *test_file = getenv("UUIDD_RANDOM_SOURCE");
+
+ if (!test_file)
+ errx(EXIT_FAILURE, "UUIDD_RANDOM_SOURCE: not set");
+#endif
#ifdef HAVE_LIBSYSTEMD
if (!uuidd_cxt->no_sock) /* no_sock implies no_fork and no_pid */
@@ -468,7 +474,12 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
break;
case UUIDD_OP_TIME_UUID:
num = 1;
+#ifdef TEST_UUIDD
+ if (uuid_generate_file(uu, test_file))
+ err(EXIT_FAILURE, "%s", test_file);
+#else
__uuid_generate_time(uu, &num);
+#endif
if (uuidd_cxt->debug) {
uuid_unparse(uu, str);
fprintf(stderr, _("Generated time UUID: %s\n"), str);
@@ -478,7 +489,12 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
break;
case UUIDD_OP_RANDOM_UUID:
num = 1;
+#ifdef TEST_UUIDD
+ if (uuid_generate_file(uu, test_file))
+ err(EXIT_FAILURE, "%s", test_file);
+#else
__uuid_generate_random(uu, &num);
+#endif
if (uuidd_cxt->debug) {
uuid_unparse(uu, str);
fprintf(stderr, _("Generated random UUID: %s\n"), str);
diff --git a/tests/commands.sh b/tests/commands.sh
index 6878650..ba1f738 100644
--- a/tests/commands.sh
+++ b/tests/commands.sh
@@ -30,6 +30,7 @@ TS_HELPER_SCRIPT="$top_builddir/test_script"
TS_HELPER_SIGRECEIVE="$top_builddir/test_sigreceive"
TS_HELPER_STRUTILS="$top_builddir/test_strutils"
TS_HELPER_SYSINFO="$top_builddir/test_sysinfo"
+TS_HELPER_UUIDD2="$top_builddir/test_uuidd2"
TS_HELPER_UUIDGEN="$top_builddir/test_uuidgen"
# paths to commands
diff --git a/tests/expected/uuid/uuidd b/tests/expected/uuid/uuidd
new file mode 100644
index 0000000..81ee6e4
--- /dev/null
+++ b/tests/expected/uuid/uuidd
@@ -0,0 +1,7 @@
+return value: 0
+deadface-cafe-babe-feed-baadbeeff00d
+return value: 0
+deadface-cafe-babe-feed-baadbeeff00d
+return value: 0
+Killed uuidd running at pid <num>.
+return value: 0
diff --git a/tests/ts/uuid/uuidd b/tests/ts/uuid/uuidd
new file mode 100755
index 0000000..d3f7d50
--- /dev/null
+++ b/tests/ts/uuid/uuidd
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="uuidd"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_HELPER_UUIDD2"
+
+UUIDD_RANDOM_SOURCE=$TS_SELF/0xdeadbeef $TS_HELPER_UUIDD2 --pid $TS_OUTDIR/pid --socket $TS_OUTDIR/socket > $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+$TS_HELPER_UUIDD2 --debug --random --socket $TS_OUTDIR/socket >> $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+$TS_HELPER_UUIDD2 --debug --time --socket $TS_OUTDIR/socket >> $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+$TS_HELPER_UUIDD2 --debug --kill --socket $TS_OUTDIR/socket |
+ sed 's/pid [0-9]*.$/pid <num>./' >> $TS_OUTPUT 2>&1
+echo "return value: $?" >> $TS_OUTPUT
+
+ts_finalize
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 6/8] ctrlaltdel: improve error messaging
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
` (4 preceding siblings ...)
2015-10-13 11:29 ` [PATCH 5/8] tests: add uuidd check Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-13 11:29 ` [PATCH 7/8] docs: update ctrlaltdel.8 man page Sami Kerola
2015-10-13 11:29 ` [PATCH 8/8] ctrlaltdel: display setting when ran without arguments Sami Kerola
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Tell user what is wrong rather than print usage().
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ctrlaltdel.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index 8f646e5..64de94f 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -21,7 +21,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fprintf(out, _(" %s hard|soft\n"), program_invocation_short_name);
fprintf(out, USAGE_SEPARATOR);
- fprintf(out, "Set the function of the Ctrl-Alt-Del combination.\n");
+ fprintf(out, _("Set the function of the Ctrl-Alt-Del combination.\n"));
fprintf(out, USAGE_OPTIONS);
fprintf(out, USAGE_HELP);
@@ -33,6 +33,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int main(int argc, char **argv)
{
int ch;
+ unsigned int cmd;
static const struct option longopts[] = {
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
@@ -59,15 +60,15 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE,
_("You must be root to set the Ctrl-Alt-Del behavior"));
- if (argc == 2 && !strcmp("hard", argv[1])) {
- if (my_reboot(LINUX_REBOOT_CMD_CAD_ON) < 0)
- err(EXIT_FAILURE, "reboot");
- } else if (argc == 2 && !strcmp("soft", argv[1])) {
- if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0)
- err(EXIT_FAILURE, "reboot");
- } else {
- usage(stderr);
- }
-
+ if (argc < 2)
+ errx(EXIT_FAILURE, _("not enough arguments"));
+ if (!strcmp("hard", argv[1]))
+ cmd = LINUX_REBOOT_CMD_CAD_ON;
+ else if (!strcmp("soft", argv[1]))
+ cmd = LINUX_REBOOT_CMD_CAD_OFF;
+ else
+ errx(EXIT_FAILURE, _("unknown argument: %s"), argv[1]);
+ if (my_reboot(cmd) < 0)
+ err(EXIT_FAILURE, "reboot");
return EXIT_SUCCESS;
}
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 7/8] docs: update ctrlaltdel.8 man page
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
` (5 preceding siblings ...)
2015-10-13 11:29 ` [PATCH 6/8] ctrlaltdel: improve error messaging Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
2015-10-13 11:29 ` [PATCH 8/8] ctrlaltdel: display setting when ran without arguments Sami Kerola
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Most significant clarification is to tell hard C_A_D is the default in linux
kernel. Update also kernel reference, and improve readability.
Reference: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/kernel/reboot.c
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ctrlaltdel.8 | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/sys-utils/ctrlaltdel.8 b/sys-utils/ctrlaltdel.8
index 30bbae4..4be6513 100644
--- a/sys-utils/ctrlaltdel.8
+++ b/sys-utils/ctrlaltdel.8
@@ -1,21 +1,23 @@
.\" Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
.\" May be distributed under the GNU General Public License
-.TH CTRLALTDEL 8 "August 2011" "util-linux" "System Administration"
+.TH CTRLALTDEL 8 "October 2015" "util-linux" "System Administration"
.SH NAME
ctrlaltdel \- set the function of the Ctrl-Alt-Del combination
.SH SYNOPSIS
.BR "ctrlaltdel hard" | soft
.SH DESCRIPTION
Based on examination of the
-.I linux/kernel/sys.c
+.I linux/kernel/reboot.c
code, it is clear that there are two supported functions that the
-Ctrl-Alt-Del sequence can perform: a
-.I hard
-reset, which immediately reboots the computer without calling
+Ctrl-Alt-Del sequence can perform.
+.TP
+.B hard
+Immediately reboot the computer without calling
.BR sync (2)
-and without any other preparation; and a
-.I soft
-reset, which sends the SIGINT (interrupt) signal to the
+and without any other preparation. This is the default.
+.TP
+.B soft
+Will make kernel to send the SIGINT (interrupt) signal to the
.B init
process (this is always the process with PID 1). If this option is used,
the
@@ -39,7 +41,8 @@ Display help text and exit.
.SH FILES
.I /etc/rc.local
.SH "SEE ALSO"
-.BR init (8)
+.BR init (8),
+.BR systemd (1)
.SH AUTHOR
.UR poe@daimi.aau.dk
Peter Orbaek
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 8/8] ctrlaltdel: display setting when ran without arguments
2015-10-13 11:29 [PATCH 0/8] [pull] various changes, uuid tests, ctrlaltdel improvements and so on Sami Kerola
` (6 preceding siblings ...)
2015-10-13 11:29 ` [PATCH 7/8] docs: update ctrlaltdel.8 man page Sami Kerola
@ 2015-10-13 11:29 ` Sami Kerola
7 siblings, 0 replies; 10+ messages in thread
From: Sami Kerola @ 2015-10-13 11:29 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
This is more useful than printing an error.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
include/pathnames.h | 3 +++
sys-utils/ctrlaltdel.8 | 5 +++-
sys-utils/ctrlaltdel.c | 70 +++++++++++++++++++++++++++++++++++++++-----------
3 files changed, 62 insertions(+), 16 deletions(-)
diff --git a/include/pathnames.h b/include/pathnames.h
index e68ac7d..81efcfa 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -208,5 +208,8 @@
/* logger paths */
#define _PATH_DEVLOG "/dev/log"
+/* ctrlaltdel paths */
+#define _PATH_PROC_CTRL_ALT_DEL "/proc/sys/kernel/ctrl-alt-del"
+
#endif /* PATHNAMES_H */
diff --git a/sys-utils/ctrlaltdel.8 b/sys-utils/ctrlaltdel.8
index 4be6513..170597f 100644
--- a/sys-utils/ctrlaltdel.8
+++ b/sys-utils/ctrlaltdel.8
@@ -27,8 +27,11 @@ program must support this feature. Since there are now several
programs in the Linux community, please consult the documentation for the
version that you are currently using.
.PP
+When command is ran without arguments it will display current function in
+use.
+.PP
.B ctrlaltdel
-is usually used in the
+function is usually set in the
.I /etc/rc.local
file.
.SH OPTIONS
diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index 64de94f..ffdad6a 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -14,6 +14,7 @@
#include "nls.h"
#include "c.h"
#include "closestream.h"
+#include "pathnames.h"
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -30,10 +31,59 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-int main(int argc, char **argv)
+static int get_cad(void)
+{
+ FILE *fp;
+ int val;
+
+ if (!(fp = fopen(_PATH_PROC_CTRL_ALT_DEL, "r"))) {
+ warn("%s", _PATH_PROC_CTRL_ALT_DEL);
+ return EXIT_FAILURE;
+ }
+ if (fscanf(fp, "%d", &val) != 1)
+ val = -1;
+ fclose(fp);
+ switch (val) {
+ case 0:
+ fputs("soft\n", stdout);
+ break;
+ case 1:
+ fputs("hard\n", stdout);
+ break;
+ default:
+ printf("%s hard\n", _("implicit"));
+ warnx(_("unexpected value in %s: %d"), _PATH_PROC_CTRL_ALT_DEL, val);
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+static int set_cad(const char *arg)
{
- int ch;
unsigned int cmd;
+
+ if (geteuid()) {
+ warnx(_("You must be root to set the Ctrl-Alt-Del behavior"));
+ return EXIT_FAILURE;
+ }
+ if (!strcmp("hard", arg))
+ cmd = LINUX_REBOOT_CMD_CAD_ON;
+ else if (!strcmp("soft", arg))
+ cmd = LINUX_REBOOT_CMD_CAD_OFF;
+ else {
+ warnx(_("unknown argument: %s"), arg);
+ return EXIT_FAILURE;
+ }
+ if (my_reboot(cmd) < 0) {
+ warnx("reboot");
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+int main(int argc, char **argv)
+{
+ int ch, ret;
static const struct option longopts[] = {
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
@@ -56,19 +106,9 @@ int main(int argc, char **argv)
usage(stderr);
}
- if (geteuid())
- errx(EXIT_FAILURE,
- _("You must be root to set the Ctrl-Alt-Del behavior"));
-
if (argc < 2)
- errx(EXIT_FAILURE, _("not enough arguments"));
- if (!strcmp("hard", argv[1]))
- cmd = LINUX_REBOOT_CMD_CAD_ON;
- else if (!strcmp("soft", argv[1]))
- cmd = LINUX_REBOOT_CMD_CAD_OFF;
+ ret = get_cad();
else
- errx(EXIT_FAILURE, _("unknown argument: %s"), argv[1]);
- if (my_reboot(cmd) < 0)
- err(EXIT_FAILURE, "reboot");
- return EXIT_SUCCESS;
+ ret = set_cad(argv[1]);
+ return ret;
}
--
2.6.1
^ permalink raw reply related [flat|nested] 10+ messages in thread