[PATCH 1/4] tests: add sethostname.test

Dmitry V. Levin ldv at altlinux.org
Sat Apr 2 02:00:13 UTC 2016


On Thu, Mar 31, 2016 at 04:06:49PM +0800, Fei Jie wrote:
> * tests/sethostname.c: New file.
> * tests/sethostname.test: New test.
> * tests/.gitignore: Add sethostname.
> * tests/Makefile.am (check_PROGRAMS): Likewise.
> (DECODER_TESTS): Add sethostname.test.
> ---
>  tests/.gitignore       |  1 +
>  tests/Makefile.am      |  2 ++
>  tests/sethostname.c    | 38 ++++++++++++++++++++++++++++++++++++++
>  tests/sethostname.test |  6 ++++++
>  4 files changed, 47 insertions(+)
>  create mode 100644 tests/sethostname.c
>  create mode 100755 tests/sethostname.test
> 
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 92ab696..b709f49 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -118,6 +118,7 @@ select
>  sendfile
>  sendfile64
>  set_ptracer_any
> +sethostname
>  sigaction
>  sigaltstack
>  signalfd
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 29d7873..98be3a4 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -167,6 +167,7 @@ check_PROGRAMS = \
>  	sendfile \
>  	sendfile64 \
>  	set_ptracer_any \
> +	sethostname \
>  	sigaction \
>  	sigaltstack \
>  	signalfd \
> @@ -343,6 +344,7 @@ DECODER_TESTS = \
>  	select.test \
>  	sendfile.test \
>  	sendfile64.test \
> +	sethostname.test \
>  	sigaction.test \
>  	sigaltstack.test \
>  	signalfd.test \
> diff --git a/tests/sethostname.c b/tests/sethostname.c
> new file mode 100644
> index 0000000..8b4eca2
> --- /dev/null
> +++ b/tests/sethostname.c
> @@ -0,0 +1,38 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_sethostname
> +
> +# include <errno.h>
> +# include <stdio.h>
> +# include <sys/utsname.h>

There is no need to include <sys/utsname.h> because...

> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	static const char *hostname = NULL;
> +	int rc = syscall(__NR_sethostname, hostname, _UTSNAME_LENGTH - 1);

... _UTSNAME_LENGTH cannot be used anyway: it's a constant internal to glibc.

also, there is no need to declare hostname pointer static.

Otherwise OK, applied with these corrections.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160402/a5a3bb25/attachment.bin>


More information about the Strace-devel mailing list