From: Petr Rockai Date: Tue, 9 Oct 2012 18:25:17 +0000 (+0200) Subject: lvmetad: Only create pidfile when running as a daemon (no -f). X-Git-Tag: v2_02_98~89 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=19971492632fb2273bb2a991858e5cd5b48e2c5d;p=lvm2.git lvmetad: Only create pidfile when running as a daemon (no -f). Additionally, -f now makes -s mandatory, so the foreground (debugging) lvmetad does not steal the system-wide socket accidentally. --- diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c index 4741649a2..ff861a206 100644 --- a/daemons/lvmetad/lvmetad-core.c +++ b/daemons/lvmetad/lvmetad-core.c @@ -1060,6 +1060,7 @@ int main(int argc, char *argv[]) daemon_state s = { .private = NULL }; lvmetad_state ls; int _restart = 0; + int _socket_override = 1; s.name = "lvmetad"; s.private = &ls; @@ -1067,8 +1068,10 @@ int main(int argc, char *argv[]) s.daemon_fini = fini; s.handler = handler; s.socket_path = getenv("LVM_LVMETAD_SOCKET"); - if (!s.socket_path) + if (!s.socket_path) { + _socket_override = 0; s.socket_path = DEFAULT_RUN_DIR "/lvmetad.socket"; + } s.pidfile = LVMETAD_PIDFILE; s.protocol = "lvmetad"; s.protocol_version = 1; @@ -1094,6 +1097,7 @@ int main(int argc, char *argv[]) break; case 's': // --socket s.socket_path = optarg; + _socket_override = 1; break; case 'V': printf("lvmetad version 0\n"); @@ -1101,6 +1105,13 @@ int main(int argc, char *argv[]) } } + if (s.foreground && !_socket_override) { + fprintf(stderr, "A socket path (-s) is required in foreground mode."); + exit(2); + } else { + s.pidfile = NULL; + } + daemon_start(s); return 0; }