[dpdk-dev] [RFC 2/4] eal: enable experimental dlopen()-based secondary process support
Stephen Hemminger
stephen at networkplumber.org
Fri May 19 19:39:48 CEST 2017
On Fri, 19 May 2017 17:39:44 +0100
Anatoly Burakov <anatoly.burakov at intel.com> wrote:
> This new forked secondary dlopen()'s the original secondary process
> binary and runs main() again. In the meantime, the original secondary
> process waits until this new forked secondary dies, and exits.
You don't have to use a lock file. Just using a pipe for process
standard input and detecting close on process exit is often simpler.
> +static
> +const char *get_run_dir(void) {
> + const char *dir = "/var/run";
> + const char *home_dir = getenv("HOME");
> +
> + if (getuid() != 0 && home_dir != NULL)
> + dir = home_dir;
> + return dir;
> +}
> +
> +static
> +void get_rand_str(char *str, int sz) {
> + char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
> + for (int i = 0; i < sz - 1; i++) {
> + // this does not give us *true* randomness but it's good enough
> + int idx = rand() % sizeof(charset);
> + str[i] = charset[idx];
> + }
> + str[sz - 1] = '\0';
> +}
> +
> +/* we need to know its length */
> +static
> +int get_lock_file_path(char *str, int sz) {
> + char rand_str[16];
> +
> + get_rand_str(rand_str, 16);
> +
> + return snprintf(str, sz, LOCKFILE_PATH_FMT, get_run_dir(),
> + internal_config.hugefile_prefix, rand_str);
> +}
> +
Why reinvent all the stuff in mkstemp and friends?
Also don't use C++ style comments in DPDK code.
More information about the dev
mailing list