From: <ssm...@us...> - 2007-09-27 13:22:57
|
Revision: 2595 http://selinux.svn.sourceforge.net/selinux/?rev=2595&view=rev Author: ssmalley Date: 2007-09-27 06:21:25 -0700 (Thu, 27 Sep 2007) Log Message: ----------- applied 2570 and 2573 (improve error reporting) from trunk Modified Paths: -------------- branches/stable/1_0/libsemanage/src/debug.c branches/stable/1_0/libsemanage/src/direct_api.c branches/stable/1_0/libsemanage/src/semanage_store.c branches/stable/1_0/policycoreutils/semodule/semodule.c Modified: branches/stable/1_0/libsemanage/src/debug.c =================================================================== --- branches/stable/1_0/libsemanage/src/debug.c 2007-09-27 13:16:53 UTC (rev 2594) +++ branches/stable/1_0/libsemanage/src/debug.c 2007-09-27 13:21:25 UTC (rev 2595) @@ -23,6 +23,8 @@ #include <stdarg.h> #include <stdlib.h> #include <stdio.h> +#include <errno.h> +#include <string.h> #include "handle.h" #include "debug.h" @@ -55,10 +57,12 @@ { FILE *stream = NULL; + int errsv = 0; switch (semanage_msg_get_level(handle)) { case SEMANAGE_MSG_ERR: + errsv = errno; case SEMANAGE_MSG_WARN: stream = stderr; break; @@ -77,6 +81,9 @@ vfprintf(stream, fmt, ap); va_end(ap); + if (errsv) + fprintf(stream, " %s.", strerror(errsv)); + fprintf(stream, "\n"); varg = NULL; Modified: branches/stable/1_0/libsemanage/src/direct_api.c =================================================================== --- branches/stable/1_0/libsemanage/src/direct_api.c 2007-09-27 13:16:53 UTC (rev 2594) +++ branches/stable/1_0/libsemanage/src/direct_api.c 2007-09-27 13:21:25 UTC (rev 2595) @@ -32,6 +32,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <limits.h> +#include <errno.h> #include "user_internal.h" #include "seuser_internal.h" @@ -540,6 +541,7 @@ * checking is done because this is likely to fail because * the file does not exist - which is not an error. */ unlink(linked_filename); + errno = 0; } /* ==================== File-backed ================== */ Modified: branches/stable/1_0/libsemanage/src/semanage_store.c =================================================================== --- branches/stable/1_0/libsemanage/src/semanage_store.c 2007-09-27 13:16:53 UTC (rev 2594) +++ branches/stable/1_0/libsemanage/src/semanage_store.c 2007-09-27 13:21:25 UTC (rev 2595) @@ -432,7 +432,7 @@ * overwrite it. Returns 0 on success, -1 on error. */ static int semanage_copy_file(const char *src, const char *dst, mode_t mode) { - int in, out, retval = 0, amount_read, n; + int in, out, retval = 0, amount_read, n, errsv = errno; char tmp[PATH_MAX]; char buf[4192]; @@ -448,23 +448,32 @@ mode = S_IRUSR | S_IWUSR; if ((out = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, mode)) == -1) { + errsv = errno; close(in); - return -1; + retval = -1; + goto out; } while (retval == 0 && (amount_read = read(in, buf, sizeof(buf))) > 0) { - if (write(out, buf, amount_read) != amount_read) { + if (write(out, buf, amount_read) < 0) { + errsv = errno; retval = -1; } } - if (amount_read < 0) + if (amount_read < 0) { + errsv = errno; retval = -1; + } close(in); - if (close(out) < 0) + if (close(out) < 0) { + errsv = errno; retval = -1; + } if (!retval && rename(tmp, dst) == -1) return -1; +out: + errno = errsv; return retval; } @@ -553,12 +562,14 @@ { const char *sandbox = semanage_path(SEMANAGE_TMP, SEMANAGE_TOPLEVEL); struct stat buf; + int errsv; if (stat(sandbox, &buf) == -1) { if (errno != ENOENT) { ERR(sh, "Error scanning directory %s.", sandbox); return -1; } + errno = 0; } else { /* remove the old sandbox */ if (semanage_remove_directory(sandbox) != 0) { @@ -577,7 +588,9 @@ return 0; cleanup: + errsv = errno; semanage_remove_directory(sandbox); + errno = errsv; return -1; } @@ -968,14 +981,14 @@ if (!strncmp(buf, "HOME_DIR", 8) || !strncmp(buf, "HOME_ROOT", 9) || strstr(buf, "ROLE")) { /* This contains one of the template variables, write it to homedir.template */ - if (write(hd, buf, strlen(buf)) == 0) { + if (write(hd, buf, strlen(buf)) < 0) { ERR(sh, "Write to %s failed.", semanage_path(SEMANAGE_TMP, SEMANAGE_HOMEDIR_TMPL)); goto cleanup; } } else { - if (write(fc, buf, strlen(buf)) == 0) { + if (write(fc, buf, strlen(buf)) < 0) { ERR(sh, "Write to %s failed.", semanage_path(SEMANAGE_TMP, SEMANAGE_FC)); goto cleanup; @@ -1074,6 +1087,7 @@ store_fc_loc); goto cleanup; } + errno = 0; snprintf(store_seusers, PATH_MAX, "%s%s", storepath, running_seusers); if (semanage_copy_file @@ -1083,6 +1097,7 @@ store_seusers); goto cleanup; } + errno = 0; snprintf(store_nc, PATH_MAX, "%s%s", storepath, running_nc); if (semanage_copy_file(active_nc, store_nc, sh->conf->file_mode) == -1 @@ -1090,6 +1105,7 @@ ERR(sh, "Could not copy %s to %s.", active_nc, store_nc); goto cleanup; } + errno = 0; if (!sh->do_reload) goto skip_reload; @@ -1111,8 +1127,10 @@ goto skip_reload; } } else if (errno == ENOENT && - strcmp(really_active_store, storepath) != 0) + strcmp(really_active_store, storepath) != 0) { + errno = 0; goto skip_reload; + } if (semanage_reload_policy(sh)) { goto cleanup; @@ -1212,6 +1230,7 @@ /* note that if an error occurs during the next three * function then the store will be left in an * inconsistent state */ + int errsv = errno; if (rename(active, sandbox) < 0) ERR(sh, "Error while renaming %s back to %s.", active, sandbox); @@ -1220,16 +1239,19 @@ active); else semanage_install_active(sh); + errno = errsv; retval = -1; goto cleanup; } if (!sh->conf->save_previous) { + int errsv = errno; retval = semanage_remove_directory(backup); if (retval < 0) { ERR(sh, "Could not delete previous directory %s.", backup); goto cleanup; } + errno = errsv; } cleanup: @@ -1391,22 +1413,26 @@ * there. */ void semanage_release_trans_lock(semanage_handle_t * sh) { + int errsv = errno; if (sh->u.direct.translock_file_fd >= 0) { flock(sh->u.direct.translock_file_fd, LOCK_UN); close(sh->u.direct.translock_file_fd); sh->u.direct.translock_file_fd = -1; } + errno = errsv; } /* Releases the read lock. Does nothing if there was not one already * there. */ void semanage_release_active_lock(semanage_handle_t * sh) { + int errsv = errno; if (sh->u.direct.activelock_file_fd >= 0) { flock(sh->u.direct.activelock_file_fd, LOCK_UN); close(sh->u.direct.activelock_file_fd); sh->u.direct.activelock_file_fd = -1; } + errno = errsv; } /* Read the current commit number from the commit number file which @@ -1432,6 +1458,7 @@ if (errno == ENOENT) { /* the commit number file does not exist yet, * so assume that the number is 0 */ + errno = 0; return 0; } else { ERR(sh, "Could not open commit number file %s.", Modified: branches/stable/1_0/policycoreutils/semodule/semodule.c =================================================================== --- branches/stable/1_0/policycoreutils/semodule/semodule.c 2007-09-27 13:16:53 UTC (rev 2594) +++ branches/stable/1_0/policycoreutils/semodule/semodule.c 2007-09-27 13:21:25 UTC (rev 2595) @@ -329,8 +329,8 @@ if (build) { if ((result = semanage_begin_transaction(sh)) < 0) { - fprintf(stderr, "%s: Could not begin transaction\n", - argv[0]); + fprintf(stderr, "%s: Could not begin transaction: %s\n", + argv[0], errno ? strerror(errno) : ""); goto cleanup; } } @@ -343,8 +343,8 @@ if (mode == INSTALL_M || mode == UPGRADE_M || mode == BASE_M) { if ((data_len = map_file(mode_arg, &data)) == 0) { fprintf(stderr, - "%s: Could not read file '%s':\n", - argv[0], mode_arg); + "%s: Could not read file '%s': %s\n", + argv[0], mode_arg, errno ? strerror(errno) : ""); goto cleanup; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |