Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider improving thread-safe death tests such that they search the PATH when re-executing the test program #33

Open
GoogleCodeExporter opened this issue Jul 31, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

Thread-safe death tests currently don't search the PATH when re-executing
the test program.  This means the user cannot put a test binary that
contains thread-safe death tests in a directory in the PATH and invoke it
without a directory prefix.

This is rarely a problem in practice (hence the low priority), as:

- people rarely leave tests in PATH - that's arguably not a good idea.
- more people use the "fast" style death tests, which don't have this problem.

Just for future reference, Mike Burrows suggested the following
impelementation:

In the forked process, you may not call getenv() (which execvp does,
for example),
and you may not call malloc(), but you can do these things before forking.
Below is an untested example.


Mike


#include <unistd.h>

/* exec() the first file possible that is called name[] and is on the colon
  separated path path[], with the argument in argv[].
  The path is ignored if name[] contains a slash.
  Requires that buffer[] be a scratch area large enough for the longest
  pathname generated:  a conservative size for buffer[] is
       strlen (name) + strlen (path) + 2
  Does not return on success.

  Example:
       const char *path = getenv ("PATH");
       char *buffer;
       int pid;
       if (path == 0) {
               path = "/bin:/usr/bin";
       }
       buffer = malloc (strlen (path) + strlen (name) + 2);

       pid = fork ();
       if (pid == 0) {
               exec_first_on_path (name, path, buffer, argv);
               perror (name);
               _exit (2);
       }
       ...
 */
void exec_first_on_path (const char *name, const char *path, char
*buffer, char *argv[]) {
       if (strchr (name, '/') != 0) {
               path = "";
       }
       path--;                 /* pretend path has a leading colon
that's never touched */
       do {
               char *p;
               path++;         /* skip colon */
               for (p = buffer; *path != 0 && *path != ':'; *p++ = *path++) {
               }
               if (p != buffer) {
                       *p++ = '/';
               }
               strcpy (p, name);
               execv (buffer, argv);
       } while (*path == ':');
}



Original issue reported on code.google.com by [email protected] on 10 Sep 2008 at 6:24

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

We have checked our speed test to our Software Blog http://www.softidro.com and 
it seems to work great with that Code.

Original comment by [email protected] on 1 Jun 2015 at 12:41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant