diff options
author | Roy Marples <roy@marples.name> | 2007-09-29 16:42:08 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-09-29 16:42:08 +0000 |
commit | 837f43e163b31e40b3ea554d6d031f25789590ac (patch) | |
tree | 5d8d5378ad4ff5695fbca51347ae75e6bb3530ab /src/librc-daemon.c | |
parent | b153f67fe3e0df84a02bfc9cae6f2469ca793615 (diff) |
librc no longer uses libeinfo. deptree function names are now all under rc_deptree_
Diffstat (limited to 'src/librc-daemon.c')
-rw-r--r-- | src/librc-daemon.c | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/src/librc-daemon.c b/src/librc-daemon.c index 5b1e0239..d9b68b08 100644 --- a/src/librc-daemon.c +++ b/src/librc-daemon.c @@ -79,16 +79,16 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, DIR *procdir; struct dirent *entry; int npids = 0; - int foundany = false; pid_t p; pid_t *pids = NULL; + pid_t *tmp = NULL; char buffer[PATH_MAX]; struct stat sb; pid_t runscript_pid = 0; char *pp; if ((procdir = opendir ("/proc")) == NULL) - eerrorx ("opendir `/proc': %s", strerror (errno)); + return (NULL); /* We never match RC_RUNSCRIPT_PID if present so we avoid the below @@ -109,7 +109,6 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, while ((entry = readdir (procdir)) != NULL) { if (sscanf (entry->d_name, "%d", &p) != 1) continue; - foundany = true; if (runscript_pid != 0 && runscript_pid == p) continue; @@ -129,9 +128,14 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, if (exec && ! cmd && ! pid_is_exec (p, exec)) continue; - pids = realloc (pids, sizeof (pid_t) * (npids + 2)); - if (! pids) - eerrorx ("memory exhausted"); + tmp = realloc (pids, sizeof (pid_t) * (npids + 2)); + if (! tmp) { + free (pids); + closedir (procdir); + errno = ENOMEM; + return (NULL); + } + pids = tmp; pids[npids] = p; pids[npids + 1] = 0; @@ -139,9 +143,6 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, } closedir (procdir); - if (! foundany) - eerrorx ("nothing in /proc"); - return (pids); } librc_hidden_def(rc_find_pids) @@ -177,6 +178,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, int argc = 0; char **argv; pid_t *pids = NULL; + pid_t *tmp; int npids = 0; if ((kd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf)) == NULL) @@ -210,15 +212,20 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, continue; } - pids = realloc (pids, sizeof (pid_t) * (npids + 2)); - if (! pids) - eerrorx ("memory exhausted"); + tmp = realloc (pids, sizeof (pid_t) * (npids + 2)); + if (! tmp) { + free (pids); + kvm_close (kd); + errno = ENOMEM; + return (NULL); + } + pids = tmp; pids[npids] = p; pids[npids + 1] = 0; npids++; } - kvm_close(kd); + kvm_close (kd); return (pids); } @@ -238,13 +245,7 @@ static bool _match_daemon (const char *path, const char *file, int lc = 0; int m = 0; - if (! rc_exists (ffile)) { - free (ffile); - return (false); - } - if ((fp = fopen (ffile, "r")) == NULL) { - eerror ("fopen `%s': %s", ffile, strerror (errno)); free (ffile); return (false); } @@ -350,19 +351,14 @@ void rc_set_service_daemon (const char *service, const char *exec, char buffer[10]; FILE *fp; - if (! rc_is_dir (dirpath)) - if (mkdir (dirpath, 0755) != 0) - eerror ("mkdir `%s': %s", dirpath, strerror (errno)); - - snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1); - file = rc_strcatpaths (dirpath, buffer, (char *) NULL); - if ((fp = fopen (file, "w")) == NULL) - eerror ("fopen `%s': %s", file, strerror (errno)); - else { - fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile); + 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"))) + fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile); fclose (fp); + free (file); } - free (file); } free (mexec); @@ -458,10 +454,8 @@ bool rc_service_daemons_crashed (const char *service) path = rc_strcatpaths (dirpath, file, (char *) NULL); fp = fopen (path, "r"); free (path); - if (! fp) { - eerror ("fopen `%s': %s", file, strerror (errno)); - continue; - } + if (! fp) + break; while ((fgets (buffer, RC_LINEBUFFER, fp))) { int lb = strlen (buffer) - 1; @@ -499,13 +493,11 @@ bool rc_service_daemons_crashed (const char *service) } if ((fp = fopen (pidfile, "r")) == NULL) { - eerror ("fopen `%s': %s", pidfile, strerror (errno)); retval = true; break; } if (fscanf (fp, "%d", &pid) != 1) { - eerror ("no pid found in `%s'", pidfile); fclose (fp); retval = true; break; |