From d1f7f0a3044b87f9693d43ece70b88a7d2f0dffa Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sun, 24 Feb 2008 23:09:15 +0000 Subject: 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. --- src/rc/start-stop-daemon.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/rc') diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index 01cc14f2..29525c96 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); } -- cgit v1.2.3