diff --git a/lustre/utils/llmount.c b/lustre/utils/llmount.c index 26bb5792e47c00ba48db77cb8e158bebdd7c5855..1270f91def7ac572ac157e571c4abcc89ae00cdb 100644 --- a/lustre/utils/llmount.c +++ b/lustre/utils/llmount.c @@ -36,6 +36,7 @@ int debug = 0; int verbose = 0; int nomtab = 0; +static char *progname = NULL; static void update_mtab_entry(char *spec, char *node, char *type, char *opts, @@ -54,12 +55,12 @@ update_mtab_entry(char *spec, char *node, char *type, char *opts, if (!nomtab) { fp = setmntent(MOUNTED, "a+"); if (fp == NULL) { - fprintf(stderr, "setmntent(%s): %s:", MOUNTED, - strerror (errno)); + fprintf(stderr, "%s: setmntent(%s): %s:", + progname, MOUNTED, strerror (errno)); } else { if ((addmntent (fp, &mnt)) == 1) { - fprintf(stderr, "addmntent: %s:", - strerror (errno)); + fprintf(stderr, "%s: addmntent: %s:", + progname, strerror (errno)); } endmntent(fp); } @@ -109,17 +110,18 @@ parse_options(char * options, struct lustre_mount_data *lmd) lmd->lmd_nal = ptl_name2nal(opteq+1); } else if(!strcmp(opt, "local_nid")) { if (ptl_parse_nid(&nid, opteq+1) != 0) { - fprintf (stderr, "mount: " + fprintf (stderr, "%s: " "can't parse NID %s\n", + progname, opteq+1); return (-1); } lmd->lmd_local_nid = nid; } else if(!strcmp(opt, "server_nid")) { if (ptl_parse_nid(&nid, opteq+1) != 0) { - fprintf (stderr, "mount: " + fprintf (stderr, "%s: " "can't parse NID %s\n", - opteq+1); + progname, opteq+1); return (-1); } lmd->lmd_server_nid = nid; @@ -174,8 +176,8 @@ set_local(struct lustre_mount_data *lmd) if (lmd->lmd_nal == SOCKNAL || lmd->lmd_nal == TCPNAL) { rc = gethostname(buf, sizeof(buf) - 1); if (rc) { - fprintf (stderr, "mount: can't get local buf:" - "%d\n", rc); + fprintf (stderr, "%s: can't get local buf: %d\n", + progname, rc); return rc; } } else if (lmd->lmd_nal == QSWNAL) { @@ -190,14 +192,15 @@ set_local(struct lustre_mount_data *lmd) } while (rc != 0 && pfiles[++i] != NULL); if (rc != 0) { - fprintf(stderr, - "mount: can't read Elan ID from /proc\n"); + fprintf(stderr, "%s: can't read Elan ID from /proc\n", + progname); + return -1; } } if (ptl_parse_nid (&nid, buf) != 0) { - fprintf (stderr, "mount: can't parse NID %s\n", buf); + fprintf (stderr, "%s: can't parse NID %s\n", progname, buf); return (-1); } @@ -214,29 +217,29 @@ set_peer(char *hostname, struct lustre_mount_data *lmd) if (lmd->lmd_nal == SOCKNAL || lmd->lmd_nal == TCPNAL) { if (lmd->lmd_server_nid == PTL_NID_ANY) { if (ptl_parse_nid (&nid, hostname) != 0) { - fprintf (stderr, "mount: can't parse NID %s\n", - hostname); + fprintf (stderr, "%s: can't parse NID %s\n", + progname, hostname); return (-1); } lmd->lmd_server_nid = nid; } if (ptl_parse_ipaddr(&lmd->lmd_server_ipaddr, hostname) != 0) { - fprintf (stderr, "mount: can't parse host %s\n", - hostname); + fprintf (stderr, "%s: can't parse host %s\n", + progname, hostname); return (-1); } } else if (lmd->lmd_nal == QSWNAL) { char buf[64]; rc = sscanf(hostname, "%*[^0-9]%63[0-9]", buf); if (rc != 1) { - fprintf (stderr, "mount: can't get elan id from host %s\n", - hostname); + fprintf (stderr, "%s: can't get elan id from host %s\n", + progname, hostname); return -1; } if (ptl_parse_nid (&nid, buf) != 0) { - fprintf (stderr, "mount: can't parse NID %s\n", - hostname); + fprintf (stderr, "%s: can't parse NID %s\n", + progname, hostname); return (-1); } lmd->lmd_server_nid = nid; @@ -260,8 +263,9 @@ build_data(char *source, char *options, struct lustre_mount_data *lmd) return -EINVAL; if (strlen(source) > sizeof(target) + 1) { - fprintf(stderr, "mount: " - "exessively long host:/mds/profile argument\n"); + fprintf(stderr, "%s: " + "exessively long host:/mds/profile argument\n", + progname); return -EINVAL; } strcpy(target, source); @@ -276,14 +280,16 @@ build_data(char *source, char *options, struct lustre_mount_data *lmd) *s = '\0'; profile = s + 1; } else { - fprintf(stderr, "mount: " + fprintf(stderr, "%s: " "directory to mount not in " - "host:/mds/profile format\n"); + "host:/mds/profile format\n", + progname); return(-1); } } else { - fprintf(stderr, "mount: " - "directory to mount not in host:/mds/profile format\n"); + fprintf(stderr, "%s: " + "directory to mount not in host:/mds/profile format\n", + progname); return(-1); } if (verbose) @@ -302,13 +308,13 @@ build_data(char *source, char *options, struct lustre_mount_data *lmd) if (rc) return rc; if (strlen(mds) > sizeof(lmd->lmd_mds) + 1) { - fprintf(stderr, "mount: mds name too long\n"); + fprintf(stderr, "%s: mds name too long\n", progname); return(-1); } strcpy(lmd->lmd_mds, mds); if (strlen(profile) > sizeof(lmd->lmd_profile) + 1) { - fprintf(stderr, "mount: profile name too long\n"); + fprintf(stderr, "%s: profile name too long\n", progname); return(-1); } strcpy(lmd->lmd_profile, profile); @@ -330,6 +336,9 @@ main(int argc, char * const argv[]) int rc; + progname = strrchr(argv[0], '/'); + progname = progname ? progname + 1 : argv[0]; + while ((opt = getopt(argc, argv, "vno:")) != EOF) { switch (opt) { case 'v': @@ -353,8 +362,10 @@ main(int argc, char * const argv[]) } if (argc < i) { - printf("Too few args!\n"); - printf("Usage: %s <source> <target> [-v] [-n] [-o ...]\n", argv[0]); + fprintf(stderr, + "%s: too few arguments\n" + "Usage: %s <source> <target> [-v] [-n] [-o ...]\n", + progname, progname); exit(1); } @@ -370,7 +381,7 @@ main(int argc, char * const argv[]) } if (debug) { - printf("mount: debug mode, not mounting\n"); + printf("%s: debug mode, not mounting\n", progname); exit(0); }