tools/libs: stat: Use const whenever we point to literal strings
authorJulien Grall <jgrall@amazon.com>
Tue, 18 May 2021 13:35:07 +0000 (14:35 +0100)
committerJulien Grall <jgrall@amazon.com>
Tue, 18 May 2021 13:54:05 +0000 (14:54 +0100)
literal strings are not meant to be modified. So we should use const
char * rather than char * when we want to store a pointer to them.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Wei Liu <wl@xen.org>
tools/libs/stat/xenstat_linux.c
tools/libs/stat/xenstat_qmp.c

index c00b26d4d8980f26ccb96ccb57e3e5df2ef6ed9b..875a0617ade8b616515e505097ff27609fe3e9a7 100644 (file)
@@ -66,7 +66,7 @@ static const char PROCNETDEV_HEADER[] =
 
 /* We need to get the name of the bridge interface for use with bonding interfaces */
 /* Use excludeName parameter to avoid adding bridges we don't care about, eg. virbr0 */
-static void getBridge(char *excludeName, char *result, size_t resultLen)
+static void getBridge(const char *excludeName, char *result, size_t resultLen)
 {
        struct dirent *de;
        DIR *d;
@@ -113,7 +113,7 @@ static int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes,
        int num = 19;
 
        /* Regular exception to parse all the information from /proc/net/dev line */
-       char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)"
+       const char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)"
                        "[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*"
                        "([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)";
 
index 0c5748ba68b3112dc0d332a89e2567225a8b3a58..2205a041313b0ad0747b3d3794a071dd65d516d2 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <yajl/yajl_tree.h>
 
-static unsigned char *qmp_query(int, char *);
+static unsigned char *qmp_query(int, const char *);
 
 enum query_blockstats {
     QMP_STATS_RETURN  = 0,
@@ -80,7 +80,7 @@ enum query_block {
 static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
 {
        char *tmp, *file = NULL;
-       char *query_block_cmd = "{ \"execute\": \"query-block\" }";
+       const char *query_block_cmd = "{ \"execute\": \"query-block\" }";
        static const char *const qblock[] = {
                [ QMP_BLOCK_RETURN  ] = "return",
                [ QMP_BLOCK_DEVICE  ] = "device",
@@ -264,7 +264,7 @@ done:
 }
 
 /* Write a command via the QMP. Returns number of bytes written */
-static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
+static size_t qmp_write(int qfd, const char *cmd, size_t cmd_len)
 {
        size_t pos = 0;
        ssize_t res;
@@ -317,7 +317,7 @@ static int qmp_read(int qfd, unsigned char **qstats)
 }
 
 /* With the given cmd, query QMP for requested data. Returns allocated buffer containing data or NULL */
-static unsigned char *qmp_query(int qfd, char *cmd)
+static unsigned char *qmp_query(int qfd, const char *cmd)
 {
        unsigned char *qstats = NULL;
        int n;
@@ -385,8 +385,8 @@ static int qmp_connect(char *path)
 */
 static void read_attributes_qdisk_dom(xenstat_node *node, domid_t domain)
 {
-       char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
-       char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
+       const char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
+       const char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
        unsigned char *qmp_stats, *val;
        char path[80];
        int qfd;