pcp
[Top] [All Lists]

[PATCH] Make pmdaDaemon() take const strings

To: pcp@xxxxxxxxxxx
Subject: [PATCH] Make pmdaDaemon() take const strings
From: David Gibson <pcp@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 10 Aug 2016 21:08:07 +1000
Cc: mgoodwin@xxxxxxxxxx
Delivered-to: pcp@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1470827169; bh=fA8vl54mK+kejUvYXduZ/0yAqqJAZ9Aws7m6PU0a1CI=; h=Date:From:To:Cc:Subject:From; b=QzYIB9+tJXUsj8oKO/NgA+8YylQt2MyBWMG1YKlKa1LnknWXKE2ZvCGsTvad8TN5Z kz+47YB/v/dyH8rPbYHBqvbTtXZTadTAHhXp5mmUnfq1vkTb08g6PePiCJ/IpQOsRT ychsdOgWs682xG2GBrhPRnZ+v9nbTFoNVpyMvTOw=
User-agent: Mutt/1.6.2 (2016-07-01)
From: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>

As far as I can tell, the name, logfile and helptext strings passed to
pmdaDaemon() should never be modified in place.  However, they're declared
as char *, rather than const char *.

This patch changes the signature, and propagates the necessary changes
through to __pmdaSetup() and the pmdaExt structure.

Signed-off-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>
---
 src/include/pcp/pmda.h     | 9 +++++----
 src/libpcp_pmda/src/open.c | 6 +++---
 2 files changed, 8 insertions(+), 7 deletions(-)

Hi, haven't contributed to PCP before, testing the waters with this
pretty trivial cleanup.  I encountered this while trying to write a
PMDA in C++ - that gives warnings when attempting to pass string
literals into these (char *) parameters.

diff --git a/src/include/pcp/pmda.h b/src/include/pcp/pmda.h
index 61b6db9..a211448 100644
--- a/src/include/pcp/pmda.h
+++ b/src/include/pcp/pmda.h
@@ -123,9 +123,9 @@ typedef struct pmdaExt {
     void       *e_ext;         /* used internally within libpcp_pmda */
 
     char       *e_sockname;    /* socket name to pmcd */
-    char       *e_name;        /* name of this pmda */
-    char       *e_logfile;     /* path to log file */
-    char       *e_helptext;    /* path to help text */             
+    const char *e_name;        /* name of this pmda */
+    const char *e_logfile;     /* path to log file */
+    const char *e_helptext;    /* path to help text */
     int                e_status;       /* =0 is OK */
     int                e_infd;         /* input file descriptor from pmcd */
     int                e_outfd;        /* output file descriptor to pmcd */
@@ -424,7 +424,8 @@ typedef struct pmdaOptions {
 PMDA_CALL extern int pmdaGetOpt(int, char *const *, const char *, 
pmdaInterface *, int *);
 PMDA_CALL extern int pmdaGetOptions(int, char *const *, pmdaOptions *, 
pmdaInterface *);
 PMDA_CALL extern void pmdaUsageMessage(pmdaOptions *);
-PMDA_CALL extern void pmdaDaemon(pmdaInterface *, int, char *, int , char *, 
char *);
+PMDA_CALL extern void pmdaDaemon(pmdaInterface *, int, const char *, int,
+                                const char *, const char *);
 PMDA_CALL extern void pmdaDSO(pmdaInterface *, int, char *, char *);
 PMDA_CALL extern void pmdaOpenLog(pmdaInterface *);
 PMDA_CALL extern void pmdaSetFlags(pmdaInterface *, int);
diff --git a/src/libpcp_pmda/src/open.c b/src/libpcp_pmda/src/open.c
index 02f771a..8896a9a 100644
--- a/src/libpcp_pmda/src/open.c
+++ b/src/libpcp_pmda/src/open.c
@@ -899,7 +899,7 @@ pmdaConnect(pmdaInterface *dispatch)
  */
 
 static void
-__pmdaSetup(pmdaInterface *dispatch, int version, char *name)
+__pmdaSetup(pmdaInterface *dispatch, int version, const char *name)
 {
     pmdaExt    *pmda = NULL;
     e_ext_t    *extp;
@@ -980,8 +980,8 @@ __pmdaSetup(pmdaInterface *dispatch, int version, char 
*name)
  */
 
 void
-pmdaDaemon(pmdaInterface *dispatch, int version, char *name, int domain, 
-          char *logfile, char *helptext)
+pmdaDaemon(pmdaInterface *dispatch, int version, const char *name, int domain,
+          const char *logfile, const char *helptext)
 {
     pmdaExt    *pmda;
 
-- 
2.1.4


-- 
David Gibson                    | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
                                | _way_ _around_!
http://www.ozlabs.org/~dgibson

Attachment: signature.asc
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>