From mboxrd@z Thu Jan 1 00:00:00 1970 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ktky+w+4AHmIMeA19VhrqrAwRW1nqRe8zagoiTpSlxw=; b=LF42rDaAloI+T7h8EXbVhX4Kv2l9tfQcZXsqbV9TFGpYdKF4qCyy708i+RooeY6y3P NkRjvFTVuFi588FlwXHGT1sNEhCuNviUFUC+8tiYqF57k1/qVJjjjLAdSJsEvZCo2RMN tU2UubMbnU0KUDAkSSTkVvhn3rrTbWmw7tQbGCfY0mW9t4OBwFvs5IXpW3yjfOZ1mUBN R8h+eDue0ZnIg0GQ9kgOdW/axxKhG2fEFjAjUehnj6EOXDqaqn6XckrGrNIGKRwvhaUa jON85u+bRwUB+FXh9+X7Nut/eLveAcvL5WHq8L19bVgiUbhoXcpq5Tth8DHq+T2zYAGq Yzhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ktky+w+4AHmIMeA19VhrqrAwRW1nqRe8zagoiTpSlxw=; b=lKAkiJGGOI8uRTUulDbWFI7iUoNqUtLsafit6vKr3ichq5L2/dVTA9vbYGsj4cM1YK 6fNjdPHtEa5R2ikWNTm1JMn6IAWS/vFZBXAhmtGGr+Gz+LSeqeAMdrb1kEhrc4pExhBq wRF9uZ+7t/JfJP5jLdZER5WOoNrKNRhoSstfUZbp2eHfY9bBaNagsQMWnnjtDHdd2Kql AUNUbfk17xNeHo5zqhFCfGWf2BRBuSJzpyJez3JgkRQasr/WTuyQFWkUT1WQuFBRbuWK jmm94S6Km6osS1enyGDKrfhuLfRt25McRsbDoPVj0+q2f6EwmnlrWteH7LBc1vCtdFqd igtQ== X-Gm-Message-State: AODbwcDVHf0QVVkLPUAqRRFzlOUgXIr3XWi8l/Xmm0f4yzMPoj4q0kBF 2wjAPJm0d2dha3wi X-Received: by 10.98.196.201 with SMTP id h70mr12006592pfk.122.1495215595523; Fri, 19 May 2017 10:39:55 -0700 (PDT) Received: from xeon-e3 (76-14-207-240.or.wavecable.com. [76.14.207.240]) by smtp.gmail.com with ESMTPSA id j21sm15409710pfj.80.2017.05.19.10.39.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2017 10:39:55 -0700 (PDT) Date: Fri, 19 May 2017 10:39:48 -0700 From: Stephen Hemminger To: Anatoly Burakov Cc: dev@dpdk.org Message-ID: <20170519103948.4d829353@xeon-e3> In-Reply-To: <1495211986-15177-3-git-send-email-anatoly.burakov@intel.com> 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 Subject: Re: [dpdk-dev] [RFC 2/4] eal: enable experimental dlopen()-based secondary process support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 May 2017 17:39:57 -0000 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.