public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 1/1] syscalls/mq_unlink: convert to use new test library API
Date: Mon, 5 Dec 2016 14:09:56 +0100	[thread overview]
Message-ID: <20161205130955.GC22344@rei.lan> (raw)
In-Reply-To: <20161202141251.26121-1-pvorel@suse.cz>

Hi!
>  enum test_type {
>  	NORMAL,
>  };

Hmm enum of a single value does not really make any sense and the ttype
looks unused anway. Shouldn't we just remove it?

> +void setup(void)
> +{
> +	euid = geteuid();
> +}
>  
> -static int do_test(struct test_case *tc)
> +static void do_test(unsigned int i)
>  {
> -	int sys_ret;
> -	int sys_errno;
> -	int result = RESULT_OK;
> -	int rc, fd1 = -1, fd2 = -1;
> -	uid_t old_uid = -1;
> +	struct test_case *tc = &tcase[i];
> +	mqd_t fd;
> +	struct passwd *pw;
> +
> +	tst_res(TINFO, "queue name '%s'", tc->qname);
>  
>  	/*
>  	 * When test ended with SIGTERM etc, mq descriptor is left remains.
>  	 * So we delete it first.
>  	 */
> -	TEST(mq_unlink(QUEUE_NAME));
> +	mq_unlink(QUEUE_NAME);
>  
> -	/*
> -	 * Open message queue
> -	 */
> -	rc = mq_open(QUEUE_NAME, O_CREAT | O_EXCL | O_RDWR, S_IRWXU, NULL);
> -	if (rc == -1) {
> -		tst_resm(TFAIL | TTERRNO, "mq_open failed");
> -		result = 1;
> +	/* prepare */
> +	fd = mq_open(QUEUE_NAME, O_CREAT | O_EXCL | O_RDWR, S_IRWXU, NULL);
> +	if (fd == -1) {
> +		tst_res(TFAIL | TTERRNO, "mq_open failed");
                        ^
			This should rather be TBROK | TERRNO

>  		goto EXIT;
>  	}
> -	fd1 = rc;
>  
> -	/*
> -	 * Change effective user id
> -	 */
>  	if (tc->user != NULL) {
> -		TEST(rc = setup_euid(tc->user, &old_uid));
> -		if (TEST_RETURN < 0) {
> -			result = 1;
> +		pw = getpwnam(tc->user);
> +		if (!pw) {
> +			tst_res(TFAIL | TTERRNO, "getpwnam failed");
>  			goto EXIT;
>  		}
> -	}
>  
> -	/*
> -	 * Execute system call
> -	 */
> -	errno = 0;
> -	TEST(sys_ret = mq_unlink(tc->qname));
> -	sys_errno = errno;
> -	if (sys_ret >= 0)
> -		fd2 = sys_ret;
> +		if (seteuid(pw->pw_uid)) {
> +			tst_res(TFAIL | TTERRNO, "seteuid failed");
                                  ^
				  Here again TBROK | TERRNO
> +			goto EXIT;
> +		}
> +	}

The getpwnam should be done once in the setup (with SAFE_GETPWNAM()) and
instead of the username we should add a flag as_nobody in the test
structure. We may also run the test for nobody in a child process so
that we don't have to take care restoring the euid at the end of the
function.


Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

      parent reply	other threads:[~2016-12-05 13:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 14:12 [LTP] [PATCH v4 1/1] syscalls/mq_unlink: convert to use new test library API Petr Vorel
2016-12-02 20:33 ` Petr Vorel
2016-12-05 13:09 ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161205130955.GC22344@rei.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox