+static int
+nfp_acquire_secondary_process_lock(struct nfp_pcie_user *desc)
+{
+ int rc;
+ struct flock lock;
+ const char *lockname = "/.lock_nfp_secondary";
+ char *home_path;
+ char *lockfile;
+
+ memset(&lock, 0, sizeof(lock));
+
+ /*
+ * Using user's home directory. Note this can be called in a DPDK app
+ * being executed as non-root. This is not the case for the previous
+ * function nfp_acquire_process_lock which is invoked only when UIO
+ * driver is used because that implies root user.
+ */
+ home_path = getenv("HOME");
+ lockfile = calloc(strlen(home_path) + strlen(lockname) + 1,
+ sizeof(char));
+
+ if (!lockfile)
+ return -ENOMEM;
+
+ strcat(lockfile, home_path);
+ strcat(lockfile, "/.lock_nfp_secondary");
+ desc->secondary_lock = open(lockfile, O_RDWR | O_CREAT | O_NONBLOCK,
+ 0666);
+ if (desc->secondary_lock < 0) {
+ RTE_LOG(ERR, PMD, "NFP lock for secondary process failed\n");
+ free(lockfile);
+ return desc->secondary_lock;
+ }
+
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ rc = fcntl(desc->secondary_lock, F_SETLK, &lock);
+ if (rc < 0) {
+ RTE_LOG(ERR, PMD, "NFP lock for secondary process failed\n");
+ close(desc->secondary_lock);
+ }
+
+ free(lockfile);
+ return rc;
+}
+