X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-config.c;h=aaa0372cd9bd3b4434dfe26e13d29154db260342;hp=248149c85de0ee0401816537ce84b1adad5a88f0;hb=6c7ec294bbe5ae4c3e1498b5061103f08076e016;hpb=6bd01e1b340f6a209dde64471bc9d7137511dada diff --git a/notmuch-config.c b/notmuch-config.c index 248149c8..aaa0372c 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -80,8 +80,17 @@ get_name_from_passwd_file (void *ctx) char *pw_buf = talloc_zero_size (ctx, pw_buf_size); struct passwd passwd, *ignored; char *name; + int e; - if (getpwuid_r (getuid (), &passwd, pw_buf, pw_buf_size, &ignored) == 0) { + if (pw_buf_size == -1) pw_buf_size = 64; + + while ((e = getpwuid_r (getuid (), &passwd, pw_buf, + pw_buf_size, &ignored)) == ERANGE) { + pw_buf_size = pw_buf_size * 2; + pw_buf = talloc_zero_size(ctx, pw_buf_size); + } + + if (e == 0) { char *comma = strchr (passwd.pw_gecos, ','); if (comma) name = talloc_strndup (ctx, passwd.pw_gecos, @@ -104,8 +113,16 @@ get_username_from_passwd_file (void *ctx) char *pw_buf = talloc_zero_size (ctx, pw_buf_size); struct passwd passwd, *ignored; char *name; + int e; + + if (pw_buf_size == -1) pw_buf_size = 64; + while ((e = getpwuid_r (getuid (), &passwd, pw_buf, + pw_buf_size, &ignored)) == ERANGE) { + pw_buf_size = pw_buf_size * 2; + pw_buf = talloc_zero_size(ctx, pw_buf_size); + } - if (getpwuid_r (getuid (), &passwd, pw_buf, pw_buf_size, &ignored) == 0) + if (e == 0) name = talloc_strdup (ctx, passwd.pw_name); else name = talloc_strdup (ctx, ""); @@ -190,9 +207,11 @@ notmuch_config_open (void *ctx, fprintf (stderr, "Error reading configuration file %s: %s\n", config->filename, error->message); talloc_free (config); + g_error_free (error); return NULL; } + g_error_free (error); is_new = 1; } @@ -291,6 +310,7 @@ notmuch_config_save (notmuch_config_t *config) if (! g_file_set_contents (config->filename, data, length, &error)) { fprintf (stderr, "Error saving configuration to %s: %s\n", config->filename, error->message); + g_error_free (error); return 1; }