Skip to content

Commit

Permalink
indomcachectl: second round of changes
Browse files Browse the repository at this point in the history
- force mode to 0660 for the files so group read+and+write is
  enabled
- convert remaining PMDA Install scripts to use indomcachectl
  in lieu of explict touch+chmod that leads to warnings for
  an empty file from pmdaCacheOp()
  • Loading branch information
kmcdonell committed Apr 12, 2024
1 parent 5bd1de5 commit 653ff2c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 42 deletions.
6 changes: 6 additions & 0 deletions man/man1/indomcachectl.1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ Because the indom cache files are precious to the associated PMDA
.I indomcachectl
will not over-write an existing indom cache file.
.PP
The instance domain cache file is created with mode 0660 \- if this
does not suit, callers should run
.BR chmod (1)
subsequently.
.PP
Operation is usually silent, except for errors (or warnings if the
.I \-w
option is used).
Expand Down Expand Up @@ -106,6 +111,7 @@ Following that is one line per instance with the instance identifier
(do not change) and the external instance name in the third field.
.SH SEE ALSO
.BR PCPIntro (1),
.BR chmod (1),
.BR pminfo (1),
.BR PMAPI (3),
.BR PMDA (3),
Expand Down
15 changes: 12 additions & 3 deletions src/indomcachectl/indomcachectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "pmapi.h"
#include "pmda.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>

static pmLongOptions longopts[] = {
Expand Down Expand Up @@ -124,20 +125,28 @@ main(int argc, char **argv)
}

/*
* initialize ...
* initialize ... enable group reading and writing as some PMDAs depend
* on this
*/
umask(S_IWOTH);
if ((sts = pmdaCacheOp(indom, PMDA_CACHE_WRITE)) < 0) {
if (wflag)
fprintf(stderr, "Warning: %s: PMDA_CACHE_WRITE: %s\n", pmInDomStr(indom), pmErrStr(sts));
}
pmsprintf(pathname, sizeof(pathname), "%s%cconfig%cpmda%c%s",
pmGetOptionalConfig("PCP_VAR_DIR"), sep, sep, sep, pmInDomStr(indom));
if (user) {
pmsprintf(pathname, sizeof(pathname), "%s%cconfig%cpmda%c%s",
pmGetOptionalConfig("PCP_VAR_DIR"), sep, sep, sep, pmInDomStr(indom));
/* change owner and group */
if (chown(pathname, pw->pw_uid, pw->pw_gid) < 0) {
fprintf(stderr, "%s: Error: created %s, but cannot change ownership: %s\n", pmGetProgname(), pathname, pmErrStr(-oserror()));
exit(1);
}
}
/* explicitly make mode 660 */
if (chmod(pathname, 0660) < 0) {
fprintf(stderr, "%s: Error: created %s, but cannot change mode: %s\n", pmGetProgname(), pathname, pmErrStr(-oserror()));
exit(1);
}

exit(0);
}
17 changes: 14 additions & 3 deletions src/pmdas/denki/Install
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ args="-U root"
#
if [ -d $PCP_VAR_DIR/config/pmda ]
then
touch $PCP_VAR_DIR/config/pmda/$domain.1
chown $PCP_USER:$PCP_GROUP $PCP_VAR_DIR/config/pmda/$domain.1
chmod 644 $PCP_VAR_DIR/config/pmda/$domain.1
if [ ! -f "$PCP_VAR_DIR/config/pmda/$domain.1" ]
then
# First time Install, initialize PMDA's indom cache file
#
if "$PCP_BINADM_DIR/indomcachectl" -u $PCP_USER $domain.1
then
:
else
echo "Cannot create indom cache file"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.1"
status=1
exit
fi
fi
fi

pmdaSetup
Expand Down
24 changes: 13 additions & 11 deletions src/pmdas/haproxy/Install
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ mkdir -p "$PCP_VAR_DIR/config/pmda" 2>/dev/null
indoms="0"
for indom in $indoms
do
failed=false
touch "$PCP_VAR_DIR/config/pmda/$domain.$indom" >/dev/null 2>&1
[ $? -ne 0 ] && failed=true
chown $user "$PCP_VAR_DIR/config/pmda/$domain.$indom"
[ $? -ne 0 ] && failed=true

if $failed; then
echo "Cannot create indom persistance files for user $user"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.$indom"
status=1
exit
if [ ! -f "$PCP_VAR_DIR/config/pmda/$domain.$indom" ]
then
# First time Install, initialize PMDA's indom cache file
#
if "$PCP_BINADM_DIR/indomcachectl" -u $user $domain.$indom
then
:
else
echo "Cannot create indom cache files for user $user"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.$indom"
status=1
exit
fi
fi
done

Expand Down
2 changes: 1 addition & 1 deletion src/pmdas/libvirt/Install
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ do
then
:
else
echo "Cannot create indom persistance files for user $user"
echo "Cannot create indom cache files for user $user"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.$indom"
status=1
exit
Expand Down
24 changes: 13 additions & 11 deletions src/pmdas/oracle/Install
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ mkdir -p "$PCP_VAR_DIR/config/pmda" 2>/dev/null
indoms="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17"
for indom in $indoms
do
failed=false
touch "$PCP_VAR_DIR/config/pmda/$domain.$indom" >/dev/null 2>&1
[ $? -ne 0 ] && failed=true
chown $os_user "$PCP_VAR_DIR/config/pmda/$domain.$indom"
[ $? -ne 0 ] && failed=true

if $failed; then
echo "Cannot create indom persistance files for user $os_user"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.$indom"
status=1
exit
if [ ! -f "$PCP_VAR_DIR/config/pmda/$domain.$indom" ]
then
# First time Install, initialize PMDA's indom cache file
#
if "$PCP_BINADM_DIR/indomcachectl" -u $os_user $domain.$indom
then
:
else
echo "Cannot create indom cache files for user $user"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.$indom"
status=1
exit
fi
fi
done

Expand Down
19 changes: 9 additions & 10 deletions src/pmdas/postgresql/Install
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ if [ -n "$osuser" ]; then
failed=false
c="$PCP_VAR_DIR/config/pmda/$domain.$indom"
if [ ! -f "$c" ]; then
if touch $c >/dev/null 2>&1; then
# TODO need a pmda cache init function
echo "2 0 2147483647" >> $c # standard v2 header
chmod 664 "$c"
chgrp $gid "$c"
else
echo "Error: failed to create indom persistance file \"$c\""
status=1
exit
fi
# First time Install, initialize PMDA's indom cache file
#
if "$PCP_BINADM_DIR/indomcachectl" $domain.$indom; then
chgrp $gid "$c"
else
echo "Error: failed to create indom cache file \"$c\""
status=1
exit
fi
fi
done
fi
Expand Down
17 changes: 14 additions & 3 deletions src/pmdas/simple/Install
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,20 @@ then
fi
if [ -d $PCP_VAR_DIR/config/pmda ]
then
touch $PCP_VAR_DIR/config/pmda/$domain.1
chown $PCP_USER:$PCP_GROUP $PCP_VAR_DIR/config/pmda/$domain.1
chmod 644 $PCP_VAR_DIR/config/pmda/$domain.1
if [ ! -f "$PCP_VAR_DIR/config/pmda/$domain.1" ]
then
# First time Install, initialize PMDA's indom cache file
#
if "$PCP_BINADM_DIR/indomcachectl" -u $PCP_USER $domain.1
then
:
else
echo "Cannot create indom cache file"
echo "Failed on: $PCP_VAR_DIR/config/pmda/$domain.1"
status=1
exit
fi
fi
fi

pmdaSetup
Expand Down

0 comments on commit 653ff2c

Please sign in to comment.