aboutsummaryrefslogtreecommitdiff
path: root/src/librc-daemon.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-10-04 19:49:12 +0000
committerRoy Marples <roy@marples.name>2007-10-04 19:49:12 +0000
commitefe6e76cc14fb92c2784ef29d40ef42860078d74 (patch)
treea223544c4cec92e65c3fb2c9e532136753a05449 /src/librc-daemon.c
parent7319c64cffca2c14ad1c7afe329d59389f60ff83 (diff)
rc_service_daemon_set now returns bool
Diffstat (limited to 'src/librc-daemon.c')
-rw-r--r--src/librc-daemon.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/librc-daemon.c b/src/librc-daemon.c
index e3da58d7..90d28c6f 100644
--- a/src/librc-daemon.c
+++ b/src/librc-daemon.c
@@ -283,13 +283,12 @@ static bool _match_daemon (const char *path, const char *file,
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,
bool started)
{
- char *svc = rc_xstrdup (service);
- char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
- (char *) NULL);
+ char *svc;
+ char *dirpath;
char **files = NULL;
char *file;
char *ffile = NULL;
@@ -299,10 +298,16 @@ void rc_service_daemon_set (const char *service, const char *exec,
char *mpidfile;
int nfiles = 0;
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);
- if (! exec && ! name && ! pidfile)
- return;
if (exec) {
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) {
snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1);
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);
- fclose (fp);
+ fclose (fp);
+ retval = true;
+ }
free (file);
}
- }
+ } else
+ retval = true;
free (mexec);
free (mname);
free (mpidfile);
free (dirpath);
+
+ return (retval);
}
librc_hidden_def(rc_service_daemon_set)