bozo: allow start of fs and dafs bnodes with options 34/11934/11
authorMark Vitale <mvitale@sinenomine.net>
Sat, 18 Jul 2015 05:12:51 +0000 (01:12 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Tue, 23 Feb 2016 04:23:38 +0000 (23:23 -0500)
fs_create() and dafs_create() issue stat() to verify
the existence of each executable specified in the bnode.
However, commit fda2bc874751ca479365dc6389c0eebb41a0bda1
inadvertently removed the code that stripped any command
arguments before the stat().  Therefore, any bnode that
specifies arguments (e.g. /usr/afs/bin/dafileserver -d 5),
causes the stat() to fail and the bnode will not start.

Rename function AppendExecutableExtension() to a less
"window-ish" name: PathToExecutable().

Modify the Windows version of PathToExecutable()
to properly strip arguments.

Reimplement the Unix macro as function PathToExecutable()
that properly strips arguments.

Change-Id: I04f7ce2afb8211bd12b9063db1335738bff1cc1e
Reviewed-on: http://gerrit.openafs.org/11934
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/bozo/fsbnodeops.c

index 7893599..0aa55ab 100644 (file)
@@ -111,11 +111,7 @@ static int RestoreSalFlag(struct fsbnode *abnode);
 static void SetNeedsClock(struct fsbnode *);
 static int NudgeProcs(struct fsbnode *);
 
-#ifdef AFS_NT40_ENV
-static char *AppendExecutableExtension(char *cmd);
-#else
-#define AppendExecutableExtension(x) strdup(x)
-#endif
+static char *PathToExecutable(char *cmd);
 
 struct bnode_ops fsbnode_ops = {
     fs_create,
@@ -346,21 +342,67 @@ fs_delete(struct bnode *bn)
     return 0;
 }
 
-
+/*! PathToExecutable() - for both Unix and Windows, accept a full bnode
+ * command, including any arguments, and return only the path to the
+ * binary executable, with arguments stripped.
+ *
+ * \notes The caller will stat() the returned path.
+ *
+ * \param cmd - full bnode command string with arguments
+ *
+ * \return - string path to the binary executable, to be freed by the caller
+ */
 #ifdef AFS_NT40_ENV
+/* The Windows implementation must also ensure that an extension is
+ * specified in the path.
+ */
+
 static char *
-AppendExecutableExtension(char *cmd)
+PathToExecutable(char *cmd)
 {
     char cmdext[_MAX_EXT];
-    char *cmdexe;
+    char *cmdexe, *cmdcopy, *cmdname;
+    size_t cmdend;
 
-    _splitpath(cmd, NULL, NULL, NULL, cmdext);
+    cmdcopy = strdup(cmd);
+    if (cmdcopy == NULL) {
+       return NULL;
+    }
+    /* strip off any arguments */
+    cmdname = strsep(&cmdcopy, " \t");    /* roken, I'm hopin' */
+    if (*cmdname == '\0') {
+       free(cmdname);
+       return NULL;
+    }
+    /* Is there an extension specified? */
+    _splitpath(cmdname, NULL, NULL, NULL, cmdext);
     if (*cmdext == '\0') {
-       if (asprintf(&cmdexe, "%s.exe", cmd) < 0)
+       /* No, supply one. */
+       if (asprintf(&cmdexe, "%s.exe", cmdname) < 0) {
+           free(cmdname);
            return NULL;
+       }
+       free(cmdname);
        return cmdexe;
     }
-    return strdup(cmd);
+    return cmdname;
+}
+#else /* AFS_NT40_ENV */
+/* Unix implementation is extension-agnostic. */
+static char *
+PathToExecutable(char *cmd)
+{
+    char *cmdcopy, *cmdname;
+    cmdcopy = strdup(cmd);
+    if (cmdcopy == NULL) {
+       return NULL;
+    }
+    cmdname = strsep(&cmdcopy, " ");
+    if (*cmdname == '\0') {
+       free(cmdname);
+       return NULL;
+    }
+    return cmdname;
 }
 #endif /* AFS_NT40_ENV */
 
@@ -404,7 +446,7 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd,
     }
 
     if (!bailout) {
-       cmdname = AppendExecutableExtension(fileCmdpath);
+       cmdname = PathToExecutable(fileCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -417,7 +459,7 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd,
        }
        free(cmdname);
 
-       cmdname = AppendExecutableExtension(volCmdpath);
+       cmdname = PathToExecutable(volCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -430,7 +472,7 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd,
        }
        free(cmdname);
 
-       cmdname = AppendExecutableExtension(salCmdpath);
+       cmdname = PathToExecutable(salCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -444,7 +486,7 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd,
 
        if (ascancmd && strlen(ascancmd)) {
            free(cmdname);
-           cmdname = AppendExecutableExtension(scanCmdpath);
+           cmdname = PathToExecutable(scanCmdpath);
            if (cmdname == NULL) {
                bozo_Log("Out of memory constructing binary filename\n");
                bailout = 1;
@@ -544,7 +586,7 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd,
     }
 
     if (!bailout) {
-       cmdname = AppendExecutableExtension(fileCmdpath);
+       cmdname = PathToExecutable(fileCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -557,7 +599,7 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd,
        }
        free(cmdname);
 
-       cmdname = AppendExecutableExtension(volCmdpath);
+       cmdname = PathToExecutable(volCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -570,7 +612,7 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd,
        }
        free(cmdname);
 
-       cmdname = AppendExecutableExtension(salsrvCmdpath);
+       cmdname = PathToExecutable(salsrvCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -583,7 +625,7 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd,
        }
        free(cmdname);
 
-       cmdname = AppendExecutableExtension(salCmdpath);
+       cmdname = PathToExecutable(salCmdpath);
        if (cmdname == NULL) {
            bozo_Log("Out of memory constructing binary filename\n");
            bailout = 1;
@@ -597,7 +639,7 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd,
 
        if (ascancmd && strlen(ascancmd)) {
            free(cmdname);
-           cmdname = AppendExecutableExtension(scanCmdpath);
+           cmdname = PathToExecutable(scanCmdpath);
            if (cmdname == NULL) {
                bozo_Log("Out of memory constructing binary filename\n");
                bailout = 1;