*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 0211-1301 USA
*
* To Do:
* + Proper support for internationalization
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <syslog.h>
#include <rpc/rpc.h>
-#include <rpc/pmap_prot.h>
-#include <rpc/pmap_clnt.h>
#include "xcommon.h"
#include "nls.h"
tmp = &errbuf[spos];
if (cf_stat == RPC_SYSTEMERROR)
pos = snprintf(tmp, (erreob - tmp),
- "System Error: %s", strerror(cf_errno));
- else
- pos = snprintf(tmp, (erreob - tmp), "RPC Error:%s", estr);
+ _("System Error: %s"),
+ strerror(cf_errno));
+ else {
+ if (cf_errno)
+ pos = snprintf(tmp, (erreob - tmp),
+ _("RPC Error:%s; errno = %s"),
+ estr, strerror(cf_errno));
+ else
+ pos = snprintf(tmp, (erreob - tmp),
+ _("RPC Error:%s"), estr);
+ }
}
return pos;
}
-void mount_errors(char *server, int will_retry, int bg)
+/**
+ * rpc_mount_errors - log an RPC error that occurred during a user-space mount
+ * @server: C string containing name of server we are attempting to mount
+ * @will_retry: one indicates mount will retry at some later point
+ * @bg: one indicates this is a background mount
+ *
+ * Extracts the error code from the user-space RPC library, and reports it
+ * on stderr (fg mount) or in the system log (bg mount).
+ */
+void rpc_mount_errors(char *server, int will_retry, int bg)
{
int pos = 0;
char *tmp;
tmp = &errbuf[pos];
if (bg)
pos = snprintf(tmp, (erreob - tmp),
- "mount to NFS server '%s' failed: ", server);
+ _("mount to NFS server '%s' failed: "),
+ server);
else
pos = snprintf(tmp, (erreob - tmp),
- "%s: mount to NFS server '%s' failed: ",
- progname, server);
+ _("%s: mount to NFS server '%s' failed: "),
+ progname, server);
tmp = &errbuf[pos];
if (rpc_createerr.cf_stat == RPC_TIMEDOUT) {
- pos = snprintf(tmp, (erreob - tmp), "timed out %s",
- will_retry ? "(retrying)" : "(giving up)");
+ if (will_retry)
+ pos = snprintf(tmp, (erreob - tmp),
+ _("timed out, retrying"));
+ else
+ pos = snprintf(tmp, (erreob - tmp),
+ _("timed out, giving up"));
} else {
pos += rpc_strerror(pos);
tmp = &errbuf[pos];
if (bg) {
- pos = snprintf(tmp, (erreob - tmp), " %s",
- will_retry ? "(retrying)" : "(giving up)");
+ if (will_retry)
+ pos = snprintf(tmp, (erreob - tmp),
+ _(", retrying"));
+ else
+ pos = snprintf(tmp, (erreob - tmp),
+ _(", giving up"));
+ }
+ }
+
+ if (bg) {
+ if (onlyonce++ < 1)
+ openlog("mount", LOG_CONS|LOG_PID, LOG_AUTH);
+ syslog(LOG_ERR, "%s", errbuf);
+ } else
+ fprintf(stderr, "%s\n", errbuf);
+}
+
+/**
+ * sys_mount_errors - log an error that occurred during a mount system call
+ * @server: C string containing name of server we are attempting to mount
+ * @error: errno value to report
+ * @will_retry: one indicates mount will retry at some later point
+ * @bg: one indicates this is a background mount
+ *
+ * Passed an errno value generated by a mount system call, and reports it
+ * on stderr (fg mount) or in the system log (bg mount).
+ */
+void sys_mount_errors(char *server, int error, int will_retry, int bg)
+{
+ int pos = 0;
+ char *tmp;
+ static int onlyonce = 0;
+
+ tmp = &errbuf[pos];
+ if (bg)
+ pos = snprintf(tmp, (erreob - tmp),
+ _("mount to NFS server '%s' failed: "),
+ server);
+ else
+ pos = snprintf(tmp, (erreob - tmp),
+ _("%s: mount to NFS server '%s' failed: "),
+ progname, server);
+
+ tmp = &errbuf[pos];
+ if (error == ETIMEDOUT) {
+ if (will_retry)
+ pos = snprintf(tmp, (erreob - tmp),
+ _("timed out, retrying"));
+ else
+ pos = snprintf(tmp, (erreob - tmp),
+ _("timed out, giving up"));
+ } else {
+ if (bg) {
+ if (will_retry)
+ pos = snprintf(tmp, (erreob - tmp),
+ _("%s, retrying"),
+ strerror(error));
+ else
+ pos = snprintf(tmp, (erreob - tmp),
+ _("%s, giving up"),
+ strerror(error));
}
}
+
if (bg) {
if (onlyonce++ < 1)
openlog("mount", LOG_CONS|LOG_PID, LOG_AUTH);
- syslog(LOG_ERR, "%s.", errbuf);
+ syslog(LOG_ERR, "%s", errbuf);
} else
- fprintf(stderr, "%s.\n", errbuf);
+ fprintf(stderr, "%s\n", errbuf);
}
+/**
+ * mount_error - report a foreground mount error
+ * @spec: C string containing the device name being mounted
+ * @mount_point: C string containing the pathname of the local mounted on dir
+ * @error: errno value to report
+ *
+ */
void mount_error(const char *spec, const char *mount_point, int error)
{
switch(error) {
+ case EACCES:
+ nfs_error(_("%s: access denied by server while mounting %s"),
+ progname, spec);
+ break;
+ case EINVAL:
+ nfs_error(_("%s: an incorrect mount option was specified"), progname);
+ break;
+ case EOPNOTSUPP:
+ nfs_error(_("%s: requested NFS version or transport"
+ " protocol is not supported"),
+ progname);
+ break;
case ENOTDIR:
nfs_error(_("%s: mount point %s is not a directory"),
progname, mount_point);
break;
case EBUSY:
- nfs_error(_("%s: %s is already mounted or busy"),
+ nfs_error(_("%s: %s is busy or already mounted"),
progname, mount_point);
break;
case ENOENT:
nfs_error(_("%s: mount point %s does not exist"),
progname, mount_point);
break;
+ case ESPIPE:
+ rpc_mount_errors((char *)spec, 0, 0);
+ break;
+ case EIO:
+ nfs_error(_("%s: mount system call failed"), progname);
+ break;
+ case EFAULT:
+ nfs_error(_("%s: encountered unexpected error condition."),
+ progname);
+ nfs_error(_("%s: please report the error to" PACKAGE_BUGREPORT),
+ progname);
+ break;
default:
nfs_error(_("%s: %s"),
progname, strerror(error));
}
/*
- * Report a failed umount
+ * umount_error - report a failed umount request
+ * @err: errno value to report
+ * @dev: C string containing the pathname of the local mounted on dir
+ *
*/
void umount_error(int err, const char *dev)
{
#define EDQUOT ENOSPC
#endif
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
static struct {
enum nfsstat stat;
int errnum;
#endif
/* Throw in some NFSv3 values for even more fun (HP returns these) */
{ 71, EREMOTE },
-
- { -1, EIO }
};
-char *nfs_strerror(int stat)
+char *nfs_strerror(unsigned int stat)
{
- int i;
+ unsigned int i;
static char buf[256];
- for (i = 0; nfs_errtbl[i].stat != -1; i++) {
+ for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
if (nfs_errtbl[i].stat == stat)
return strerror(nfs_errtbl[i].errnum);
}
- sprintf(buf, _("unknown nfs status return value: %d"), stat);
+ sprintf(buf, _("unknown nfs status return value: %u"), stat);
return buf;
}