From: prajnoha@sourceware.org <prajnoha@sourceware.org>
To: lvm-devel@redhat.com
Subject: LVM2/daemons/dmeventd dmeventd.c
Date: 27 Feb 2012 11:13:52 -0000 [thread overview]
Message-ID: <20120227111352.28380.qmail@sourceware.org> (raw)
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: prajnoha at sourceware.org 2012-02-27 11:13:52
Modified files:
daemons/dmeventd: dmeventd.c
Log message:
Systemd is linux-specific - move the supporting code under the 'ifdef linux'.
Some 'defines' used in this specific code were already under an ifdef so this
patch just completes it.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/dmeventd.c.diff?cvsroot=lvm2&r1=1.89&r2=1.90
--- LVM2/daemons/dmeventd/dmeventd.c 2012/02/13 11:18:45 1.89
+++ LVM2/daemons/dmeventd/dmeventd.c 2012/02/27 11:13:51 1.90
@@ -1657,6 +1657,76 @@
return _set_oom_adj(OOM_ADJ_FILE, OOM_SCORE_ADJ_MIN);
}
+
+static int _handle_preloaded_fifo(int fd, const char *path)
+{
+ struct stat st_fd, st_path;
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) < 0)
+ return 0;
+
+ if (flags & FD_CLOEXEC)
+ return 0;
+
+ if (fstat(fd, &st_fd) < 0 || !S_ISFIFO(st_fd.st_mode))
+ return 0;
+
+ if (stat(path, &st_path) < 0 ||
+ st_path.st_dev != st_fd.st_dev ||
+ st_path.st_ino != st_fd.st_ino)
+ return 0;
+
+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
+ return 0;
+
+ return 1;
+}
+
+static int _systemd_handover(struct dm_event_fifos *fifos)
+{
+ const char *e;
+ char *p;
+ unsigned long env_pid, env_listen_fds;
+ int r = 0;
+
+ memset(fifos, 0, sizeof(*fifos));
+
+ /* LISTEN_PID must be equal to our PID! */
+ if (!(e = getenv(SD_LISTEN_PID_ENV_VAR_NAME)))
+ goto out;
+
+ errno = 0;
+ env_pid = strtoul(e, &p, 10);
+ if (errno || !p || *p || env_pid <= 0 ||
+ getpid() != (pid_t) env_pid)
+ goto out;
+
+ /* LISTEN_FDS must be 2 and the fds must be FIFOSs! */
+ if (!(e = getenv(SD_LISTEN_FDS_ENV_VAR_NAME)))
+ goto out;
+
+ errno = 0;
+ env_listen_fds = strtoul(e, &p, 10);
+ if (errno || !p || *p || env_listen_fds != 2)
+ goto out;
+
+ /* Check and handle the FIFOs passed in */
+ r = (_handle_preloaded_fifo(SD_FD_FIFO_SERVER, DM_EVENT_FIFO_SERVER) &&
+ _handle_preloaded_fifo(SD_FD_FIFO_CLIENT, DM_EVENT_FIFO_CLIENT));
+
+ if (r) {
+ fifos->server = SD_FD_FIFO_SERVER;
+ fifos->server_path = DM_EVENT_FIFO_SERVER;
+ fifos->client = SD_FD_FIFO_CLIENT;
+ fifos->client_path = DM_EVENT_FIFO_CLIENT;
+ }
+
+out:
+ unsetenv(SD_LISTEN_PID_ENV_VAR_NAME);
+ unsetenv(SD_LISTEN_FDS_ENV_VAR_NAME);
+ return r;
+}
#endif
static void remove_lockfile(void)
@@ -1723,10 +1793,12 @@
fd = rlim.rlim_cur;
for (--fd; fd >= 0; fd--) {
+#ifdef linux
/* Do not close fds preloaded by systemd! */
if (_systemd_activation &&
(fd == SD_FD_FIFO_SERVER || fd == SD_FD_FIFO_CLIENT))
continue;
+#endif
close(fd);
}
@@ -1804,76 +1876,6 @@
fini_fifos(&fifos);
}
-static int _handle_preloaded_fifo(int fd, const char *path)
-{
- struct stat st_fd, st_path;
- int flags;
-
- if ((flags = fcntl(fd, F_GETFD)) < 0)
- return 0;
-
- if (flags & FD_CLOEXEC)
- return 0;
-
- if (fstat(fd, &st_fd) < 0 || !S_ISFIFO(st_fd.st_mode))
- return 0;
-
- if (stat(path, &st_path) < 0 ||
- st_path.st_dev != st_fd.st_dev ||
- st_path.st_ino != st_fd.st_ino)
- return 0;
-
- if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
- return 0;
-
- return 1;
-}
-
-static int _systemd_handover(struct dm_event_fifos *fifos)
-{
- const char *e;
- char *p;
- unsigned long env_pid, env_listen_fds;
- int r = 0;
-
- memset(fifos, 0, sizeof(*fifos));
-
- /* LISTEN_PID must be equal to our PID! */
- if (!(e = getenv(SD_LISTEN_PID_ENV_VAR_NAME)))
- goto out;
-
- errno = 0;
- env_pid = strtoul(e, &p, 10);
- if (errno || !p || *p || env_pid <= 0 ||
- getpid() != (pid_t) env_pid)
- goto out;
-
- /* LISTEN_FDS must be 2 and the fds must be FIFOSs! */
- if (!(e = getenv(SD_LISTEN_FDS_ENV_VAR_NAME)))
- goto out;
-
- errno = 0;
- env_listen_fds = strtoul(e, &p, 10);
- if (errno || !p || *p || env_listen_fds != 2)
- goto out;
-
- /* Check and handle the FIFOs passed in */
- r = (_handle_preloaded_fifo(SD_FD_FIFO_SERVER, DM_EVENT_FIFO_SERVER) &&
- _handle_preloaded_fifo(SD_FD_FIFO_CLIENT, DM_EVENT_FIFO_CLIENT));
-
- if (r) {
- fifos->server = SD_FD_FIFO_SERVER;
- fifos->server_path = DM_EVENT_FIFO_SERVER;
- fifos->client = SD_FD_FIFO_CLIENT;
- fifos->client_path = DM_EVENT_FIFO_CLIENT;
- }
-
-out:
- unsetenv(SD_LISTEN_PID_ENV_VAR_NAME);
- unsetenv(SD_LISTEN_FDS_ENV_VAR_NAME);
- return r;
-}
-
static void usage(char *prog, FILE *file)
{
fprintf(file, "Usage:\n"
@@ -1928,7 +1930,9 @@
if (_restart)
restart();
+#ifdef linux
_systemd_activation = _systemd_handover(&fifos);
+#endif
if (!_foreground)
_daemonize();
next reply other threads:[~2012-02-27 11:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-27 11:13 prajnoha [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-03-02 23:01 LVM2/daemons/dmeventd dmeventd.c zkabelac
2012-03-01 22:54 zkabelac
2012-02-10 13:46 zkabelac
2011-09-14 9:53 zkabelac
2011-08-31 8:23 zkabelac
2011-03-02 14:20 mornfall
2011-01-17 23:14 mbroz
2010-11-29 12:15 zkabelac
2010-11-29 11:23 zkabelac
2010-10-26 8:54 zkabelac
2010-03-30 14:40 zkabelac
2010-03-30 14:37 zkabelac
2010-03-30 14:35 zkabelac
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120227111352.28380.qmail@sourceware.org \
--to=prajnoha@sourceware.org \
--cc=lvm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.