All of lore.kernel.org
 help / color / mirror / Atom feed
From: Doug Goldstein <cardoe@cardoe.com>
To: Roger Pau Monne <roger.pau@citrix.com>, xen-devel@lists.xenproject.org
Subject: Re: [PATCH 1/2] libxl: fix _SC_GETPW_R_SIZE_MAX usage
Date: Tue, 12 Jan 2016 21:19:38 -0600	[thread overview]
Message-ID: <5695C24A.80903@cardoe.com> (raw)
In-Reply-To: <1452604467-65746-2-git-send-email-roger.pau@citrix.com>


[-- Attachment #1.1: Type: text/plain, Size: 1938 bytes --]

On 1/12/16 7:14 AM, Roger Pau Monne wrote:
> According to the FreeBSD sysconf man page [0] if the variable is associated
> with functionality that is not supported, -1 is returned and errno is not
> modified. Modify libxl__dm_runas_helper so it's able to correctly
> deal with this situation by setting the initial buffer value to 2048.
> 
> [0] https://www.freebsd.org/cgi/man.cgi?query=sysconf
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
>  tools/libxl/libxl_dm.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
> index 0aaefd9..ec8fb51 100644
> --- a/tools/libxl/libxl_dm.c
> +++ b/tools/libxl/libxl_dm.c
> @@ -728,7 +728,14 @@ static int libxl__dm_runas_helper(libxl__gc *gc, const char *username)
>      long buf_size;
>      int ret;
>  
> +    errno = 0;
>      buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
> +    if (buf_size < 0 && errno == 0) {
> +        buf_size = 2048;
> +        LOG(DEBUG,
> +"sysconf(_SC_GETPW_R_SIZE_MAX) is not supported, using a buffer size of %ld",
> +            buf_size);
> +    }
>      if (buf_size < 0) {
>          LOGE(ERROR, "sysconf(_SC_GETPW_R_SIZE_MAX) returned error %ld",
>                  buf_size);
> 

So on Linux the behavior is somewhat similar [1]. But I took a peek at
the libvirt code for doing the similar thing and I notice that they just
default if the value is returned as less than 0 [2]. Reading both man
pages it seems like that would be the better bet instead of failing how
the current code is. Your fix probably makes it fail less but it could
still error out senselessly. Just a suggestion for an improvement overall.

[1] http://man7.org/linux/man-pages/man3/sysconf.3.html#RETURN_VALUE
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/virutil.c;h=bb9604a0c1ffb9c99e454e84878a8c376f773046;hb=HEAD#l935

-- 
Doug Goldstein


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 959 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-01-13  3:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 13:14 [PATCH 0/2] libxl: FreeBSD fixes Roger Pau Monne
2016-01-12 13:14 ` [PATCH 1/2] libxl: fix _SC_GETPW_R_SIZE_MAX usage Roger Pau Monne
2016-01-13  3:19   ` Doug Goldstein [this message]
2016-01-13  9:08     ` Roger Pau Monné
2016-01-15 10:16       ` Ian Campbell
2016-01-12 13:14 ` [PATCH 2/2] libxl: fix UUID usage on FreeBSD Roger Pau Monne
2016-01-15 10:26   ` Ian Campbell
2016-01-15 15:11     ` Roger Pau Monné
2016-01-15 15:26       ` Ian Campbell
2016-01-19 18:40         ` Ian Jackson
2016-01-12 14:54 ` [PATCH 0/2] libxl: FreeBSD fixes Roger Pau Monné

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=5695C24A.80903@cardoe.com \
    --to=cardoe@cardoe.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.