diff options
author | Branden Robinson <branden@debian.org> | 2010-01-05 16:40:21 +0000 |
---|---|---|
committer | Julien Cristau <jcristau@debian.org> | 2010-01-12 18:08:17 +0000 |
commit | 5222d28e8d8e5b4cc705f1a637aace405ad32bd5 (patch) | |
tree | 550bc7608826ee3051345b0f4bdc0425b5c46a08 | |
parent | 17105faffcb4533da71f0d3d17fd40a64b6faf50 (diff) |
improve error logging
Make several LogError() and Debug() messages more informative.
Change LogError() invocations to use _SysErrorMsg() where errno might be set
(and not clobbered by intermediate calls). Also make LogError() the first
thing we do after an error condition in those cases.
Forward-ported by Julien Cristau <jcristau@debian.org>.
Signed-off-by: Julien Cristau <jcristau@debian.org>
Reviewed-by: Alan Coopersmith <alan.coopersmith@sun.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
-rw-r--r-- | auth.c | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -403,6 +403,7 @@ SaveServerAuthorizations ( int i; const char dummy_auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "XXXXXXXXXXXXXXXXX"; /* 64 "X"s */ + int err = 0; mask = umask (0077); ret = MakeServerAuthFile(d, &auth_file); @@ -410,10 +411,8 @@ SaveServerAuthorizations ( if (!ret) return FALSE; if (!auth_file) { - Debug ("Can't creat auth file %s\n", d->authFile); - LogError ("Cannot open server authorization file %s\n", d->authFile); - free (d->authFile); - d->authFile = NULL; + LogError ("cannot open server authorization file %s: %s\n", + d->authFile, _SysErrorMsg (errno)); ret = FALSE; } else @@ -436,8 +435,7 @@ SaveServerAuthorizations ( (void) fflush (auth_file); if (ferror (auth_file)) { - LogError ("Cannot write server authorization file %s\n", - d->authFile); + err = errno; ret = FALSE; } /* @@ -453,14 +451,15 @@ SaveServerAuthorizations ( * to the auth file so xrdb and setup programs don't fail. */ if (auths[i]->data_length > 0) - if (!XauWriteAuth (auth_file, auths[i]) || - fflush (auth_file) == EOF) + if (!XauWriteAuth (auth_file, auths[i])) + { + Debug ("XauWriteAuth() failed\n"); + } + (void) fflush (auth_file); + if (ferror (auth_file)) { - LogError ("Cannot write server authorization file %s\n", - d->authFile); + err = errno; ret = FALSE; - free (d->authFile); - d->authFile = NULL; } } /* @@ -471,6 +470,16 @@ SaveServerAuthorizations ( Debug ("ftruncate() failed\n"); } fclose (auth_file); + + } + if (ret == FALSE) + { + LogError ("Cannot write to server authorization file %s%s%s\n", + d->authFile, + err ? ": " : "", + err ? _SysErrorMsg (errno) : ""); + free (d->authFile); + d->authFile = NULL; } return ret; } |