static void error_callback_default(enum llapi_message_level level, int err,
const char *fmt, va_list ap)
{
+ bool has_nl = strchr(fmt, '\n') != NULL;
+
if (liblustreapi_cmd != NULL)
fprintf(stderr, "%s %s: ", program_invocation_short_name,
liblustreapi_cmd);
else
fprintf(stderr, "%s: ", program_invocation_short_name);
- vfprintf(stderr, fmt, ap);
- if (level & LLAPI_MSG_NO_ERRNO)
- fprintf(stderr, "\n");
- else
+
+
+ if (level & LLAPI_MSG_NO_ERRNO) {
+ vfprintf(stderr, fmt, ap);
+ if (!has_nl)
+ fprintf(stderr, "\n");
+ } else {
+ char *newfmt;
+
+ /* Remove trailing linefeed so error string can be appended.
+ * @fmt is a const string, so we can't modify it directly.
+ */
+ if (has_nl && (newfmt = strdup(fmt)))
+ *strrchr(newfmt, '\n') = '\0';
+ else
+ newfmt = (char *)fmt;
+
+ vfprintf(stderr, newfmt, ap);
+ if (newfmt != fmt)
+ free(newfmt);
fprintf(stderr, ": %s (%d)\n", strerror(err), err);
+ }
}
static void info_callback_default(enum llapi_message_level level, int err,
if (*pbuf != NULL && data->ioc_len > max_len) {
llapi_error(LLAPI_MSG_ERROR, -EINVAL,
- "pbuf = %p, ioc_len = %u, max_len = %d\n",
+ "pbuf = %p, ioc_len = %u, max_len = %d",
*pbuf, data->ioc_len, max_len);
return -EINVAL;
}
if (len > XATTR_SIZE_MAX - offsetof(struct lmv_foreign_md, lfm_value) ||
len <= 0) {
rc = -EINVAL;
- llapi_error(LLAPI_MSG_ERROR, rc, "invalid LOV EA length %zu "
- "(must be 0 < len < %zu)\n", len,
- XATTR_SIZE_MAX -
- offsetof(struct lmv_foreign_md, lfm_value));
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "invalid LOV EA length %zu (must be 0 < len < %zu)",
+ len, XATTR_SIZE_MAX -
+ offsetof(struct lmv_foreign_md, lfm_value));
return rc;
}
lfm_size = len + offsetof(struct lmv_foreign_md, lfm_value);
goto out;
}
- if (ioctl(fd, LL_IOC_REMOVE_ENTRY, filename)) {
- char *errmsg = strerror(errno);
- llapi_err_noerrno(LLAPI_MSG_ERROR,
- "error on ioctl %#jx for '%s' (%d): %s",
- (uintmax_t)LL_IOC_LMV_SETSTRIPE, filename,
- fd, errmsg);
- }
+ if (ioctl(fd, LL_IOC_REMOVE_ENTRY, filename))
+ llapi_error(LLAPI_MSG_ERROR, errno,
+ "error on ioctl %#lx for '%s' (%d)",
+ (long)LL_IOC_LMV_SETSTRIPE, filename, fd);
out:
free(dirpath);
free(namepath);
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot open '%s': %s", mntdir,
- strerror(-rc));
+ "cannot open '%s'", mntdir);
} else {
*outfd = fd;
ret = llapi_obd_statfs(path, type,
param->fp_obd_index, &stat_buf,
&uuid_buf);
- if (ret) {
- llapi_printf(LLAPI_MSG_NORMAL,
- "obd_uuid: %s failed %s ",
- param->fp_obd_uuid->uuid,
- strerror(errno));
- }
+ if (ret)
+ llapi_error(LLAPI_MSG_NORMAL, ret, "obd_uuid: %s failed",
+ param->fp_obd_uuid->uuid);
return ret;
}
} else if (errno == EALREADY) {
if (param->fp_verbose & VERBOSE_DETAIL)
llapi_printf(LLAPI_MSG_NORMAL,
- "%s was migrated to MDT%d already\n",
+ "%s migrated to MDT%d already\n",
path, lmu->lum_stripe_offset);
ret = 0;
} else {
ret = -errno;
- llapi_error(LLAPI_MSG_ERROR, ret,
- "%s migrate failed: %s (%d)\n",
- path, strerror(-ret), ret);
+ llapi_error(LLAPI_MSG_ERROR, ret, "%s migrate failed",
+ path);
goto out;
}
} else if (param->fp_verbose & VERBOSE_DETAIL) {
if (!printed) {
llapi_error(LLAPI_MSG_ERROR, -ESTALE,
- "llapi_mv() is deprecated, use llapi_migrate_mdt()\n");
+ "%s() is deprecated, use llapi_migrate_mdt() instead",
+ __func__);
printed = true;
}
#endif
rc = llapi_getname(mntpath, buf, sizeof(buf));
if (rc < 0) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot get name for '%s'\n", mntpath);
+ "cannot get name for '%s'", mntpath);
return rc;
}
rc = errno;
if (errno != EIO)
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: setting llite.%s.pcc=\"%s\"\n",
+ "error: setting llite.%s.pcc='%s'",
buf, cmd);
} else if (count < strlen(cmd)) { /* Truncate case */
rc = -EINVAL;
llapi_error(LLAPI_MSG_ERROR, rc,
- "setting llite.%s.pcc=\"%s\": wrote only %zd\n",
+ "setting llite.%s.pcc='%s': wrote only %zd",
buf, cmd, count);
}
close(fd);
rc = llapi_getname(mntpath, pathbuf, sizeof(pathbuf));
if (rc < 0) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot get name for '%s'\n", mntpath);
+ "cannot get name for '%s'", mntpath);
return rc;
}
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: opening '%s'\n",
+ "error: pccdev_get: opening '%s'",
path.gl_pathv[0]);
goto out_free_param;
}
if (buf == NULL) {
rc = -ENOMEM;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: allocating '%s' buffer\n",
+ "error: pccdev_get: allocating '%s' buffer",
path.gl_pathv[0]);
goto out_close;
}
rc = -errno;
if (errno != EIO) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: "
- "reading failed\n");
+ "error: pccdev_get: reading failed");
}
break;
}
if (fwrite(buf, 1, count, stdout) != count) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: get_param: write to stdout\n");
+ "error: get_param: write to stdout");
break;
}
}