Whamcloud - gitweb
LU-947 ptlrpc: allow stopping threads above threads_max
[fs/lustre-release.git] / lustre / utils / liblustreapi_util.c
index db84f98..f0f1991 100644 (file)
@@ -5,7 +5,7 @@
  *
  * (C) Copyright (c) 2015, Cray Inc, all rights reserved.
  *
- * Copyright (c) 2016 Intel Corporation.
+ * Copyright (c) 2016, 2017, Intel Corporation.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the GNU Lesser General Public License
@@ -41,8 +41,7 @@
 #include <sys/stat.h>
 #include <sys/syscall.h>
 #include <lustre/lustreapi.h>
-#include <libcfs/util/string.h>        /* only needed for compat strlcpy() */
-#include <lustre_ver.h>                /* only until LUSTRE_VERSION_CODE is gone */
+#include <linux/lustre/lustre_ver.h>   /* only until LUSTRE_VERSION_CODE is gone */
 #include "lustreapi_internal.h"
 
 /*
@@ -53,7 +52,6 @@
  */
 bool liblustreapi_initialized;
 
-
 /**
  * Initialize the library once at startup.
  *
@@ -124,21 +122,24 @@ int llapi_get_version_string(char *version, unsigned int version_size)
        }
 
        ptr = strstr(buffer, "lustre:");
-       if (ptr != NULL) {
-               llapi_chomp_string(ptr);
+       if (ptr) {
                ptr += strlen("lustre:");
                while (*ptr == ' ' || *ptr == '\t')
                        ptr++;
-
-               if (strlcpy(version, ptr, version_size) >= version_size) {
-                       errno = EOVERFLOW;
-                       return -1;
-               }
        } else {
+               ptr = buffer;
+       }
+       llapi_chomp_string(ptr);
+
+       if (ptr[0] == '\0') {
                errno = ENODATA;
                return -1;
        }
 
+       if (snprintf(version, version_size, "%s", ptr) >= version_size) {
+               errno = EOVERFLOW;
+               return -1;
+       }
        return 0;
 }