X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fdocker%2Frootfs_prefix%2Frootfs_prefix.c;h=fdacf74348468b45f1e60843a9cf8f38f2731a84;hb=7c9d772c992647fcba64a96800c146eb9f1647f8;hp=c27a67afd12eeebfcc94dfba288c5a464bbe4373;hpb=fe6da88c2eb1637ef6dce0a7d928c202ededc450;p=collectd.git diff --git a/contrib/docker/rootfs_prefix/rootfs_prefix.c b/contrib/docker/rootfs_prefix/rootfs_prefix.c index c27a67af..fdacf743 100644 --- a/contrib/docker/rootfs_prefix/rootfs_prefix.c +++ b/contrib/docker/rootfs_prefix/rootfs_prefix.c @@ -1,3 +1,33 @@ +/** + * collectd - contrib/docker/rootfs_prefix/rootfs_prefix.c + * Copyright (C) 2016-2018 Marc Fournier + * Copyright (C) 2016-2018 Ruben Kerkhof + * + * MIT License: + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Marc Fournier + * Ruben Kerkhof + **/ + #define _GNU_SOURCE #include @@ -11,28 +41,22 @@ #define BUFSIZE 256 const char *add_prefix(const char *orig, char *prefixed) { - int status; - int errno; - - if ((strncmp(orig, "/proc", 5) == 0) || (strncmp(orig, "/sys", 4) == 0)) { - - status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig); - if ((unsigned int)status >= BUFSIZE) { - error(status, ENAMETOOLONG, - "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX, - prefixed); - return orig; - } else if (status < 1) { - error(status, errno, - "adding '%s' prefix to file path failed: '%s' -> '%s'", PREFIX, - orig, prefixed); - return orig; - } else { - return (const char *)prefixed; - } + if ((strncmp(orig, "/proc", strlen("/proc")) != 0) && + (strncmp(orig, "/sys", strlen("/sys")) != 0)) + return orig; - } else { + int status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig); + if (status < 1) { + error(status, errno, "adding '%s' prefix to file path failed: '%s' -> '%s'", + PREFIX, orig, prefixed); + return orig; + } else if ((unsigned int)status >= BUFSIZE) { + error(status, ENAMETOOLONG, + "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX, + prefixed); return orig; + } else { + return (const char *)prefixed; } }