From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [RFC 2/4] eal: enable experimental dlopen()-based secondary process support Date: Fri, 19 May 2017 10:39:48 -0700 Message-ID: <20170519103948.4d829353@xeon-e3> References: <1495211986-15177-1-git-send-email-anatoly.burakov@intel.com> <1495211986-15177-3-git-send-email-anatoly.burakov@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org To: Anatoly Burakov Return-path: Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) by dpdk.org (Postfix) with ESMTP id 4238E107A for ; Fri, 19 May 2017 19:39:56 +0200 (CEST) Received: by mail-pf0-f173.google.com with SMTP id n23so42935626pfb.2 for ; Fri, 19 May 2017 10:39:56 -0700 (PDT) In-Reply-To: <1495211986-15177-3-git-send-email-anatoly.burakov@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 19 May 2017 17:39:44 +0100 Anatoly Burakov 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.