Allow interpreted daemons to use s-s-d a little easier.
This commit is contained in:
@@ -97,9 +97,10 @@ typedef struct scheduleitem
|
|||||||
TAILQ_ENTRY(scheduleitem) entries;
|
TAILQ_ENTRY(scheduleitem) entries;
|
||||||
} SCHEDULEITEM;
|
} SCHEDULEITEM;
|
||||||
TAILQ_HEAD(, scheduleitem) schedule;
|
TAILQ_HEAD(, scheduleitem) schedule;
|
||||||
|
static char **nav = NULL;
|
||||||
|
|
||||||
extern const char *applet;
|
extern const char *applet;
|
||||||
static char *changeuser;
|
static char *changeuser = NULL;
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
@@ -118,8 +119,8 @@ static void free_schedulelist(void)
|
|||||||
|
|
||||||
static void cleanup(void)
|
static void cleanup(void)
|
||||||
{
|
{
|
||||||
if (changeuser)
|
free(changeuser);
|
||||||
free(changeuser);
|
free(nav);
|
||||||
|
|
||||||
free_schedulelist();
|
free_schedulelist();
|
||||||
}
|
}
|
||||||
@@ -753,6 +754,7 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
case_RC_COMMON_GETOPT
|
case_RC_COMMON_GETOPT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endpwent();
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
quiet = rc_yesno(getenv("EINFO_QUIET"));
|
quiet = rc_yesno(getenv("EINFO_QUIET"));
|
||||||
@@ -855,30 +857,31 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we don't have a pidfile or name, check it's not
|
/* If we don't have a pidfile we should check if it's interpreted
|
||||||
* interpreted, otherwise we should fail */
|
* or not. If it we, we need to pass the interpreter through
|
||||||
if (!pidfile && !name) {
|
* to our daemon calls to find it correctly. */
|
||||||
fp = fopen(tmp, "r");
|
if (!pidfile) {
|
||||||
|
fp = fopen(exec_file, "r");
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fgets(line, sizeof(line), fp);
|
fgets(line, sizeof(line), fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (line[0] == '#' && line[1] == '!') {
|
if (line[0] == '#' && line[1] == '!') {
|
||||||
len = strlen(line) - 1;
|
|
||||||
|
|
||||||
/* Remove the trailing newline */
|
/* Remove the trailing newline */
|
||||||
|
len = strlen(line) - 1;
|
||||||
if (line[len] == '\n')
|
if (line[len] == '\n')
|
||||||
line[len] = '\0';
|
line[len] = '\0';
|
||||||
|
strncpy(exec_file, line + 2, sizeof(exec_file));
|
||||||
eerror("%s: %s is a script",
|
opt = 0;
|
||||||
applet, exec);
|
for (nav = argv; *nav; nav++)
|
||||||
eerror("%s: and should be started, stopped"
|
opt++;
|
||||||
" or signalled with ", applet);
|
nav = xmalloc(sizeof(char *) * (opt + 3));
|
||||||
eerror("%s: --exec %s %s",
|
nav[0] = exec_file;
|
||||||
applet, line + 2, exec);
|
nav[1] = (char *)"--";
|
||||||
eerror("%s: or you should specify a pidfile"
|
for (i = 0; i < opt; i++)
|
||||||
" or process name", applet);
|
nav[i + 2] = argv[i];
|
||||||
exit(EXIT_FAILURE);
|
nav[i + 2] = '\0';
|
||||||
|
argv = nav;
|
||||||
|
exec = exec_file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user