Re: [PATCH 5/6] renice: fix numeric uid argument parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Sep 06, 2014 at 12:24:52PM +0100, Sami Kerola wrote:
>  		if (which == PRIO_USER) {
> -			register struct passwd *pwd = getpwnam(*argv);
> +			struct passwd *pwd = getpwnam(*argv);
>  
> -			if (pwd == NULL) {
> -				warnx(_("unknown user %s"), *argv);
> -				errs = 1;
> -				continue;
> +			if (pwd != NULL)
> +				who = pwd->pw_uid;
> +			else {
> +				error_msg = _("unknown user %s");
> +				goto numeric_pid;
>  			}
> -			who = pwd->pw_uid;
>  		} else {
> +			error_msg = _("bad value %s");
> + numeric_pid:
>  			who = strtol(*argv, &endptr, 10);
>  			if (who < 0 || *endptr) {
> -				warnx(_("bad value %s"), *argv);
> +				warnx(error_msg, *argv);
>  				errs = 1;
>  				continue;
>  			}

 The goto is unnecessary. Just set who = -1 by default.

  who = -1;
  if (which == PRIO_USER) {
        ...
        who = pwd->pw_uid;
  }

  if (who < 0) {
        who = strtol(*argv, &endptr, 10);
        ...
        if (who < 0 || *endptr)
            warnx(_("failed to parse %s argument"), idtype[which]);
  }


    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux