Skip to content
Snippets Groups Projects
Commit 2a72f595 authored by Dennis Waldron's avatar Dennis Waldron
Browse files

Fixed compilation warning and provided as flag to ignore error messages related to forced CNS hosts

parent 91e11b76
Branches
Tags
No related merge requests found
......@@ -14,13 +14,17 @@
#include "Cns_api.h"
#include "Cgetopt.h"
#include "serrno.h"
#include "getconfent.h"
void usage(int status, char *name) {
if (status != 0) {
fprintf (stderr, "Try `%s --help` for more information.\n", name);
} else {
printf ("Usage: %s <CNSHOST> [FILEID|-x HEXID]\n", name);
printf ("Usage: %s [OPTION] <CNSHOST> [FILEID|-x HEXID]\n", name);
printf ("Resolve a fileid to a filepath.\n\n");
printf (" -x, --hex=HEXID the fileid represented in hexidecimal\n");
printf (" -i, --ignore ignore error messages related to forced CNS hosts\n");
printf (" --help display this help and exit\n\n");
printf ("Report bugs to <castor.support@cern.ch>.\n");
}
exit (status);
......@@ -31,26 +35,25 @@ int main(int argc, char**argv) {
int c;
int errflg = 0;
int hflg = 0;
int iflg = 0;
int i = 0;
int j = 0;
u_signed64 fileid = 0;
char *server = NULL;
char filepath[CA_MAXPATHLEN + 1];
char tmpbuf[21];
char *p = NULL;
Coptind = 1;
if (argc >= 3) {
server = argv[1];
fileid = strtou64(argv[2]);
Coptind = 2;
}
Coptions_t longopts[] = {
{ "help", NO_ARGUMENT, &hflg, 1 },
{ NULL, 0, NULL, 0 }
{ "help", NO_ARGUMENT, &hflg, 1 },
{ "hex", REQUIRED_ARGUMENT, NULL, 'x' },
{ "ignore", NO_ARGUMENT, NULL, 'i' },
{ NULL, 0, NULL, 0 }
};
Copterr = 1;
while ((c = Cgetopt_long (argc, argv, "x:", longopts, NULL)) != EOF) {
Coptind = 1;
while ((c = Cgetopt_long (argc, argv, "x:i", longopts, NULL)) != EOF) {
switch (c) {
case 'x':
fileid = strtoull(Coptarg, NULL, 16);
......@@ -60,6 +63,9 @@ int main(int argc, char**argv) {
exit (USERR);
}
break;
case 'i':
iflg++;
break;
case '?':
errflg++;
break;
......@@ -67,18 +73,29 @@ int main(int argc, char**argv) {
break;
}
}
for (i = Coptind, j = 0; i < argc && j < 2; i++, j++) {
if (j == 0) {
server = argv[i];
} else if (fileid == 0) {
fileid = strtou64(argv[i]);
}
}
if (hflg) {
usage (0, argv[0]);
}
if (errflg || (server == NULL) || (fileid == 0)) {
usage (USERR, argv[0]);
}
if ((p = getenv (CNS_HOST_ENV)) ||
(p = getconfent (CNS_SCE, "HOST", 0))) {
if (strcmp(p, server) != 0) {
fprintf (stderr,
"CNSHOST option is not permitted when CNS/HOST is defined\n");
exit (USERR);
if (!iflg) {
if ((p = getenv (CNS_HOST_ENV)) ||
(p = getconfent (CNS_SCE, "HOST", 0))) {
if (strcmp(p, server) != 0) {
fprintf (stderr,
"cannot query '%s', all name server commands are forced to "
"query '%s'\n", server, p);
exit (USERR);
}
}
}
if (Cns_getpath(server, fileid, filepath) != 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment