This file is indexed.

/var/lib/pcp/testsuite/src/github-50.c is in pcp-testsuite 4.0.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Copyright (c) 1995-2001 Silicon Graphics, Inc.  All Rights Reserved.
 * Copyright (c) 2015 Ken McDonell.  All Rights Reserved.
 *
 * Locking bug in libpcp ... see
 * https://github.com/performancecopilot/pcp/pull/50
 */

#include <pcp/pmapi.h>
#include "libpcp.h"

#define BUILD_STANDALONE

int
main(int argc, char **argv)
{
    int		c;
    int		sts;
    int		errflag = 0;
    int		type = 0;
    int		try = 0;
    char	*host = NULL;			/* pander to gcc */
    pmLogLabel	label;
    __pmContext	*ctxp;

    /* trim cmd name of leading directory components */
    pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "a:D:h:Lx?")) != EOF) {
	switch (c) {

	case 'a':	/* archive name */
	    if (type != 0) {
#ifdef BUILD_STANDALONE
		fprintf(stderr, "%s: at most one of -a, -h, -L and -x allowed\n", pmGetProgname());
#else
		fprintf(stderr, "%s: at most one of -a and -h allowed\n", pmGetProgname());
#endif
		errflag++;
	    }
	    type = PM_CONTEXT_ARCHIVE;
	    host = optarg;
	    break;

	case 'D':	/* debug options */
	    sts = pmSetDebug(optarg);
	    if (sts < 0) {
		fprintf(stderr, "%s: unrecognized debug options specification (%s)\n",
		    pmGetProgname(), optarg);
		errflag++;
	    }
	    break;

	case 'h':	/* contact PMCD on this hostname */
	    if (type != 0) {
#ifdef BUILD_STANDALONE
		fprintf(stderr, "%s: at most one of -a, -h, -L and -x allowed\n", pmGetProgname());
#else
		fprintf(stderr, "%s: at most one of -a and -h allowed\n", pmGetProgname());
#endif
		errflag++;
	    }
	    host = optarg;
	    type = PM_CONTEXT_HOST;
	    break;

#ifdef BUILD_STANDALONE
	case 'L':	/* LOCAL, no PMCD */
	    if (type != 0) {
		fprintf(stderr, "%s: at most one of -a, -h, -L and -x allowed\n", pmGetProgname());
		errflag++;
	    }
	    host = NULL;
	    type = PM_CONTEXT_LOCAL;
	    putenv("PMDA_LOCAL_PROC=");		/* if proc PMDA needed */
	    putenv("PMDA_LOCAL_SAMPLE=");	/* if sampledso PMDA needed */
	    break;
#endif

	case 'x':	/* no current context */
	    if (type != 0) {
		fprintf(stderr, "%s: at most one of -a, -h, -L and -x allowed\n", pmGetProgname());
		errflag++;
	    }
	    type = -1;
	    break;
	case '?':
	default:
	    errflag++;
	    break;
	}
    }

    if (errflag) {
	fprintf(stderr,
"Usage: %s [options]\n\
\n\
Options:\n\
  -a archive     metrics source is a PCP log archive\n\
  -h host        metrics source is PMCD on host\n"
#ifdef BUILD_STANDALONE
"  -L             use local context instead of PMCD\n"
#endif
"  -x             no current context\n"
	    , pmGetProgname());
        exit(1);
    }

    if (type != -1) {
	if (type == 0) {
	    /* default context */
	    type = PM_CONTEXT_HOST;
	    host = "local:";
	}
	if ((sts = pmNewContext(type, host)) < 0) {
	    if (type == PM_CONTEXT_HOST)
		fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
		    pmGetProgname(), host, pmErrStr(sts));
    #ifdef BUILD_STANDALONE
	    else if (type == PM_CONTEXT_LOCAL)
		fprintf(stderr, "%s: Cannot initialize LOCAL context: %s\n",
		    pmGetProgname(), pmErrStr(sts));
    #endif
	    else
		fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
		    pmGetProgname(), host, pmErrStr(sts));
	    exit(1);
	}
    }

    if ((sts = pmGetArchiveLabel(&label)) < 0)
	fprintf(stderr, "%s: Cannot get archive label record: %s\n",
	    pmGetProgname(), pmErrStr(sts));
    else
	fprintf(stderr, "%s: archive label record: magic=%x host=%s\n",
	    pmGetProgname(), label.ll_magic, label.ll_hostname);

    ctxp = __pmHandleToPtr(pmWhichContext());
    if (ctxp == NULL) {
	fprintf(stderr, "%s: __pmHandleToPtr botch: for context=%d\n",
	    pmGetProgname(), pmWhichContext());
	exit(1);
    }

    /*
     * Should Unlock OK just once ... from the __pmHandleToPtr() call
     * above.
     * In the bug case, when the context is valid and _not_ an archive,
     * the Unlock OK happens twice
     */
    while (try < 3 && (sts = PM_UNLOCK(ctxp->c_lock)) == 0) {
	fprintf(stderr, "Unlock OK\n");
	try++;
    }
    fprintf(stderr, "Unlock Fail: %s\n", pmErrStr(sts));

    return 0;
}