Whamcloud - gitweb
LU-8854 llapi: remove lustre specific strlcpy & strlcat functions 98/29798/6
authorJames Simmons <uja.ornl@yahoo.com>
Sat, 10 Feb 2018 16:18:53 +0000 (11:18 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 27 Feb 2018 03:46:14 +0000 (03:46 +0000)
In the days when lustre supported many more platforms some of those
platforms natively support strl[cpy|cat] but Linux has always lack
these functions. So lustre ended up providing its own versions of
these functions to fill in this functionality. Today Lustre only
supports the Linux platforms which has a version of libc that will
most likely never support strl[cat|cpy]. Since this is the case we
can remove the AC_CHECK_FUNCS since they only test against libc.
We could support detecting strl[cpy|cat] in another library but
many libraries provide their own version so the chances of collision
are high. The best solution is remove strlcpy and strlcat by
replacing those functions with string functions that are always
provided by the standard c library.

Change-Id: I72df93c8f83ed1aad80653fe0d1c4d54d1d8e2f2
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/29798
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
20 files changed:
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/util/string.h
libcfs/libcfs/util/param.c
libcfs/libcfs/util/string.c
lustre/tests/ll_dirstripe_verify.c
lustre/utils/gss/gssd.c
lustre/utils/gss/gssd.h
lustre/utils/gss/lgss_keyring.c
lustre/utils/l_getidentity.c
lustre/utils/lfs.c
lustre/utils/lhsmtool_posix.c
lustre/utils/libiam.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi.map
lustre/utils/liblustreapi_json.c
lustre/utils/liblustreapi_util.c
lustre/utils/lustre_rsync.c
lustre/utils/mount_lustre.c
lustre/utils/obd.c
lustre/utils/portals.c

index a85f18d..1231e90 100644 (file)
@@ -934,38 +934,6 @@ AC_DEFUN([LIBCFS_CONFIGURE], [
 AC_MSG_NOTICE([LibCFS core checks
 ==============================================================================])
 
 AC_MSG_NOTICE([LibCFS core checks
 ==============================================================================])
 
-# lnet/utils/portals.c
-AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
-
-# lnet/utils/debug.c
-AC_CHECK_HEADERS([linux/version.h])
-
-AC_CHECK_TYPE([spinlock_t],
-       [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
-       [],
-       [#include <linux/spinlock.h>])
-
-# lnet/utils/wirecheck.c
-AC_CHECK_FUNCS([strnlen])
-
-# lnet/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
-AC_CHECK_FUNCS([strlcpy])
-
-# libcfs/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
-AC_CHECK_FUNCS([strlcat])
-
-# libcfs/include/libcfs/linux/linux-prim.h, ...
-AC_CHECK_HEADERS([linux/types.h sys/types.h linux/unistd.h unistd.h])
-
-# libcfs/include/libcfs/linux/linux-prim.h
-AC_CHECK_HEADERS([linux/random.h], [], [],
-                [#ifdef HAVE_LINUX_TYPES_H
-                 #include <linux/types.h>
-                 #endif
-                ])
-
-# libcfs/include/libcfs/linux/libcfs.h
-# libcfs/include/libcfs/byteorder.h
 # libcfs/libcfs/util/nidstrings.c
 AC_CHECK_HEADERS([netdb.h asm/types.h endian.h])
 AC_CHECK_FUNCS([gethostbyname])
 # libcfs/libcfs/util/nidstrings.c
 AC_CHECK_HEADERS([netdb.h asm/types.h endian.h])
 AC_CHECK_FUNCS([gethostbyname])
index 11bf780..22e6024 100644 (file)
 #include <linux/types.h>
 #include <libcfs/util/list.h>
 
 #include <linux/types.h>
 #include <libcfs/util/list.h>
 
-#ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
-size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
-#endif
-
-#ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
-size_t strlcat(char *tgt, const char *src, size_t tgt_len);
-#endif
-
 /**
  * Structure to represent NULL-less strings.
  */
 /**
  * Structure to represent NULL-less strings.
  */
index 9facce6..18fe84d 100644 (file)
 int
 cfs_get_param_paths(glob_t *paths, const char *pattern, ...)
 {
 int
 cfs_get_param_paths(glob_t *paths, const char *pattern, ...)
 {
-       char path[PATH_MAX] = "{/sys/{fs,kernel/debug}/{lnet,lustre}/,"
-                              "/proc/{fs,sys}/{lnet,lustre}/}";
+       char topdir[PATH_MAX] = "{/sys/{fs,kernel/debug}/{lnet,lustre},"
+                               "/proc/{fs,sys}/{lnet,lustre}}";
        static bool test_mounted = false;
        static bool test_mounted = false;
-       size_t len = strlen(path);
+       char path[PATH_MAX];
        char buf[PATH_MAX];
        struct statfs statfsbuf;
        va_list args;
        char buf[PATH_MAX];
        struct statfs statfsbuf;
        va_list args;
@@ -127,9 +127,9 @@ skip_mounting:
                errno = EINVAL;
                return -1;
        }
                errno = EINVAL;
                return -1;
        }
-       len += rc;
 
 
-       if (strlcat(path, buf, sizeof(path)) != len) {
+       if (snprintf(path, sizeof(path), "%s/%s", topdir, buf) >=
+           sizeof(path)) {
                errno = E2BIG;
                return -1;
        }
                errno = E2BIG;
                return -1;
        }
index 8f541c6..2c1a24c 100644 (file)
 #include <unistd.h>
 #include <libcfs/util/string.h>
 
 #include <unistd.h>
 #include <libcfs/util/string.h>
 
-/*
- * According manual of strlcpy() and strlcat() the functions should return
- * the total length of the string they tried to create. For strlcpy() that
- * means the length of src. For strlcat() that means the initial length of
- * dst plus the length of src. So, the function strnlen() cannot be used
- * otherwise the return value will be wrong.
- */
-#ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
-size_t strlcpy(char *dst, const char *src, size_t size)
-{
-       size_t ret = strlen(src);
-
-       if (size) {
-               size_t len = (ret >= size) ? size - 1 : ret;
-               memcpy(dst, src, len);
-               dst[len] = '\0';
-       }
-       return ret;
-}
-#endif
-
-#ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
-size_t strlcat(char *dst, const char *src, size_t size)
-{
-       size_t dsize = strlen(dst);
-       size_t len = strlen(src);
-       size_t ret = dsize + len;
-
-       dst  += dsize;
-       size -= dsize;
-       if (len >= size)
-               len = size-1;
-       memcpy(dst, src, len);
-       dst[len] = '\0';
-       return ret;
-}
-#endif
-
 /**
  * Extracts tokens from strings.
  *
 /**
  * Extracts tokens from strings.
  *
index 1ad7552..09cf1b9 100644 (file)
@@ -279,7 +279,7 @@ int main(int argc, char **argv)
 
        rc = llapi_file_get_stripe(argv[1], lum_dir);
        if (rc == -ENODATA) {
 
        rc = llapi_file_get_stripe(argv[1], lum_dir);
        if (rc == -ENODATA) {
-               char root[PATH_MAX];
+               char root[PATH_MAX], path[PATH_MAX + 2];
 
                rc = llapi_search_mounts(argv[1], 0, root, NULL);
                if (rc) {
 
                rc = llapi_search_mounts(argv[1], 0, root, NULL);
                if (rc) {
@@ -288,14 +288,14 @@ int main(int argc, char **argv)
                        goto cleanup;
                }
 
                        goto cleanup;
                }
 
-               strlcat(root, "/.", PATH_MAX);
-               rc = llapi_file_get_stripe(root, lum_dir);
+               snprintf(path, sizeof(path), "%s/.", root);
+               rc = llapi_file_get_stripe(path, lum_dir);
                if (rc == -ENODATA) {
                        free(lum_dir);
                        lum_dir = NULL;
                } else if (rc) {
                        llapi_error(LLAPI_MSG_ERROR, rc, "error: cant't get "
                if (rc == -ENODATA) {
                        free(lum_dir);
                        lum_dir = NULL;
                } else if (rc) {
                        llapi_error(LLAPI_MSG_ERROR, rc, "error: cant't get "
-                                   "root's LOVEA for %s\n", root);
+                                   "root's LOVEA for %s\n", path);
                        goto cleanup;
                }
        } else if (rc) {
                        goto cleanup;
                }
        } else if (rc) {
index 2f96b5c..a0f05e2 100644 (file)
 #include "krb5_util.h"
 #include "lsupport.h"
 
 #include "krb5_util.h"
 #include "lsupport.h"
 
-char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
+char *pipefs_dir = GSSD_PIPEFS_DIR;
 char pipefs_nfsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
 char pipefs_nfsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
-char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
-char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR;
+char *keytabfile = GSSD_DEFAULT_KEYTAB_FILE;
+char *ccachedir = GSSD_DEFAULT_CRED_DIR;
 int  use_memcache = 0;
 int  lgssd_mutex_downcall = -1;
 
 int  use_memcache = 0;
 int  lgssd_mutex_downcall = -1;
 
@@ -201,19 +201,19 @@ main(int argc, char *argv[])
                                verbosity++;
                                break;
                        case 'p':
                                verbosity++;
                                break;
                        case 'p':
-                               strlcpy(pipefs_dir, optarg, sizeof(pipefs_dir));
-                               if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
-                                       errx(1, "pipefs path name too long");
+                               pipefs_dir = strdup(optarg);
+                               if (!pipe_dir)
+                                       errx(1, "pipefs path name not aquired");
                                break;
                        case 'k':
                                break;
                        case 'k':
-                               strlcpy(keytabfile, optarg, sizeof(keytabfile));
-                               if (keytabfile[sizeof(keytabfile)-1] != '\0')
-                                       errx(1, "keytab path name too long");
+                               keytabfile = strdup(optarg);
+                               if (!keytab_file)
+                                       errx(1, "keytab path name not aquired");
                                break;
                        case 'd':
                                break;
                        case 'd':
-                               strlcpy(ccachedir, optarg, sizeof(ccachedir));
-                               if (ccachedir[sizeof(ccachedir)-1] != '\0')
-                                       errx(1, "ccachedir path name too long");
+                               ccachedir = strdup(optarg);
+                               if (!ccachedir)
+                                       errx(1, "ccachedir path name not aquired");
                                break;
                        default:
                                usage(argv[0]);
                                break;
                        default:
                                usage(argv[0]);
index 9f0a191..b66fdf9 100644 (file)
@@ -64,11 +64,11 @@ enum {AUTHTYPE_KRB5, AUTHTYPE_SPKM3, AUTHTYPE_LIPKEY};
 
 
 
 
 
 
-extern char                    pipefs_dir[PATH_MAX];
-extern char                    keytabfile[PATH_MAX];
-extern char                    ccachedir[PATH_MAX];
-extern char                    gethostname_ex[PATH_MAX];
-extern int                     use_memcache;
+extern char *pipefs_dir;
+extern char *keytabfile;
+extern char *ccachedir;
+extern char gethostname_ex[PATH_MAX];
+extern int use_memcache;
 
 TAILQ_HEAD(clnt_list_head, clnt_info) clnt_list;
 
 
 TAILQ_HEAD(clnt_list_head, clnt_info) clnt_list;
 
index 9a093ad..6d62273 100644 (file)
@@ -850,7 +850,7 @@ static int parse_callout_info(const char *coinfo,
               data[6], data[7], data[8], data[9], data[10]);
 
        uparam->kup_secid = strtol(data[0], NULL, 0);
               data[6], data[7], data[8], data[9], data[10]);
 
        uparam->kup_secid = strtol(data[0], NULL, 0);
-       strlcpy(uparam->kup_mech, data[1], sizeof(uparam->kup_mech));
+       snprintf(uparam->kup_mech, sizeof(uparam->kup_mech), "%s", data[1]);
        uparam->kup_uid = strtol(data[2], NULL, 0);
        uparam->kup_gid = strtol(data[3], NULL, 0);
        if (strchr(data[4], 'r'))
        uparam->kup_uid = strtol(data[2], NULL, 0);
        uparam->kup_gid = strtol(data[3], NULL, 0);
        if (strchr(data[4], 'r'))
@@ -862,7 +862,7 @@ static int parse_callout_info(const char *coinfo,
        uparam->kup_svc_type = data[5][0];
        uparam->kup_svc = strtol(data[6], NULL, 0);
        uparam->kup_nid = strtoll(data[7], NULL, 0);
        uparam->kup_svc_type = data[5][0];
        uparam->kup_svc = strtol(data[6], NULL, 0);
        uparam->kup_nid = strtoll(data[7], NULL, 0);
-       strlcpy(uparam->kup_tgt, data[8], sizeof(uparam->kup_tgt));
+       snprintf(uparam->kup_tgt, sizeof(uparam->kup_tgt), "%s", data[8]);
        uparam->kup_selfnid = strtoll(data[9], NULL, 0);
        uparam->kup_pid = strtol(data[10], NULL, 0);
 
        uparam->kup_selfnid = strtoll(data[9], NULL, 0);
        uparam->kup_pid = strtol(data[10], NULL, 0);
 
index 6f8dff6..ff7bb26 100644 (file)
@@ -46,7 +46,6 @@
 #include <syslog.h>
 
 #include <libcfs/util/param.h>
 #include <syslog.h>
 
 #include <libcfs/util/param.h>
-#include <libcfs/util/string.h>
 #include <linux/lnet/nidstr.h>
 #include <linux/lustre/lustre_user.h>
 #include <linux/lustre/lustre_idl.h>
 #include <linux/lnet/nidstr.h>
 #include <linux/lustre/lustre_user.h>
 #include <linux/lustre/lustre_idl.h>
@@ -105,8 +104,6 @@ int get_groups_local(struct identity_downcall_data *data,
        unsigned int ngroups = 0;
        int ngroups_tmp;
        struct passwd *pw;
        unsigned int ngroups = 0;
        int ngroups_tmp;
        struct passwd *pw;
-       char *pw_name;
-       int namelen;
        int i;
 
        pw = getpwuid(data->idd_uid);
        int i;
 
        pw = getpwuid(data->idd_uid);
@@ -117,25 +114,13 @@ int get_groups_local(struct identity_downcall_data *data,
        }
 
        data->idd_gid = pw->pw_gid;
        }
 
        data->idd_gid = pw->pw_gid;
-       namelen = sysconf(_SC_LOGIN_NAME_MAX);
-       if (namelen < _POSIX_LOGIN_NAME_MAX)
-               namelen = _POSIX_LOGIN_NAME_MAX;
-
-       pw_name = malloc(namelen);
-       if (!pw_name) {
-               errlog("malloc error\n");
-               data->idd_err = errno;
-               return -1;
-       }
 
 
-       strlcpy(pw_name, pw->pw_name, namelen);
        groups = data->idd_groups;
 
        /* Allocate array of size maxgroups instead of handling two
         * consecutive and potentially racy getgrouplist() calls. */
        groups_tmp = malloc(maxgroups * sizeof(gid_t));
        if (groups_tmp == NULL) {
        groups = data->idd_groups;
 
        /* Allocate array of size maxgroups instead of handling two
         * consecutive and potentially racy getgrouplist() calls. */
        groups_tmp = malloc(maxgroups * sizeof(gid_t));
        if (groups_tmp == NULL) {
-               free(pw_name);
                data->idd_err = errno ? errno : ENOMEM;
                errlog("malloc error=%u\n",data->idd_err);
                return -1;
                data->idd_err = errno ? errno : ENOMEM;
                errlog("malloc error=%u\n",data->idd_err);
                return -1;
@@ -144,7 +129,6 @@ int get_groups_local(struct identity_downcall_data *data,
        ngroups_tmp = maxgroups;
        if (getgrouplist(pw->pw_name, pw->pw_gid, groups_tmp, &ngroups_tmp) <
            0) {
        ngroups_tmp = maxgroups;
        if (getgrouplist(pw->pw_name, pw->pw_gid, groups_tmp, &ngroups_tmp) <
            0) {
-               free(pw_name);
                free(groups_tmp);
                data->idd_err = errno ? errno : EIDRM;
                errlog("getgrouplist() error for uid %u: error=%u\n",
                free(groups_tmp);
                data->idd_err = errno ? errno : EIDRM;
                errlog("getgrouplist() error for uid %u: error=%u\n",
@@ -161,7 +145,6 @@ int get_groups_local(struct identity_downcall_data *data,
                qsort(groups, ngroups, sizeof(*groups), compare_u32);
        data->idd_ngroups = ngroups;
 
                qsort(groups, ngroups, sizeof(*groups), compare_u32);
        data->idd_ngroups = ngroups;
 
-       free(pw_name);
        free(groups_tmp);
        return 0;
 }
        free(groups_tmp);
        return 0;
 }
index bb0f81b..1020567 100644 (file)
@@ -5813,7 +5813,7 @@ quota_type:
                         break;
                 case 'o':
                         valid = qctl.qc_valid = QC_UUID;
                         break;
                 case 'o':
                         valid = qctl.qc_valid = QC_UUID;
-                       strlcpy(obd_uuid, optarg, sizeof(qctl.obd_uuid));
+                       snprintf(obd_uuid, sizeof(qctl.obd_uuid), "%s", optarg);
                         break;
                case 'i':
                        valid = qctl.qc_valid = QC_MDTIDX;
                         break;
                case 'i':
                        valid = qctl.qc_valid = QC_MDTIDX;
index 28e3c49..d3633d6 100644 (file)
@@ -886,7 +886,8 @@ static int ct_archive(const struct hsm_action_item *hai, const long hal_flags)
 {
        struct hsm_copyaction_private   *hcp = NULL;
        char                             src[PATH_MAX];
 {
        struct hsm_copyaction_private   *hcp = NULL;
        char                             src[PATH_MAX];
-       char                             dst[PATH_MAX] = "";
+       char                             dst[PATH_MAX + 4] = "";
+       char                             root[PATH_MAX] = "";
        int                              rc;
        int                              rcf = 0;
        bool                             rename_needed = false;
        int                              rc;
        int                              rcf = 0;
        bool                             rename_needed = false;
@@ -904,14 +905,16 @@ static int ct_archive(const struct hsm_action_item *hai, const long hal_flags)
         * destination = lustre FID
         */
        ct_path_lustre(src, sizeof(src), opt.o_mnt, &hai->hai_dfid);
         * destination = lustre FID
         */
        ct_path_lustre(src, sizeof(src), opt.o_mnt, &hai->hai_dfid);
-       ct_path_archive(dst, sizeof(dst), opt.o_hsm_root, &hai->hai_fid);
+       ct_path_archive(root, sizeof(root), opt.o_hsm_root, &hai->hai_fid);
        if (hai->hai_extent.length == -1) {
                /* whole file, write it to tmp location and atomically
                 * replace old archived file */
        if (hai->hai_extent.length == -1) {
                /* whole file, write it to tmp location and atomically
                 * replace old archived file */
-               strlcat(dst, "_tmp", sizeof(dst));
+               snprintf(dst, sizeof(dst), "%s_tmp", root);
                /* we cannot rely on the same test because ct_copy_data()
                 * updates hai_extent.length */
                rename_needed = true;
                /* we cannot rely on the same test because ct_copy_data()
                 * updates hai_extent.length */
                rename_needed = true;
+       } else {
+               snprintf(dst, sizeof(dst), "%s", root);
        }
 
        CT_TRACE("archiving '%s' to '%s'", src, dst);
        }
 
        CT_TRACE("archiving '%s' to '%s'", src, dst);
@@ -1242,7 +1245,7 @@ fini:
 static int ct_remove(const struct hsm_action_item *hai, const long hal_flags)
 {
        struct hsm_copyaction_private   *hcp = NULL;
 static int ct_remove(const struct hsm_action_item *hai, const long hal_flags)
 {
        struct hsm_copyaction_private   *hcp = NULL;
-       char                             dst[PATH_MAX];
+       char                             dst[PATH_MAX], attr[PATH_MAX + 4];
        int                              rc;
 
        rc = ct_begin(&hcp, hai);
        int                              rc;
 
        rc = ct_begin(&hcp, hai);
@@ -1266,11 +1269,11 @@ static int ct_remove(const struct hsm_action_item *hai, const long hal_flags)
                goto fini;
        }
 
                goto fini;
        }
 
-       strlcat(dst, ".lov", sizeof(dst));
-       rc = unlink(dst);
+       snprintf(attr, sizeof(attr), "%s.lov", dst);
+       rc = unlink(attr);
        if (rc < 0) {
                rc = -errno;
        if (rc < 0) {
                rc = -errno;
-               CT_ERROR(rc, "cannot unlink '%s'", dst);
+               CT_ERROR(rc, "cannot unlink '%s'", attr);
                err_minor++;
                goto fini;
        }
                err_minor++;
                goto fini;
        }
@@ -1576,6 +1579,9 @@ static int ct_rebind_one(const struct lu_fid *old_fid,
        ct_path_archive(dst, sizeof(dst), opt.o_hsm_root, new_fid);
 
        if (!opt.o_dry_run) {
        ct_path_archive(dst, sizeof(dst), opt.o_hsm_root, new_fid);
 
        if (!opt.o_dry_run) {
+               char src_attr[PATH_MAX + 4];
+               char dst_attr[PATH_MAX + 4];
+
                ct_mkdir_p(dst);
                if (rename(src, dst)) {
                        rc = -errno;
                ct_mkdir_p(dst);
                if (rename(src, dst)) {
                        rc = -errno;
@@ -1583,10 +1589,11 @@ static int ct_rebind_one(const struct lu_fid *old_fid,
                        return -errno;
                }
                /* rename lov file */
                        return -errno;
                }
                /* rename lov file */
-               strlcat(src, ".lov", sizeof(src));
-               strlcat(dst, ".lov", sizeof(dst));
-               if (rename(src, dst))
-                       CT_ERROR(errno, "cannot rename '%s' to '%s'", src, dst);
+               snprintf(src_attr, sizeof(src_attr), "%s.lov", src);
+               snprintf(dst_attr, sizeof(dst_attr), "%s.lov", dst);
+               if (rename(src_attr, dst_attr))
+                       CT_ERROR(errno, "cannot rename '%s' to '%s'",
+                                src_attr, dst_attr);
 
        }
        return 0;
 
        }
        return 0;
@@ -1752,7 +1759,7 @@ static int ct_max_sequence(void)
        __u64   seq = 0;
        __u16   subseq;
 
        __u64   seq = 0;
        __u16   subseq;
 
-       strlcpy(path, opt.o_hsm_root, sizeof(path));
+       snprintf(path, sizeof(path), "%s", opt.o_hsm_root);
        /* FID sequence is stored in top-level directory names:
         * hsm_root/16bits (high weight)/16 bits/16 bits/16 bits (low weight).
         */
        /* FID sequence is stored in top-level directory names:
         * hsm_root/16bits (high weight)/16 bits/16 bits/16 bits (low weight).
         */
@@ -1958,7 +1965,7 @@ int main(int argc, char **argv)
 {
        int     rc;
 
 {
        int     rc;
 
-       strlcpy(cmd_name, basename(argv[0]), sizeof(cmd_name));
+       snprintf(cmd_name, sizeof(cmd_name), "%s", basename(argv[0]));
        rc = ct_parseopts(argc, argv);
        if (rc < 0) {
                CT_WARN("try '%s --help' for more information", cmd_name);
        rc = ct_parseopts(argc, argv);
        if (rc < 0) {
                CT_WARN("try '%s --help' for more information", cmd_name);
index b0649ac..39a05bb 100644 (file)
@@ -328,11 +328,11 @@ static char *iam_convert(int size, int need_convert, char *source)
         if (source == NULL)
                 return NULL;
 
         if (source == NULL)
                 return NULL;
 
-        ptr = calloc(size + 1, sizeof(char));
-        if (ptr == NULL)
-                return NULL;
+       if (need_convert) {
+               ptr = calloc(size + 1, sizeof(char));
+               if (ptr == NULL)
+                       return NULL;
 
 
-        if (need_convert) {
                 opt = packdigit((unsigned char*)source);
                 if (opt == NULL) {
                         free(ptr);
                 opt = packdigit((unsigned char*)source);
                 if (opt == NULL) {
                         free(ptr);
@@ -342,7 +342,7 @@ static char *iam_convert(int size, int need_convert, char *source)
                         free(opt);
                 }
         } else {
                         free(opt);
                 }
         } else {
-               strlcpy(ptr, source, size + 1);
+               ptr = strdup(source);
         }
 
         return ptr;
         }
 
         return ptr;
index 273412d..b3dd226 100644 (file)
@@ -1274,30 +1274,37 @@ int llapi_search_fsname(const char *pathname, char *fsname)
 
         path = realpath(pathname, NULL);
         if (path == NULL) {
 
         path = realpath(pathname, NULL);
         if (path == NULL) {
-               char buf[PATH_MAX], *ptr;
+               char tmp[PATH_MAX - 1];
+               char buf[PATH_MAX];
+               char *ptr;
 
 
+               tmp[0] = '\0';
                buf[0] = '\0';
                if (pathname[0] != '/') {
                        /* Need an absolute path, but realpath() only works for
                         * pathnames that actually exist.  We go through the
                         * extra hurdle of dirname(getcwd() + pathname) in
                         * case the relative pathname contains ".." in it. */
                buf[0] = '\0';
                if (pathname[0] != '/') {
                        /* Need an absolute path, but realpath() only works for
                         * pathnames that actually exist.  We go through the
                         * extra hurdle of dirname(getcwd() + pathname) in
                         * case the relative pathname contains ".." in it. */
-                       if (getcwd(buf, sizeof(buf) - 2) == NULL) {
+                       char realpath[PATH_MAX - 1];
+
+                       if (getcwd(realpath, sizeof(realpath) - 2) == NULL) {
                                rc = -errno;
                                llapi_error(LLAPI_MSG_ERROR, rc,
                                            "cannot get current working directory");
                                return rc;
                        }
                                rc = -errno;
                                llapi_error(LLAPI_MSG_ERROR, rc,
                                            "cannot get current working directory");
                                return rc;
                        }
-                       rc = strlcat(buf, "/", sizeof(buf));
-                       if (rc >= sizeof(buf)) {
+
+                       rc = snprintf(tmp, sizeof(tmp), "%s/", realpath);
+                       if (rc >= sizeof(tmp)) {
                                rc = -E2BIG;
                                llapi_error(LLAPI_MSG_ERROR, rc,
                                            "invalid parent path '%s'",
                                rc = -E2BIG;
                                llapi_error(LLAPI_MSG_ERROR, rc,
                                            "invalid parent path '%s'",
-                                           buf);
+                                           tmp);
                                return rc;
                        }
                }
                                return rc;
                        }
                }
-               rc = strlcat(buf, pathname, sizeof(buf));
+
+               rc = snprintf(buf, sizeof(buf), "%s%s", tmp, pathname);
                if (rc >= sizeof(buf)) {
                        rc = -E2BIG;
                        llapi_error(LLAPI_MSG_ERROR, rc,
                if (rc >= sizeof(buf)) {
                        rc = -E2BIG;
                        llapi_error(LLAPI_MSG_ERROR, rc,
@@ -1385,7 +1392,8 @@ int llapi_get_poolmembers(const char *poolname, char **members,
        /* name is FSNAME.POOLNAME */
        if (strlen(poolname) >= sizeof(fsname))
                return -EOVERFLOW;
        /* name is FSNAME.POOLNAME */
        if (strlen(poolname) >= sizeof(fsname))
                return -EOVERFLOW;
-       strlcpy(fsname, poolname, sizeof(fsname));
+
+       snprintf(fsname, sizeof(fsname), "%s", poolname);
        pool = strchr(fsname, '.');
        if (pool == NULL)
                return -EINVAL;
        pool = strchr(fsname, '.');
        if (pool == NULL)
                return -EINVAL;
@@ -1761,7 +1769,7 @@ static int get_lmd_info(char *path, DIR *parent, DIR *dir,
                 * a large filesystem.  */
                fname = (fname == NULL ? path : fname + 1);
                /* retrieve needed file info */
                 * a large filesystem.  */
                fname = (fname == NULL ? path : fname + 1);
                /* retrieve needed file info */
-               strlcpy((char *)lmd, fname, lumlen);
+               snprintf((char *)lmd, lumlen, "%s", fname);
                ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO, (void *)lmd);
         }
 
                ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO, (void *)lmd);
         }
 
@@ -1914,7 +1922,7 @@ static int param_callback(char *path, semantic_func_t sem_init,
         if (!buf)
                 return -ENOMEM;
 
         if (!buf)
                 return -ENOMEM;
 
-       strlcpy(buf, path, PATH_MAX + 1);
+       snprintf(buf, PATH_MAX + 1, "%s", path);
         ret = common_param_init(param, buf);
         if (ret)
                 goto out;
         ret = common_param_init(param, buf);
         if (ret)
                 goto out;
@@ -2381,7 +2389,7 @@ int sattr_cache_get_defaults(const char *const fsname,
                 if (rc)
                         return rc;
         } else {
                 if (rc)
                         return rc;
         } else {
-               strlcpy(fsname_buf, fsname, sizeof(fsname_buf));
+               snprintf(fsname_buf, sizeof(fsname_buf), "%s", fsname);
         }
 
        if (strncmp(fsname_buf, cache.fsname, sizeof(fsname_buf) - 1) != 0) {
         }
 
        if (strncmp(fsname_buf, cache.fsname, sizeof(fsname_buf) - 1) != 0) {
@@ -2397,7 +2405,7 @@ int sattr_cache_get_defaults(const char *const fsname,
                 cache.stripecount = tmp[0];
                 cache.stripesize = tmp[1];
                 cache.stripeoffset = tmp[2];
                 cache.stripecount = tmp[0];
                 cache.stripesize = tmp[1];
                 cache.stripeoffset = tmp[2];
-               strlcpy(cache.fsname, fsname_buf, sizeof(cache.fsname));
+               snprintf(cache.fsname, sizeof(cache.fsname), "%s", fsname_buf);
         }
 
         if (scount)
         }
 
         if (scount)
@@ -3051,8 +3059,8 @@ static inline void
 lov_v1v3_pool_name(struct lov_user_md *v1, char *pool_name)
 {
        if (v1->lmm_magic == LOV_USER_MAGIC_V3)
 lov_v1v3_pool_name(struct lov_user_md *v1, char *pool_name)
 {
        if (v1->lmm_magic == LOV_USER_MAGIC_V3)
-               strlcpy(pool_name, ((struct lov_user_md_v3 *)v1)->lmm_pool_name,
-                       LOV_MAXPOOLNAME);
+               snprintf(pool_name, LOV_MAXPOOLNAME, "%s",
+                        ((struct lov_user_md_v3 *)v1)->lmm_pool_name);
        else
                pool_name[0] = '\0';
 }
        else
                pool_name[0] = '\0';
 }
@@ -3371,7 +3379,8 @@ static void lov_dump_plain_user_lmm(struct find_param *param, char *path,
                struct lov_user_ost_data_v1 *objects;
                struct lov_user_md_v3 *lmmv3 = (void *)&param->fp_lmd->lmd_lmm;
 
                struct lov_user_ost_data_v1 *objects;
                struct lov_user_md_v3 *lmmv3 = (void *)&param->fp_lmd->lmd_lmm;
 
-               strlcpy(pool_name, lmmv3->lmm_pool_name, sizeof(pool_name));
+               snprintf(pool_name, sizeof(pool_name), "%s",
+                        lmmv3->lmm_pool_name);
                objects = lmmv3->lmm_objects;
                lov_dump_user_lmm_v1v3(&param->fp_lmd->lmd_lmm, pool_name,
                                       objects, path, param->fp_obd_index,
                objects = lmmv3->lmm_objects;
                lov_dump_user_lmm_v1v3(&param->fp_lmd->lmd_lmm, pool_name,
                                       objects, path, param->fp_obd_index,
@@ -3406,7 +3415,8 @@ static void llapi_lov_dump_user_lmm(struct find_param *param, char *path,
                struct lmv_user_md *lum;
 
                lum = (struct lmv_user_md *)param->fp_lmv_md;
                struct lmv_user_md *lum;
 
                lum = (struct lmv_user_md *)param->fp_lmv_md;
-               strlcpy(pool_name, lum->lum_pool_name, sizeof(pool_name));
+               snprintf(pool_name, sizeof(pool_name), "%s",
+                        lum->lum_pool_name);
                lmv_dump_user_lmm(lum, pool_name, path, param->fp_obd_index,
                                  param->fp_max_depth, param->fp_verbose,
                                  flags);
                lmv_dump_user_lmm(lum, pool_name, path, param->fp_obd_index,
                                  param->fp_max_depth, param->fp_verbose,
                                  flags);
@@ -4497,8 +4507,8 @@ static int cb_getstripe(char *path, DIR *parent, DIR **dirp, void *data,
                char *fname = strrchr(path, '/');
                fname = (fname == NULL ? path : fname + 1);
 
                char *fname = strrchr(path, '/');
                fname = (fname == NULL ? path : fname + 1);
 
-               strlcpy((char *)&param->fp_lmd->lmd_lmm, fname,
-                       param->fp_lum_size);
+               snprintf((char *)&param->fp_lmd->lmd_lmm, param->fp_lum_size,
+                        "%s", fname);
 
                ret = ioctl(dirfd(parent), IOC_MDC_GETFILESTRIPE,
                            (void *)&param->fp_lmd->lmd_lmm);
 
                ret = ioctl(dirfd(parent), IOC_MDC_GETFILESTRIPE,
                            (void *)&param->fp_lmd->lmd_lmm);
index ecbbc12..45b8927 100644 (file)
@@ -8,8 +8,6 @@
        mdt_hash_name;
        Parser_*;
        register_ioc_*;
        mdt_hash_name;
        Parser_*;
        register_ioc_*;
-       strlcat;
-       strlcpy;
     local:
        *;
 };
     local:
        *;
 };
index bfcf902..e19f25f 100644 (file)
@@ -276,7 +276,7 @@ int llapi_json_add_item(struct llapi_json_item_list **json_items,
        if (new_item->lji_key == NULL)
                return -ENOMEM;
 
        if (new_item->lji_key == NULL)
                return -ENOMEM;
 
-       strlcpy(new_item->lji_key, key, len);
+       snprintf(new_item->lji_key, len, "%s", key);
        new_item->lji_type = type;
        new_item->lji_next = NULL;
 
        new_item->lji_type = type;
        new_item->lji_next = NULL;
 
@@ -295,7 +295,7 @@ int llapi_json_add_item(struct llapi_json_item_list **json_items,
                new_item->lji_string = calloc(len, sizeof(char));
                if (new_item->lji_string == NULL)
                        return -ENOMEM;
                new_item->lji_string = calloc(len, sizeof(char));
                if (new_item->lji_string == NULL)
                        return -ENOMEM;
-               strlcpy(new_item->lji_string, (char *)val, len);
+               snprintf(new_item->lji_string, len, "%s", (char *)val);
                break;
        default:
                llapi_err_noerrno(LLAPI_MSG_ERROR, "Unknown JSON type: %d",
                break;
        default:
                llapi_err_noerrno(LLAPI_MSG_ERROR, "Unknown JSON type: %d",
index fbc7542..f0f1991 100644 (file)
@@ -41,7 +41,6 @@
 #include <sys/stat.h>
 #include <sys/syscall.h>
 #include <lustre/lustreapi.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
 #include <lustre/lustreapi.h>
-#include <libcfs/util/string.h>        /* only needed for compat strlcpy() */
 #include <linux/lustre/lustre_ver.h>   /* only until LUSTRE_VERSION_CODE is gone */
 #include "lustreapi_internal.h"
 
 #include <linux/lustre/lustre_ver.h>   /* only until LUSTRE_VERSION_CODE is gone */
 #include "lustreapi_internal.h"
 
@@ -137,7 +136,7 @@ int llapi_get_version_string(char *version, unsigned int version_size)
                return -1;
        }
 
                return -1;
        }
 
-       if (strlcpy(version, ptr, version_size) >= version_size) {
+       if (snprintf(version, version_size, "%s", ptr) >= version_size) {
                errno = EOVERFLOW;
                return -1;
        }
                errno = EOVERFLOW;
                return -1;
        }
index 509c67d..7db491b 100644 (file)
@@ -571,8 +571,9 @@ int lr_get_symlink(struct lr_info *info)
         } else {
                 link = info->linktmp;
         }
         } else {
                 link = info->linktmp;
         }
-       strlcpy(info->link, link, sizeof(info->link));
-
+       rc = snprintf(info->link, sizeof(info->link), "%s", link);
+       if (rc >= sizeof(info->link))
+               rc = -E2BIG;
        return rc;
 }
 
        return rc;
 }
 
@@ -640,13 +641,16 @@ int lr_add_pc(const char *pfid, const char *tfid, const char *name)
        p = calloc(1, sizeof(*p));
        if (p == NULL)
                return -ENOMEM;
        p = calloc(1, sizeof(*p));
        if (p == NULL)
                return -ENOMEM;
-       len = strlcpy(p->pc_log.pcl_pfid, pfid, sizeof(p->pc_log.pcl_pfid));
+       len = snprintf(p->pc_log.pcl_pfid, sizeof(p->pc_log.pcl_pfid),
+                      "%s", pfid);
        if (len >= sizeof(p->pc_log.pcl_pfid))
                goto out_err;
        if (len >= sizeof(p->pc_log.pcl_pfid))
                goto out_err;
-       len = strlcpy(p->pc_log.pcl_tfid, tfid, sizeof(p->pc_log.pcl_tfid));
+       len = snprintf(p->pc_log.pcl_tfid, sizeof(p->pc_log.pcl_tfid),
+                      "%s", tfid);
        if (len >= sizeof(p->pc_log.pcl_tfid))
                goto out_err;
        if (len >= sizeof(p->pc_log.pcl_tfid))
                goto out_err;
-       len = strlcpy(p->pc_log.pcl_name, name, sizeof(p->pc_log.pcl_name));
+       len = snprintf(p->pc_log.pcl_name, sizeof(p->pc_log.pcl_name),
+                      "%s", name);
        if (len >= sizeof(p->pc_log.pcl_name))
                goto out_err;
 
        if (len >= sizeof(p->pc_log.pcl_name))
                goto out_err;
 
@@ -1058,7 +1062,8 @@ int lr_link(struct lr_info *info)
                                 info->path);
 
                        if (strcmp(srcpath, info->dest) != 0) {
                                 info->path);
 
                        if (strcmp(srcpath, info->dest) != 0) {
-                               strlcpy(info->src, srcpath, sizeof(info->src));
+                               snprintf(info->src, sizeof(info->src), "%s",
+                                        srcpath);
                                lr_debug(DINFO, "link source is %s\n",
                                         info->src);
                        }
                                lr_debug(DINFO, "link source is %s\n",
                                         info->src);
                        }
@@ -1171,7 +1176,7 @@ int lr_parse_line(void *priv, struct lr_info *info)
        namelen = strnlen(changelog_rec_name(rec), rec->cr_namelen);
        if (copylen > namelen + 1)
                copylen = namelen + 1;
        namelen = strnlen(changelog_rec_name(rec), rec->cr_namelen);
        if (copylen > namelen + 1)
                copylen = namelen + 1;
-       strlcpy(info->name, changelog_rec_name(rec), copylen);
+       snprintf(info->name, copylen, "%s", changelog_rec_name(rec));
 
        /* Don't use rnm if CLF_RENAME isn't set */
        rnm = changelog_rec_rename(rec);
 
        /* Don't use rnm if CLF_RENAME isn't set */
        rnm = changelog_rec_rename(rec);
@@ -1185,7 +1190,7 @@ int lr_parse_line(void *priv, struct lr_info *info)
                namelen = changelog_rec_snamelen(rec);
                if (copylen > namelen + 1)
                        copylen = namelen + 1;
                namelen = changelog_rec_snamelen(rec);
                if (copylen > namelen + 1)
                        copylen = namelen + 1;
-               strlcpy(info->sname, changelog_rec_sname(rec), copylen);
+               snprintf(info->sname, copylen, "%s", changelog_rec_sname(rec));
 
                if (verbose > 1)
                        printf("Rec %lld: %d %s %s\n", info->recno, info->type,
 
                if (verbose > 1)
                        printf("Rec %lld: %d %s %s\n", info->recno, info->type,
@@ -1359,20 +1364,24 @@ int lr_read_log()
                 status->ls_last_recno = s->ls_last_recno;
 
        if (status->ls_registration[0] == '\0')
                 status->ls_last_recno = s->ls_last_recno;
 
        if (status->ls_registration[0] == '\0')
-               strlcpy(status->ls_registration, s->ls_registration,
-                       sizeof(status->ls_registration));
+               snprintf(status->ls_registration,
+                        sizeof(status->ls_registration), "%s",
+                        s->ls_registration);
 
        if (status->ls_mdt_device[0] == '\0')
 
        if (status->ls_mdt_device[0] == '\0')
-               strlcpy(status->ls_mdt_device, s->ls_mdt_device,
-                       sizeof(status->ls_mdt_device));
+               snprintf(status->ls_mdt_device,
+                        sizeof(status->ls_mdt_device), "%s",
+                        s->ls_mdt_device);
 
        if (status->ls_source_fs[0] == '\0')
 
        if (status->ls_source_fs[0] == '\0')
-               strlcpy(status->ls_source_fs, s->ls_source_fs,
-                       sizeof(status->ls_source_fs));
+               snprintf(status->ls_source_fs,
+                        sizeof(status->ls_source_fs), "%s",
+                        s->ls_source_fs);
 
        if (status->ls_source[0] == '\0')
 
        if (status->ls_source[0] == '\0')
-               strlcpy(status->ls_source, s->ls_source,
-                       sizeof(status->ls_source));
+               snprintf(status->ls_source,
+                        sizeof(status->ls_source), "%s",
+                        s->ls_source);
 
  out:
         if (fd != -1)
 
  out:
         if (fd != -1)
@@ -1399,9 +1408,9 @@ int lr_clear_cl(struct lr_info *info, int force)
                         /* llapi_changelog_clear modifies the mdt
                          * device name so make a copy of it until this
                          * is fixed.
                         /* llapi_changelog_clear modifies the mdt
                          * device name so make a copy of it until this
                          * is fixed.
-                        */
-                       strlcpy(mdt_device, status->ls_mdt_device,
-                               sizeof(mdt_device));
+                        */
+                       snprintf(mdt_device, sizeof(mdt_device), "%s",
+                                status->ls_mdt_device);
                         rc = llapi_changelog_clear(mdt_device,
                                                    status->ls_registration,
                                                    rec);
                         rc = llapi_changelog_clear(mdt_device,
                                                    status->ls_registration,
                                                    rec);
@@ -1597,8 +1606,10 @@ int lr_replicate()
                        memcpy(info->spfid, info->pfid, sizeof(info->spfid));
                        memcpy(info->tfid, ext->tfid, sizeof(info->tfid));
                        memcpy(info->pfid, ext->pfid, sizeof(info->pfid));
                        memcpy(info->spfid, info->pfid, sizeof(info->spfid));
                        memcpy(info->tfid, ext->tfid, sizeof(info->tfid));
                        memcpy(info->pfid, ext->pfid, sizeof(info->pfid));
-                       strlcpy(info->sname, info->name, sizeof(info->sname));
-                       strlcpy(info->name, ext->name, sizeof(info->name));
+                       snprintf(info->sname, sizeof(info->sname), "%s",
+                                info->name);
+                       snprintf(info->name, sizeof(info->name), "%s",
+                                ext->name);
                        info->is_extended = 1;
                }
 
                        info->is_extended = 1;
                }
 
@@ -1713,8 +1724,8 @@ int main(int argc, char *argv[])
                         break;
                 case 's':
                         /* Assume absolute paths */
                         break;
                 case 's':
                         /* Assume absolute paths */
-                       strlcpy(status->ls_source, optarg,
-                               sizeof(status->ls_source));
+                       snprintf(status->ls_source, sizeof(status->ls_source),
+                                "%s", optarg);
                         break;
                 case 't':
                         status->ls_num_targets++;
                         break;
                 case 't':
                         status->ls_num_targets++;
@@ -1735,16 +1746,18 @@ int main(int argc, char *argv[])
                                 if (status == NULL)
                                         return -ENOMEM;
                         }
                                 if (status == NULL)
                                         return -ENOMEM;
                         }
-                       strlcpy(status->ls_targets[status->ls_num_targets - 1],
-                               optarg, sizeof(status->ls_targets[0]));
+                       snprintf(status->ls_targets[status->ls_num_targets - 1],
+                                sizeof(status->ls_targets[0]), "%s", optarg);
                        break;
                case 'm':
                        break;
                case 'm':
-                       strlcpy(status->ls_mdt_device, optarg,
-                               sizeof(status->ls_mdt_device));
+                       snprintf(status->ls_mdt_device,
+                                sizeof(status->ls_mdt_device),
+                                "%s", optarg);
                        break;
                case 'u':
                        break;
                case 'u':
-                       strlcpy(status->ls_registration, optarg,
-                               sizeof(status->ls_registration));
+                       snprintf(status->ls_registration,
+                                sizeof(status->ls_registration),
+                                "%s", optarg);
                         break;
                 case 'l':
                         statuslog = optarg;
                         break;
                 case 'l':
                         statuslog = optarg;
index 22689b3..fbfb1a0 100644 (file)
@@ -235,20 +235,38 @@ static int parse_one_option(const char *check, int *flagp)
         return 0;
 }
 
         return 0;
 }
 
+static size_t merge_strings(char *dst, const char *src, size_t size)
+{
+       size_t dsize = strlen(dst);
+       size_t len = strlen(src);
+       size_t ret = dsize + len;
+
+       dst  += dsize;
+       size -= dsize;
+       if (len >= size)
+               len = size - 1;
+       memcpy(dst, src, len);
+       dst[len] = '\0';
+       return ret;
+}
+
 static int append_option(char *options, size_t options_len,
                         const char *param, const char *value)
 {
        int rc;
 static int append_option(char *options, size_t options_len,
                         const char *param, const char *value)
 {
        int rc;
+
        if (options[0] != '\0') {
        if (options[0] != '\0') {
-               rc = strlcat(options, ",", options_len);
+               rc = merge_strings(options, ",", options_len);
                if (rc >= options_len)
                        goto out_err;
        }
                if (rc >= options_len)
                        goto out_err;
        }
-       rc = strlcat(options, param, options_len);
+
+       rc = merge_strings(options, param, options_len);
        if (rc >= options_len)
                goto out_err;
        if (rc >= options_len)
                goto out_err;
+
        if (value != NULL) {
        if (value != NULL) {
-               rc = strlcat(options, value, options_len);
+               rc = merge_strings(options, value, options_len);
                if (rc >= options_len)
                        goto out_err;
        }
                if (rc >= options_len)
                        goto out_err;
        }
index 09775d2..0bfdd11 100644 (file)
@@ -3909,7 +3909,7 @@ static int extract_fsname_poolname(const char *arg, char *fsname,
        char *ptr;
        int rc;
 
        char *ptr;
        int rc;
 
-       strlcpy(fsname, arg, PATH_MAX + 1);
+       snprintf(fsname, PATH_MAX + 1, "%s", arg);
        ptr = strchr(fsname, '.');
        if (ptr == NULL) {
                fprintf(stderr, ". is missing in %s\n", fsname);
        ptr = strchr(fsname, '.');
        if (ptr == NULL) {
                fprintf(stderr, ". is missing in %s\n", fsname);
index e5cf799..4016388 100644 (file)
 #include <time.h>
 #include <linux/types.h>
 
 #include <time.h>
 #include <linux/types.h>
 
-#include <libcfs/util/string.h>
 #include <libcfs/util/ioctl.h>
 #include <linux/lnet/libcfs_debug.h>
 #include <linux/lnet/lnet-dlc.h>
 #include <linux/lnet/lnetctl.h>
 #include <linux/lnet/nidstr.h>
 #include <linux/lnet/socklnd.h>
 #include <libcfs/util/ioctl.h>
 #include <linux/lnet/libcfs_debug.h>
 #include <linux/lnet/lnet-dlc.h>
 #include <linux/lnet/lnetctl.h>
 #include <linux/lnet/nidstr.h>
 #include <linux/lnet/socklnd.h>
+#include <lustre/lustreapi.h>
 
 unsigned int libcfs_debug;
 unsigned int libcfs_printk = D_CANTMASK;
 
 unsigned int libcfs_debug;
 unsigned int libcfs_printk = D_CANTMASK;
@@ -177,7 +177,7 @@ ptl_ipaddr_2_str(__u32 ipaddr, char *str, size_t strsize, int lookup)
                 net_ip = htonl (ipaddr);
                 he = gethostbyaddr (&net_ip, sizeof (net_ip), AF_INET);
                 if (he != NULL) {
                 net_ip = htonl (ipaddr);
                 he = gethostbyaddr (&net_ip, sizeof (net_ip), AF_INET);
                 if (he != NULL) {
-                       strlcpy(str, he->h_name, strsize);
+                       snprintf(str, strsize, "%s", he->h_name);
                         return (str);
                 }
         }
                         return (str);
                 }
         }