rc_service_daemon_set now returns bool

This commit is contained in:
Roy Marples 2007-10-04 19:49:12 +00:00
parent 7319c64cff
commit efe6e76cc1
2 changed files with 20 additions and 10 deletions

View File

@ -283,13 +283,12 @@ static bool _match_daemon (const char *path, const char *file,
return (m == 111 ? true : false); return (m == 111 ? true : false);
} }
void rc_service_daemon_set (const char *service, const char *exec, bool rc_service_daemon_set (const char *service, const char *exec,
const char *name, const char *pidfile, const char *name, const char *pidfile,
bool started) bool started)
{ {
char *svc = rc_xstrdup (service); char *svc;
char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), char *dirpath;
(char *) NULL);
char **files = NULL; char **files = NULL;
char *file; char *file;
char *ffile = NULL; char *ffile = NULL;
@ -299,10 +298,16 @@ void rc_service_daemon_set (const char *service, const char *exec,
char *mpidfile; char *mpidfile;
int nfiles = 0; int nfiles = 0;
char *oldfile = NULL; char *oldfile = NULL;
bool retval = false;
if (! exec && ! name && ! pidfile) {
errno = EINVAL;
return (false);
}
svc = rc_xstrdup (service);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons",
basename (svc), (char *) NULL);
free (svc); free (svc);
if (! exec && ! name && ! pidfile)
return;
if (exec) { if (exec) {
i = strlen (exec) + 6; i = strlen (exec) + 6;
@ -354,17 +359,22 @@ void rc_service_daemon_set (const char *service, const char *exec,
if (mkdir (dirpath, 0755) == 0 || errno == EEXIST) { if (mkdir (dirpath, 0755) == 0 || errno == EEXIST) {
snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1); snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1);
file = rc_strcatpaths (dirpath, buffer, (char *) NULL); file = rc_strcatpaths (dirpath, buffer, (char *) NULL);
if ((fp = fopen (file, "w"))) if ((fp = fopen (file, "w"))) {
fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile); fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
fclose (fp); fclose (fp);
retval = true;
}
free (file); free (file);
} }
} } else
retval = true;
free (mexec); free (mexec);
free (mname); free (mname);
free (mpidfile); free (mpidfile);
free (dirpath); free (dirpath);
return (retval);
} }
librc_hidden_def(rc_service_daemon_set) librc_hidden_def(rc_service_daemon_set)

View File

@ -99,7 +99,7 @@ bool rc_service_delete (const char *runlevel, const char *service);
* @param name of the process (optional) * @param name of the process (optional)
* @param pidfile of the process (optional) * @param pidfile of the process (optional)
* @param started if true, add the arguments otherwise remove existing matching arguments */ * @param started if true, add the arguments otherwise remove existing matching arguments */
void rc_service_daemon_set (const char *service, const char *exec, bool rc_service_daemon_set (const char *service, const char *exec,
const char *name, const char *pidfile, const char *name, const char *pidfile,
bool started); bool started);