All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] [meta-ivi] portmap: Write portmap.pid file at startup
@ 2013-06-11 15:31 Shakeel, Muhammad
  0 siblings, 0 replies; only message in thread
From: Shakeel, Muhammad @ 2013-06-11 15:31 UTC (permalink / raw)
  To: holger.behrens, florin.sarbu; +Cc: yocto

From: Muhammad Shakeel <muhammad_shakeel@mentor.com>

Portmap systemd service is expecting this file to be present and
without this patch portmap service will fail, with timeout status.

Signed-off-by: Muhammad Shakeel <muhammad_shakeel@mentor.com>
---
 .../portmap/portmap/pid_file_creation.patch        |  162 ++++++++++++++++++++
 recipes-connectivity/portmap/portmap_6.0.bbappend  |    3 +-
 2 files changed, 164 insertions(+), 1 deletion(-)

diff --git a/recipes-connectivity/portmap/portmap/pid_file_creation.patch b/recipes-connectivity/portmap/portmap/pid_file_creation.patch
new file mode 100644
index 0000000..ec99968
--- /dev/null
+++ b/recipes-connectivity/portmap/portmap/pid_file_creation.patch
@@ -0,0 +1,162 @@
+Create portmap.pid file at startup
+
+This patch has been taken from:
+http://debian.2.n7.nabble.com/Bug-448470-Portmap-does-not-start-if-a-random-user-has-a-process-named-portmap-td440179.html
+Witout this patch systemd service was failing to start because no pidfile
+was getting generated by portmap. This problem is solved by getting
+portmap to write a pidfile, making sure the correct process is checked by
+the start script instead of a random one with the portmap name.
+
+Upstream-Status: Pending
+
+Signed-off-by: Muhammad Shakeel <muhammad_shakeel@mentor.com>
+===================================================================
+--- portmap-6.0.orig/portmap.c
++++ portmap-6.0/portmap.c
+@@ -98,6 +98,8 @@
+
+ #include <stdlib.h>
+ #include <pwd.h>
++#include <stdarg.h>
++#include <sys/stat.h>
+
+ #ifndef LOG_PERROR
+ #define LOG_PERROR 0
+@@ -169,6 +171,126 @@
+        int priv;
+ };
+
++#ifndef PIDFILE
++#  define PIDFILE "/var/run/portmap.pid"
++#endif
++
++/*
++ * Copied from the atd source
++ */
++static int
++lock_fd(int fd)
++{
++    struct flock lock;
++
++    lock.l_type = F_WRLCK;
++    lock.l_whence = SEEK_SET;
++    lock.l_start = 0;
++    lock.l_len = 0;
++
++    return fcntl(fd, F_SETLK, &lock);
++}
++
++void
++perr(const char *fmt,...)
++{
++    char buf[1024];
++    va_list args;
++
++    va_start(args, fmt);
++    vsnprintf(buf, sizeof(buf), fmt, args);
++    va_end(args);
++
++    if (debugging) {
++       perror(buf);
++    } else
++       syslog(LOG_ERR, "%s: %m", buf);
++
++    exit(EXIT_FAILURE);
++}
++
++void
++pabort(const char *fmt,...)
++{
++    char buf[1024];
++    va_list args;
++
++    va_start(args, fmt);
++    vsnprintf(buf, sizeof(buf), fmt, args);
++    va_end(args);
++
++    if (debugging) {
++       fprintf(stderr, "%s\n", buf);
++    } else
++       syslog(LOG_ERR, "%s", buf);
++
++    exit(EXIT_FAILURE);
++}
++
++FILE *
++save_pidfile(void) {
++    pid_t pid;
++    int fd;
++    FILE *fp;
++    fd = open(PIDFILE, O_RDWR | O_CREAT | O_EXCL,
++             S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
++
++    if (fd == -1) {
++
++       if (errno != EEXIST)
++           perr("Cannot open " PIDFILE);
++
++       if ((fd = open(PIDFILE, O_RDWR)) < 0)
++           perr("Cannot open " PIDFILE);
++
++       fp = fdopen(fd, "rw");
++       if (fp == NULL) {
++           perr("Cannot open " PIDFILE " for reading");
++       }
++       pid = -1;
++       if ((fscanf(fp, "%d", &pid) != 1) || (pid == getpid())
++           || (lock_fd(fileno(fp)) == 0)) {
++           int rc;
++
++           syslog(LOG_NOTICE, "Removing stale lockfile for pid %d", pid);
++
++           rc = unlink(PIDFILE);
++
++           if (rc == -1) {
++               perr("Cannot unlink " PIDFILE);
++           }
++       } else {
++           pabort("Another atd already running with pid %d", pid);
++       }
++       fclose(fp);
++
++       unlink(PIDFILE);
++       fd = open(PIDFILE, O_RDWR | O_CREAT | O_EXCL,
++                 S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
++
++
++       if (fd == -1)
++           perr("Cannot open " PIDFILE " the second time round");
++
++    }
++
++    if (lock_fd(fd) == -1)
++       perr("Cannot lock " PIDFILE);
++
++    fp = fdopen(fd, "w");
++    if (fp == NULL)
++       perr("Special weirdness: fdopen failed");
++
++    fprintf(fp, "%d\n", getpid());
++
++    /* We do NOT close fd, since we want to keep the lock. However, we don't
++     * want to keep the file descriptor in case of an exec().
++     */
++    fflush(fp);
++    fcntl(fd, F_SETFD, (long) 1);
++    return fp;
++}
++
+ int
+ main(int argc, char **argv)
+ {
+@@ -252,6 +374,8 @@
+                exit(1);
+        }
+
++       save_pidfile();
++
+ #ifdef LOG_DAEMON
+        openlog("portmap", LOG_PID|LOG_NDELAY | ( foreground ? LOG_PERROR : 0),
+            FACILITY);
+
+
diff --git a/recipes-connectivity/portmap/portmap_6.0.bbappend b/recipes-connectivity/portmap/portmap_6.0.bbappend
index 0432982..512b826 100644
--- a/recipes-connectivity/portmap/portmap_6.0.bbappend
+++ b/recipes-connectivity/portmap/portmap_6.0.bbappend
@@ -1,4 +1,4 @@
-PRINC := "${@int(PRINC) + 5}"
+PRINC := "${@int(PRINC) + 6}"
 
 # Find local ${PN} directory
 FILESEXTRAPATHS := "${THISDIR}/${PN}"
@@ -12,6 +12,7 @@ FILES_${PN} =+ "${systemd_unitdir}/system/portmap.service"
 
 SRC_URI_append = " \
     file://portmap.service \
+    file://pid_file_creation.patch\
     "
 
 do_install_append() {
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-06-11 15:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-11 15:31 [PATCH 2/3] [meta-ivi] portmap: Write portmap.pid file at startup Shakeel, Muhammad

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.