summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-02-24 23:09:15 +0000
committerRoy Marples <roy@marples.name>2008-02-24 23:09:15 +0000
commitd1f7f0a3044b87f9693d43ece70b88a7d2f0dffa (patch)
treedeb2369c8b8588c7d767637f0c7084e3a820b916 /src
parent8b4b958678c52893ab1901c15dec123c99d56927 (diff)
downloadopenrc-d1f7f0a3044b87f9693d43ece70b88a7d2f0dffa.tar.gz
openrc-d1f7f0a3044b87f9693d43ece70b88a7d2f0dffa.tar.bz2
openrc-d1f7f0a3044b87f9693d43ece70b88a7d2f0dffa.tar.xz
Force the specification of a pidfile or process name if daemon is a script. Alternatively, document the use of starting the script interpreter and passing the daemon as an option.
Diffstat (limited to 'src')
-rw-r--r--src/rc/start-stop-daemon.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 01cc14f..29525c9 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -758,18 +758,51 @@ int start_stop_daemon (int argc, char **argv)
argv += optind;
/* Validate that the binary exists if we are starting */
- if (exec && start) {
+ if (exec) {
char *tmp;
if (ch_root)
tmp = rc_strcatpaths (ch_root, exec, (char *) NULL);
else
tmp = exec;
- if (! exists (tmp)) {
+ if (start && ! exists (tmp)) {
eerror ("%s: %s does not exist", applet, tmp);
if (ch_root)
free (tmp);
exit (EXIT_FAILURE);
}
+
+ /* If we don't have a pidfile or name, check it's not
+ * interpreted, otherwise we should fail */
+ if (! pidfile && ! cmd) {
+ char line[130];
+ FILE *fp = fopen (tmp, "r");
+
+ if (fp) {
+ fgets (line, sizeof (line), fp);
+ fclose (fp);
+
+ if (line[0] == '#' && line[1] == '!') {
+ size_t len = strlen (line) - 1;
+
+ /* Remove the trailing newline */
+ if (line[len] == '\n')
+ line[len] = '\0';
+
+ eerror ("%s: %s is a script",
+ applet, exec);
+ eerror ("%s: and should be started, stopped or signalled with ",
+ applet);
+ eerror ("%s: --exec %s %s",
+ applet, line + 2, exec);
+ eerror ("%s: or you should specify a pidfile or process name",
+ applet);
+ if (ch_root)
+ free (tmp);
+ exit (EXIT_FAILURE);
+ }
+ }
+ }
+
if (ch_root)
free (tmp);
}