From a89ceb7e2c994e2a3907d9c906d99021a6e15788 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 8 Oct 2007 11:11:21 +0000 Subject: Punt rc_ from xstrdup, xalloc, xrealloc and exists as they're not in librc anymore --- src/env-update.c | 16 ++++++------- src/librc-daemon.c | 30 +++++++++++------------ src/librc-depend.c | 34 +++++++++++++------------- src/librc-misc.c | 8 +++---- src/librc-strlist.c | 10 ++++---- src/librc.c | 64 ++++++++++++++++++++++++------------------------- src/mountinfo.c | 4 ++-- src/rc-misc.c | 32 ++++++++++++------------- src/rc-misc.h | 8 +++---- src/rc-plugin.c | 6 ++--- src/rc.c | 46 +++++++++++++++++------------------ src/runscript.c | 34 +++++++++++++------------- src/start-stop-daemon.c | 16 ++++++------- 13 files changed, 154 insertions(+), 154 deletions(-) (limited to 'src') diff --git a/src/env-update.c b/src/env-update.c index 1ee13eff..e1367c2d 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -152,7 +152,7 @@ int env_update (int argc, char **argv) entries = rc_config_load (path); STRLIST_FOREACH (entries, entry, j) { - char *tmpent = rc_xstrdup (entry); + char *tmpent = strdup (entry); char *value = tmpent; char *var = strsep (&value, "="); @@ -176,7 +176,7 @@ int env_update (int argc, char **argv) eerrorx ("%s: nothing to process", applet); STRLIST_FOREACH (config, entry, i) { - char *tmpent = rc_xstrdup (entry); + char *tmpent = strdup (entry); char *value = tmpent; char *var = strsep (&value, "="); char *match; @@ -220,19 +220,19 @@ int env_update (int argc, char **argv) } STRLIST_FOREACH (envs, env, j) { - char *tmpenv = rc_xstrdup (env); + char *tmpenv = strdup (env); char *tmpvalue = tmpenv; char *tmpentry = strsep (&tmpvalue, "="); if (strcmp (tmpentry, var) == 0) { if (colon || space) { int len = strlen (envs[j - 1]) + strlen (entry) + 1; - envs[j - 1] = rc_xrealloc (envs[j - 1], len); + envs[j - 1] = xrealloc (envs[j - 1], len); snprintf (envs[j - 1] + strlen (envs[j - 1]), len, "%s%s", colon ? ":" : " ", value); } else { free (envs[j - 1]); - envs[j - 1] = rc_xstrdup (entry); + envs[j - 1] = strdup (entry); } replaced = true; } @@ -256,7 +256,7 @@ int env_update (int argc, char **argv) fprintf (fp, NOTICE, "/etc/profile", PROFILE_ENV); STRLIST_FOREACH (envs, env, i) { - char *tmpent = rc_xstrdup (env); + char *tmpent = strdup (env); char *value = tmpent; char *var = strsep (&value, "="); if (strcmp (var, "LDPATH") != 0) { @@ -274,7 +274,7 @@ int env_update (int argc, char **argv) fprintf (fp, NOTICE, "/etc/csh.cshrc", PROFILE_ENV); STRLIST_FOREACH (envs, env, i) { - char *tmpent = rc_xstrdup (env); + char *tmpent = strdup (env); char *value = tmpent; char *var = strsep (&value, "="); if (strcmp (var, "LDPATH") != 0) { @@ -303,7 +303,7 @@ int env_update (int argc, char **argv) if (ldconfig) { /* Update ld.so.conf only if different */ - if (rc_exists (LDSOCONF)) { + if (exists (LDSOCONF)) { char **lines = rc_config_list (LDSOCONF); char *line; ld = false; diff --git a/src/librc-daemon.c b/src/librc-daemon.c index ebad6a54..ca1a39ef 100644 --- a/src/librc-daemon.c +++ b/src/librc-daemon.c @@ -304,31 +304,31 @@ bool rc_service_daemon_set (const char *service, const char *exec, errno = EINVAL; return (false); } - svc = rc_xstrdup (service); + svc = strdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); if (exec) { i = strlen (exec) + 6; - mexec = rc_xmalloc (sizeof (char *) * i); + mexec = xmalloc (sizeof (char *) * i); snprintf (mexec, i, "exec=%s", exec); } else - mexec = rc_xstrdup ("exec="); + mexec = strdup ("exec="); if (name) { i = strlen (name) + 6; - mname = rc_xmalloc (sizeof (char *) * i); + mname = xmalloc (sizeof (char *) * i); snprintf (mname, i, "name=%s", name); } else - mname = rc_xstrdup ("name="); + mname = strdup ("name="); if (pidfile) { i = strlen (pidfile) + 9; - mpidfile = rc_xmalloc (sizeof (char *) * i); + mpidfile = xmalloc (sizeof (char *) * i); snprintf (mpidfile, i, "pidfile=%s", pidfile); } else - mpidfile = rc_xstrdup ("pidfile="); + mpidfile = strdup ("pidfile="); /* Regardless, erase any existing daemon info */ if ((dp = opendir (dirpath))) { @@ -398,18 +398,18 @@ bool rc_service_started_daemon (const char *service, const char *exec, if (! service || ! exec) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); i = strlen (exec) + 6; - mexec = rc_xmalloc (sizeof (char *) * i); + mexec = xmalloc (sizeof (char *) * i); snprintf (mexec, i, "exec=%s", exec); if (indx > 0) { int len = sizeof (char *) * 10; - file = rc_xmalloc (len); + file = xmalloc (len); snprintf (file, len, "%03d", indx); retval = _match_daemon (dirpath, file, mexec, NULL, NULL); free (file); @@ -453,7 +453,7 @@ bool rc_service_daemons_crashed (const char *service) if (! service) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); @@ -488,22 +488,22 @@ bool rc_service_daemons_crashed (const char *service) if (strcmp (token, "exec") == 0) { if (exec) free (exec); - exec = rc_xstrdup (p); + exec = strdup (p); } else if (strcmp (token, "name") == 0) { if (name) free (name); - name = rc_xstrdup (p); + name = strdup (p); } else if (strcmp (token, "pidfile") == 0) { if (pidfile) free (pidfile); - pidfile = rc_xstrdup (p); + pidfile = strdup (p); } } fclose (fp); pid = 0; if (pidfile) { - if (! rc_exists (pidfile)) { + if (! exists (pidfile)) { retval = true; break; } diff --git a/src/librc-depend.c b/src/librc-depend.c index 4794c856..1591eba3 100644 --- a/src/librc-depend.c +++ b/src/librc-depend.c @@ -101,16 +101,16 @@ rc_depinfo_t *rc_deptree_load (void) if (! deptree) { - deptree = rc_xmalloc (sizeof (rc_depinfo_t)); + deptree = xmalloc (sizeof (rc_depinfo_t)); depinfo = deptree; } else { - depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); + depinfo->next = xmalloc (sizeof (rc_depinfo_t)); depinfo = depinfo->next; } memset (depinfo, 0, sizeof (rc_depinfo_t)); - depinfo->service = rc_xstrdup (e); + depinfo->service = strdup (e); deptype = NULL; continue; } @@ -126,20 +126,20 @@ rc_depinfo_t *rc_deptree_load (void) if (! deptype) { - depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t)); + depinfo->depends = xmalloc (sizeof (rc_deptype_t)); deptype = depinfo->depends; memset (deptype, 0, sizeof (rc_deptype_t)); } else if (strcmp (deptype->type, type) != 0) { - deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); + deptype->next = xmalloc (sizeof (rc_deptype_t)); deptype = deptype->next; memset (deptype, 0, sizeof (rc_deptype_t)); } if (! deptype->type) - deptype->type = rc_xstrdup (type); + deptype->type = strdup (type); rc_strlist_addsort (&deptype->services, e); } @@ -683,7 +683,7 @@ bool rc_deptree_update (void) if (! (fp = popen (GENDEP, "r"))) return (false); - deptree = rc_xmalloc (sizeof (rc_depinfo_t)); + deptree = xmalloc (sizeof (rc_depinfo_t)); memset (deptree, 0, sizeof (rc_depinfo_t)); memset (buffer, 0, RC_LINEBUFFER); @@ -713,11 +713,11 @@ bool rc_deptree_update (void) depinfo = last_depinfo; else { - last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); + last_depinfo->next = xmalloc (sizeof (rc_depinfo_t)); depinfo = last_depinfo->next; } memset (depinfo, 0, sizeof (rc_depinfo_t)); - depinfo->service = rc_xstrdup (service); + depinfo->service = strdup (service); } /* We may not have any depends */ @@ -738,16 +738,16 @@ bool rc_deptree_update (void) { if (! last_deptype) { - depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t)); + depinfo->depends = xmalloc (sizeof (rc_deptype_t)); deptype = depinfo->depends; } else { - last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); + last_deptype->next = xmalloc (sizeof (rc_deptype_t)); deptype = last_deptype->next; } memset (deptype, 0, sizeof (rc_deptype_t)); - deptype->type = rc_xstrdup (type); + deptype->type = strdup (type); } } @@ -791,10 +791,10 @@ bool rc_deptree_update (void) } if (! di) { - last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); + last_depinfo->next = xmalloc (sizeof (rc_depinfo_t)); di = last_depinfo->next; memset (di, 0, sizeof (rc_depinfo_t)); - di->service = rc_xstrdup (service); + di->service = strdup (service); } } } @@ -835,16 +835,16 @@ bool rc_deptree_update (void) { if (! last_deptype) { - di->depends = rc_xmalloc (sizeof (rc_deptype_t)); + di->depends = xmalloc (sizeof (rc_deptype_t)); dt = di->depends; } else { - last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); + last_deptype->next = xmalloc (sizeof (rc_deptype_t)); dt = last_deptype->next; } memset (dt, 0, sizeof (rc_deptype_t)); - dt->type = rc_xstrdup (deppairs[i].addto); + dt->type = strdup (deppairs[i].addto); } already_added = false; diff --git a/src/librc-misc.c b/src/librc-misc.c index 01baf4a5..ba0122da 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -58,7 +58,7 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...) } va_end (ap); - pathp = path = rc_xmalloc (length * sizeof (char *)); + pathp = path = xmalloc (length * sizeof (char *)); memset (path, 0, length); i = strlen (path1); memcpy (path, path1, i); @@ -120,7 +120,7 @@ char **rc_config_load (const char *file) if (! token) continue; - entry = rc_xstrdup (token); + entry = strdup (token); /* Preserve shell coloring */ if (*p == '$') @@ -137,14 +137,14 @@ char **rc_config_load (const char *file) token[i] = 0; i = strlen (entry) + strlen (token) + 2; - newline = rc_xmalloc (i); + newline = xmalloc (i); snprintf (newline, i, "%s=%s", entry, token); replaced = false; /* In shells the last item takes precedence, so we need to remove any prior values we may already have */ STRLIST_FOREACH (list, line, i) { - char *tmp = rc_xstrdup (line); + char *tmp = strdup (line); linep = tmp; linetok = strsep (&linep, "="); if (strcmp (linetok, entry) == 0) { diff --git a/src/librc-strlist.c b/src/librc-strlist.c index 34f454dd..a9222c68 100644 --- a/src/librc-strlist.c +++ b/src/librc-strlist.c @@ -26,8 +26,8 @@ static char *_rc_strlist_add (char ***list, const char *item, bool uniq) i++; } - newlist = rc_xrealloc (lst, sizeof (char *) * (i + 2)); - newlist[i] = rc_xstrdup (item); + newlist = xrealloc (lst, sizeof (char *) * (i + 2)); + newlist[i] = strdup (item); newlist[i + 1] = NULL; *list = newlist; @@ -69,7 +69,7 @@ static char *_rc_strlist_addsort (char ***list, const char *item, i++; } - newlist = rc_xrealloc (lst, sizeof (char *) * (i + 2)); + newlist = xrealloc (lst, sizeof (char *) * (i + 2)); if (! i) newlist[i] = NULL; @@ -80,7 +80,7 @@ static char *_rc_strlist_addsort (char ***list, const char *item, i++; tmp1 = newlist[i]; - retval = newlist[i] = rc_xstrdup (item); + retval = newlist[i] = strdup (item); do { i++; tmp2 = newlist[i]; @@ -151,7 +151,7 @@ char *rc_strlist_join (char ***list1, char **list2) while (list2[j]) j++; - newlist = rc_xrealloc (lst1, sizeof (char *) * (i + j + 1)); + newlist = xrealloc (lst1, sizeof (char *) * (i + j + 1)); j = 0; while (list2[j]) { diff --git a/src/librc.c b/src/librc.c index b52329fc..12b3ffa2 100644 --- a/src/librc.c +++ b/src/librc.c @@ -61,7 +61,7 @@ static char **ls_dir (const char *dir, int options) int l = strlen (d->d_name); char *init = rc_strcatpaths (RC_INITDIR, d->d_name, (char *) NULL); - bool ok = rc_exists (init); + bool ok = exists (init); free (init); if (! ok) continue; @@ -137,13 +137,13 @@ static const char *rc_parse_service_state (rc_service_state_t state) bool rc_runlevel_starting (void) { - return (rc_exists (RC_STARTING)); + return (exists (RC_STARTING)); } librc_hidden_def(rc_runlevel_starting) bool rc_runlevel_stopping (void) { - return (rc_exists (RC_STOPPING)); + return (exists (RC_STOPPING)); } librc_hidden_def(rc_runlevel_stopping) @@ -164,13 +164,13 @@ char *rc_runlevel_get (void) int i = strlen (buffer) - 1; if (buffer[i] == '\n') buffer[i] = 0; - runlevel = rc_xstrdup (buffer); + runlevel = strdup (buffer); } fclose (fp); } if (! runlevel) - runlevel = rc_xstrdup (RC_LEVEL_SYSINIT); + runlevel = strdup (RC_LEVEL_SYSINIT); return (runlevel); } @@ -217,7 +217,7 @@ char *rc_service_resolve (const char *service) return (NULL); if (service[0] == '/') - return (rc_xstrdup (service)); + return (strdup (service)); file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL); if (lstat (file, &buf) || ! S_ISLNK (buf.st_mode)) { @@ -234,11 +234,11 @@ char *rc_service_resolve (const char *service) r = readlink (file, buffer, sizeof (buffer)); free (file); if (r > 0) - return (rc_xstrdup (buffer)); + return (strdup (buffer)); } snprintf (buffer, sizeof (buffer), RC_INITDIR "/%s", service); - return (rc_xstrdup (buffer)); + return (strdup (buffer)); } librc_hidden_def(rc_service_resolve) @@ -320,10 +320,10 @@ char *rc_service_description (const char *service, const char *option) while (fgets (buffer, RC_LINEBUFFER, fp)) { if (! desc) { - desc = rc_xmalloc (strlen (buffer) + 1); + desc = xmalloc (strlen (buffer) + 1); *desc = '\0'; } else { - desc = rc_xrealloc (desc, strlen (desc) + strlen (buffer) + 1); + desc = xrealloc (desc, strlen (desc) + strlen (buffer) + 1); } i = strlen (desc); memcpy (desc + i, buffer, strlen (buffer)); @@ -344,11 +344,11 @@ bool rc_service_in_runlevel (const char *service, const char *runlevel) if (! runlevel || ! service) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), (char *) NULL); free (svc); - retval = rc_exists (file); + retval = exists (file); free (file); return (retval); @@ -368,11 +368,11 @@ bool rc_service_mark (const char *service, const rc_service_state_t state) if (! service) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); base = basename (svc); if (state != RC_SERVICE_STOPPED) { - if (! rc_exists (init)) { + if (! exists (init)) { free (init); free (svc); return (false); @@ -380,7 +380,7 @@ bool rc_service_mark (const char *service, const rc_service_state_t state) file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state), base, (char *) NULL); - if (rc_exists (file)) + if (exists (file)) unlink (file); i = symlink (init, file); if (i != 0) { @@ -412,7 +412,7 @@ bool rc_service_mark (const char *service, const rc_service_state_t state) { file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state(s), base, (char *) NULL); - if (rc_exists (file)) { + if (exists (file)) { if ((state == RC_SERVICE_STARTING || state == RC_SERVICE_STOPPING) && s == RC_SERVICE_INACTIVE) @@ -487,12 +487,12 @@ rc_service_state_t rc_service_state (const char *service) { int i; int state = RC_SERVICE_STOPPED; - char *svc = rc_xstrdup (service); + char *svc = strdup (service); for (i = 0; rc_service_state_names[i].name; i++) { char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name, basename (svc), (char*) NULL); - if (rc_exists (file)) { + if (exists (file)) { if (rc_service_state_names[i].state <= 0x10) state = rc_service_state_names[i].state; else @@ -525,7 +525,7 @@ char *rc_service_value_get (const char *service, const char *option) if ((fp = fopen (file, "r"))) { memset (buffer, 0, sizeof (buffer)); if (fgets (buffer, RC_LINEBUFFER, fp)) - value = rc_xstrdup (buffer); + value = strdup (buffer); fclose (fp); } free (file); @@ -569,14 +569,14 @@ static pid_t _exec_service (const char *service, const char *arg) char *svc; file = rc_service_resolve (service); - if (! rc_exists (file)) { + if (! exists (file)) { rc_service_mark (service, RC_SERVICE_STOPPED); free (file); return (0); } /* We create a fifo so that other services can wait until we complete */ - svc = rc_xstrdup (service); + svc = strdup (service); fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (svc), (char *) NULL); free (svc); @@ -634,7 +634,7 @@ bool rc_service_schedule_start (const char *service, if (! service || ! rc_service_exists (service_to_start)) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc), (char *) NULL); free (svc); @@ -644,10 +644,10 @@ bool rc_service_schedule_start (const char *service, } init = rc_service_resolve (service_to_start); - svc = rc_xstrdup (service_to_start); + svc = strdup (service_to_start); file = rc_strcatpaths (dir, basename (svc), (char *) NULL); free (svc); - retval = (rc_exists (file) || symlink (init, file) == 0); + retval = (exists (file) || symlink (init, file) == 0); free (init); free (file); free (dir); @@ -658,7 +658,7 @@ librc_hidden_def(rc_service_schedule_start) bool rc_service_schedule_clear (const char *service) { - char *svc = rc_xstrdup (service); + char *svc = strdup (service); char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc), (char *) NULL); bool retval; @@ -684,7 +684,7 @@ bool rc_service_wait (const char *service) if (! service) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); base = basename (svc); fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL); /* FIXME: find a better way of doing this @@ -697,7 +697,7 @@ bool rc_service_wait (const char *service) ts.tv_nsec = WAIT_INTERVAL; while (nloops) { - if (! rc_exists (fifo)) { + if (! exists (fifo)) { retval = true; break; } @@ -789,7 +789,7 @@ bool rc_service_add (const char *runlevel, const char *service) } init = rc_service_resolve (service); - svc = rc_xstrdup (service); + svc = strdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), (char *) NULL); free (svc); @@ -809,7 +809,7 @@ bool rc_service_delete (const char *runlevel, const char *service) if (! runlevel || ! service) return (false); - svc = rc_xstrdup (service); + svc = strdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), (char *) NULL); free (svc); @@ -831,7 +831,7 @@ char **rc_services_scheduled_by (const char *service) STRLIST_FOREACH (dirs, dir, i) { char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service, (char *) NULL); - if (rc_exists (file)) + if (exists (file)) rc_strlist_add (&list, file); free (file); } @@ -843,7 +843,7 @@ librc_hidden_def(rc_services_scheduled_by) char **rc_services_scheduled (const char *service) { - char *svc = rc_xstrdup (service); + char *svc = strdup (service); char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc), (char *) NULL); char **list = NULL; @@ -866,7 +866,7 @@ bool rc_service_plugable (char *service) if (! match) return true; - list = rc_xstrdup (match); + list = strdup (match); p = list; while ((token = strsep (&p, " "))) { bool truefalse = true; diff --git a/src/mountinfo.c b/src/mountinfo.c index be31012a..25e83ca5 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -173,7 +173,7 @@ static char **find_mounts (struct args *args) for (o = optnames; flags && o->o_opt; o++) { if (flags & o->o_opt) { if (! options) - options = rc_xstrdup (o->o_name); + options = strdup (o->o_name); else { char *tmp = NULL; asprintf (&tmp, "%s,%s", options, o->o_name); @@ -232,7 +232,7 @@ static char **find_mounts (struct args *args) static regex_t *get_regex (const char *string) { - regex_t *reg = rc_xmalloc (sizeof (regex_t)); + regex_t *reg = xmalloc (sizeof (regex_t)); int result; char buffer[256]; diff --git a/src/rc-misc.c b/src/rc-misc.c index 4bae93c7..f3fce324 100644 --- a/src/rc-misc.c +++ b/src/rc-misc.c @@ -54,7 +54,7 @@ char **env_filter (void) if (! whitelist) return (NULL); - if (rc_exists (PROFILE_ENV)) + if (exists (PROFILE_ENV)) profile = rc_config_load (PROFILE_ENV); STRLIST_FOREACH (whitelist, env_name, count) { @@ -66,7 +66,7 @@ char **env_filter (void) if (! env_var && profile) { env_len = strlen (env_name) + strlen ("export ") + 1; - p = rc_xmalloc (sizeof (char *) * env_len); + p = xmalloc (sizeof (char *) * env_len); snprintf (p, env_len, "export %s", env_name); env_var = rc_config_value (profile, p); free (p); @@ -82,13 +82,13 @@ char **env_filter (void) { got_path = true; env_len = strlen (env_name) + strlen (env_var) + pplen + 2; - e = p = rc_xmalloc (sizeof (char *) * env_len); + e = p = xmalloc (sizeof (char *) * env_len); p += snprintf (e, env_len, "%s=%s", env_name, PATH_PREFIX); /* Now go through the env var and only add bits not in our PREFIX */ sep = env_var; while ((token = strsep (&sep, ":"))) { - char *np = rc_xstrdup (PATH_PREFIX); + char *np = strdup (PATH_PREFIX); char *npp = np; char *tok = NULL; while ((tok = strsep (&npp, ":"))) @@ -101,7 +101,7 @@ char **env_filter (void) *p++ = 0; } else { env_len = strlen (env_name) + strlen (env_var) + 2; - e = rc_xmalloc (sizeof (char *) * env_len); + e = xmalloc (sizeof (char *) * env_len); snprintf (e, env_len, "%s=%s", env_name, env_var); } @@ -113,7 +113,7 @@ char **env_filter (void) However, we do need a path, so use a default. */ if (! got_path) { env_len = strlen ("PATH=") + strlen (PATH_PREFIX) + 2; - p = rc_xmalloc (sizeof (char *) * env_len); + p = xmalloc (sizeof (char *) * env_len); snprintf (p, env_len, "PATH=%s", PATH_PREFIX); rc_strlist_add (&env, p); free (p); @@ -178,7 +178,7 @@ char **env_config (void) /* Don't trust environ for softlevel yet */ snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel); - if (rc_exists (buffer)) + if (exists (buffer)) config = rc_config_load (buffer); else config = rc_config_load (RC_CONFIG); @@ -195,7 +195,7 @@ char **env_config (void) rc_strlist_add (&env, line); } else { int len = strlen (line) + strlen (e) + 2; - char *new = rc_xmalloc (sizeof (char *) * len); + char *new = xmalloc (sizeof (char *) * len); snprintf (new, len, "%s=%s", line, e); rc_strlist_add (&env, new); free (new); @@ -205,14 +205,14 @@ char **env_config (void) /* One char less to drop the trailing / */ i = strlen ("RC_LIBDIR=") + strlen (RC_LIBDIR) + 1; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_LIBDIR=" RC_LIBDIR); rc_strlist_add (&env, line); free (line); /* One char less to drop the trailing / */ i = strlen ("RC_SVCDIR=") + strlen (RC_SVCDIR) + 1; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_SVCDIR=" RC_SVCDIR); rc_strlist_add (&env, line); free (line); @@ -220,7 +220,7 @@ char **env_config (void) rc_strlist_add (&env, "RC_BOOTLEVEL=" RC_LEVEL_BOOT); i = strlen ("RC_SOFTLEVEL=") + strlen (runlevel) + 1; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_SOFTLEVEL=%s", runlevel); rc_strlist_add (&env, line); free (line); @@ -232,7 +232,7 @@ char **env_config (void) if (buffer[i] == '\n') buffer[i] = 0; i += strlen ("RC_DEFAULTLEVEL=") + 2; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer); rc_strlist_add (&env, line); free (line); @@ -247,7 +247,7 @@ char **env_config (void) We store this special system in RC_SYS so our scripts run fast */ memset (sys, 0, sizeof (sys)); - if (rc_exists ("/proc/xen")) { + if (exists ("/proc/xen")) { if ((fp = fopen ("/proc/xen/capabilities", "r"))) { fclose (fp); if (file_regex ("/proc/xen/capabilities", "control_d")) @@ -265,7 +265,7 @@ char **env_config (void) if (sys[0]) { i = strlen ("RC_SYS=") + strlen (sys) + 2; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_SYS=%s", sys); rc_strlist_add (&env, line); free (line); @@ -282,7 +282,7 @@ char **env_config (void) if (! has_net_fs_list) { i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_NET_FS_LIST=%s", RC_NET_FS_LIST_DEFAULT); rc_strlist_add (&env, line); free (line); @@ -292,7 +292,7 @@ char **env_config (void) To save on calling uname, we store it in an environment variable */ if (uname (&uts) == 0) { i = strlen ("RC_UNAME=") + strlen (uts.sysname) + 2; - line = rc_xmalloc (sizeof (char *) * i); + line = xmalloc (sizeof (char *) * i); snprintf (line, i, "RC_UNAME=%s", uts.sysname); rc_strlist_add (&env, line); free (line); diff --git a/src/rc-misc.h b/src/rc-misc.h index e7bef747..fb4ea855 100644 --- a/src/rc-misc.h +++ b/src/rc-misc.h @@ -43,7 +43,7 @@ #define ERRX fprintf (stderr, "out of memory\n"); exit (1) -static inline void *rc_xmalloc (size_t size) +static inline void *xmalloc (size_t size) { void *value = malloc (size); @@ -53,7 +53,7 @@ static inline void *rc_xmalloc (size_t size) ERRX; } -static inline void *rc_xrealloc (void *ptr, size_t size) +static inline void *xrealloc (void *ptr, size_t size) { void *value = realloc (ptr, size); @@ -63,7 +63,7 @@ static inline void *rc_xrealloc (void *ptr, size_t size) ERRX; } -static inline char *rc_xstrdup (const char *str) +static inline char *xstrdup (const char *str) { char *value; @@ -80,7 +80,7 @@ static inline char *rc_xstrdup (const char *str) #undef ERRX -static inline bool rc_exists (const char *pathname) +static inline bool exists (const char *pathname) { struct stat buf; diff --git a/src/rc-plugin.c b/src/rc-plugin.c index b367228f..b43d4990 100644 --- a/src/rc-plugin.c +++ b/src/rc-plugin.c @@ -85,13 +85,13 @@ void rc_plugin_load (void) dlclose (h); } else { if (plugin) { - plugin->next = rc_xmalloc (sizeof (plugin_t)); + plugin->next = xmalloc (sizeof (plugin_t)); plugin = plugin->next; } else - plugin = plugins = rc_xmalloc (sizeof (plugin_t)); + plugin = plugins = xmalloc (sizeof (plugin_t)); memset (plugin, 0, sizeof (plugin_t)); - plugin->name = rc_xstrdup (d->d_name); + plugin->name = strdup (d->d_name); plugin->handle = h; plugin->hook = fptr; } diff --git a/src/rc.c b/src/rc.c index c71284da..2730bf44 100644 --- a/src/rc.c +++ b/src/rc.c @@ -192,7 +192,7 @@ static int do_e (int argc, char **argv) for (i = 0; i < argc; i++) l += strlen (argv[i]) + 1; - message = rc_xmalloc (l); + message = xmalloc (l); p = message; for (i = 0; i < argc; i++) { @@ -205,7 +205,7 @@ static int do_e (int argc, char **argv) } if (message) - fmt = rc_xstrdup ("%s"); + fmt = strdup ("%s"); if (strcmp (applet, "einfo") == 0) einfo (fmt, message); @@ -338,10 +338,10 @@ static int do_mark_service (int argc, char **argv) strlen (svcname) + strlen (runscript_pid) + 4; - mtime = rc_xmalloc (l); + mtime = xmalloc (l); snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", svcname, runscript_pid); - if (rc_exists (mtime) && unlink (mtime) != 0) + if (exists (mtime) && unlink (mtime) != 0) eerror ("%s: unlink: %s", applet, strerror (errno)); free (mtime); } @@ -384,7 +384,7 @@ static char *proc_getent (const char *ent) char *value = NULL; int i; - if (! rc_exists ("/proc/cmdline")) + if (! exists ("/proc/cmdline")) return (NULL); if (! (fp = fopen ("/proc/cmdline", "r"))) { @@ -428,7 +428,7 @@ static char read_key (bool block) /* Now save our terminal settings. We need to restore them at exit as we will be changing it for non-blocking reads for Interactive */ if (! termios_orig) { - termios_orig = rc_xmalloc (sizeof (struct termios)); + termios_orig = xmalloc (sizeof (struct termios)); tcgetattr (fd, termios_orig); } @@ -547,7 +547,7 @@ static void set_ksoftlevel (const char *level) strcmp (level, RC_LEVEL_SINGLE) == 0 || strcmp (level, RC_LEVEL_SYSINIT) == 0) { - if (rc_exists (RC_KSOFTLEVEL) && + if (exists (RC_KSOFTLEVEL) && unlink (RC_KSOFTLEVEL) != 0) eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); return; @@ -567,7 +567,7 @@ static int get_ksoftlevel (char *buffer, int buffer_len) FILE *fp; int i = 0; - if (! rc_exists (RC_KSOFTLEVEL)) + if (! exists (RC_KSOFTLEVEL)) return (0); if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { @@ -597,10 +597,10 @@ static void add_pid (pid_t pid) if (sp) { while (sp->next) sp = sp->next; - sp->next = rc_xmalloc (sizeof (pidlist_t)); + sp->next = xmalloc (sizeof (pidlist_t)); sp = sp->next; } else - sp = service_pids = rc_xmalloc (sizeof (pidlist_t)); + sp = service_pids = xmalloc (sizeof (pidlist_t)); memset (sp, 0, sizeof (pidlist_t)); sp->pid = pid; } @@ -757,7 +757,7 @@ int main (int argc, char **argv) atexit (cleanup); if (argv[0]) - applet = rc_xstrdup (basename (argv[0])); + applet = strdup (basename (argv[0])); if (! applet) eerrorx ("arguments required"); @@ -858,7 +858,7 @@ int main (int argc, char **argv) some kernels bitch about this according to the environ man pages so we walk though environ and call unsetenv for each value. */ while (environ[0]) { - tmp = rc_xstrdup (environ[0]); + tmp = strdup (environ[0]); p = tmp; var = strsep (&p, "="); unsetenv (var); @@ -898,7 +898,7 @@ int main (int argc, char **argv) snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); setenv ("RC_PID", pidstr, 1); - interactive = rc_exists (INTERACTIVE); + interactive = exists (INTERACTIVE); rc_plugin_load (); /* Load current softlevel */ @@ -925,7 +925,7 @@ int main (int argc, char **argv) /* exec init-early.sh if it exists * This should just setup the console to use the correct * font. Maybe it should setup the keyboard too? */ - if (rc_exists (INITEARLYSH)) + if (exists (INITEARLYSH)) run_script (INITEARLYSH); uname (&uts); @@ -1104,7 +1104,7 @@ int main (int argc, char **argv) if ((dp = opendir ("/dev/net"))) { while ((d = readdir (dp))) { i = (strlen ("net.") + strlen (d->d_name) + 1); - tmp = rc_xmalloc (sizeof (char *) * i); + tmp = xmalloc (sizeof (char *) * i); snprintf (tmp, i, "net.%s", d->d_name); if (rc_service_exists (tmp) && rc_service_plugable (tmp)) @@ -1125,7 +1125,7 @@ int main (int argc, char **argv) char *p = d->d_name + 3; if (p && isdigit (*p)) { i = (strlen ("moused.") + strlen (d->d_name) + 1); - tmp = rc_xmalloc (sizeof (char *) * i); + tmp = xmalloc (sizeof (char *) * i); snprintf (tmp, i, "moused.%s", d->d_name); if (rc_service_exists (tmp) && rc_service_plugable (tmp)) rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); @@ -1245,18 +1245,18 @@ int main (int argc, char **argv) continue; len = strlen (service) + strlen (runlevel) + 2; - tmp = rc_xmalloc (sizeof (char *) * len); + tmp = xmalloc (sizeof (char *) * len); snprintf (tmp, len, "%s.%s", service, runlevel); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); - found = rc_exists (conf); + found = exists (conf); CHAR_FREE (conf); CHAR_FREE (tmp); if (! found) { len = strlen (service) + strlen (newlevel) + 2; - tmp = rc_xmalloc (sizeof (char *) * len); + tmp = xmalloc (sizeof (char *) * len); snprintf (tmp, len, "%s.%s", service, newlevel); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); - found = rc_exists (conf); + found = exists (conf); CHAR_FREE (conf); CHAR_FREE (tmp); if (!found) @@ -1310,7 +1310,7 @@ int main (int argc, char **argv) if (newlevel) { rc_runlevel_set (newlevel); free (runlevel); - runlevel = rc_xstrdup (newlevel); + runlevel = strdup (newlevel); setenv ("RC_SOFTLEVEL", runlevel, 1); } @@ -1325,7 +1325,7 @@ int main (int argc, char **argv) /* Single user is done now */ if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { - if (rc_exists (INTERACTIVE)) + if (exists (INTERACTIVE)) unlink (INTERACTIVE); sulogin (false); } @@ -1423,7 +1423,7 @@ interactive_option: if (interactive && strcmp (runlevel, bootlevel) == 0) mark_interactive (); else { - if (rc_exists (INTERACTIVE)) + if (exists (INTERACTIVE)) unlink (INTERACTIVE); } diff --git a/src/runscript.c b/src/runscript.c index ffb55103..e95fc5b0 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -83,7 +83,7 @@ static void setup_selinux (int argc, char **argv) { void *lib_handle = NULL; - if (! rc_exists (SELINUX_LIB)) + if (! exists (SELINUX_LIB)) return; lib_handle = dlopen (SELINUX_LIB, RTLD_NOW | RTLD_GLOBAL); @@ -97,7 +97,7 @@ static void setup_selinux (int argc, char **argv) selinux_run_init_new = (void (*)(int, char **)) dlfunc (lib_handle, "selinux_runscript2"); - /* Use new run_init if it rc_exists, else fall back to old */ + /* Use new run_init if it exists, else fall back to old */ if (selinux_run_init_new) selinux_run_init_new (argc, argv); else if (selinux_run_init_old) @@ -186,7 +186,7 @@ static bool in_control () if (sighup) return (false); - if (! mtime_test || ! rc_exists (mtime_test)) + if (! mtime_test || ! exists (mtime_test)) return (false); if (rc_service_state (applet) & RC_SERVICE_STOPPED) @@ -197,7 +197,7 @@ static bool in_control () while (tests[i]) { path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL); - if (rc_exists (path)) { + if (exists (path)) { time_t m = get_mtime (path, false); if (mtime < m && m != 0) { free (path); @@ -214,7 +214,7 @@ static bool in_control () static void uncoldplug () { char *cold = rc_strcatpaths (RC_SVCDIR, "coldplugged", applet, (char *) NULL); - if (rc_exists (cold) && unlink (cold) != 0) + if (exists (cold) && unlink (cold) != 0) eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno)); free (cold); } @@ -284,7 +284,7 @@ static void cleanup (void) else rc_service_mark (applet, RC_SERVICE_STARTED); } - if (exclusive && rc_exists (exclusive)) + if (exclusive && exists (exclusive)) unlink (exclusive); } @@ -401,7 +401,7 @@ static bool svc_exec (const char *arg1, const char *arg2) close (slave_tty); } - if (rc_exists (RC_SVCDIR "/runscript.sh")) { + if (exists (RC_SVCDIR "/runscript.sh")) { execl (RC_SVCDIR "/runscript.sh", service, service, arg1, arg2, (char *) NULL); eerror ("%s: exec `" RC_SVCDIR "/runscript.sh': %s", @@ -503,11 +503,11 @@ static void make_exclusive () path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL); i = strlen (path) + 16; - mtime_test = rc_xmalloc (sizeof (char *) * i); + mtime_test = xmalloc (sizeof (char *) * i); snprintf (mtime_test, i, "%s.%d", path, getpid ()); free (path); - if (rc_exists (mtime_test) && unlink (mtime_test) != 0) { + if (exists (mtime_test) && unlink (mtime_test) != 0) { eerror ("%s: unlink `%s': %s", applet, mtime_test, strerror (errno)); free (mtime_test); @@ -711,7 +711,7 @@ static void svc_start (bool deps) } len += 5; - tmp = rc_xmalloc (sizeof (char *) * len); + tmp = xmalloc (sizeof (char *) * len); p = tmp; STRLIST_FOREACH (tmplist, svc, i) { if (i > 1) { @@ -1009,7 +1009,7 @@ int runscript (int argc, char **argv) /* We need the full path to the service */ if (*argv[1] == '/') - service = rc_xstrdup (argv[1]); + service = strdup (argv[1]); else { char pwd[PATH_MAX]; if (! getcwd (pwd, PATH_MAX)) @@ -1017,7 +1017,7 @@ int runscript (int argc, char **argv) service = rc_strcatpaths (pwd, argv[1], (char *) NULL); } - applet = rc_xstrdup (basename (service)); + applet = strdup (basename (service)); atexit (cleanup); /* Change dir to / to ensure all init scripts don't use stuff in pwd */ @@ -1033,7 +1033,7 @@ int runscript (int argc, char **argv) #ifdef __linux__ /* coldplug events can trigger init scripts, but we don't want to run them until after rc sysinit has completed so we punt them to the boot runlevel */ - if (rc_exists ("/dev/.rcsysinit")) { + if (exists ("/dev/.rcsysinit")) { eerror ("%s: cannot run until sysvinit completes", applet); if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST) eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno)); @@ -1043,7 +1043,7 @@ int runscript (int argc, char **argv) } #endif - if ((softlevel = rc_xstrdup (getenv ("RC_SOFTLEVEL"))) == NULL) { + if ((softlevel = strdup (getenv ("RC_SOFTLEVEL"))) == NULL) { /* Ensure our environment is pure Also, add our configuration to it */ tmplist = env_config (); @@ -1066,7 +1066,7 @@ int runscript (int argc, char **argv) some kernels bitch about this according to the environ man pages so we walk though environ and call unsetenv for each value. */ while (environ[0]) { - tmp = rc_xstrdup (environ[0]); + tmp = strdup (environ[0]); p = tmp; var = strsep (&p, "="); unsetenv (var); @@ -1106,7 +1106,7 @@ int runscript (int argc, char **argv) } /* Make our prefix string */ - prefix = rc_xmalloc (sizeof (char *) * l); + prefix = xmalloc (sizeof (char *) * l); ll = strlen (applet); memcpy (prefix, applet, ll); memset (prefix + ll, ' ', l - ll); @@ -1144,7 +1144,7 @@ int runscript (int argc, char **argv) that is being called and not any dependents */ if (getenv ("IN_BACKGROUND")) { in_background = rc_env_bool ("IN_BACKGROUND"); - ibsave = rc_xstrdup (getenv ("IN_BACKGROUND")); + ibsave = strdup (getenv ("IN_BACKGROUND")); unsetenv ("IN_BACKGROUND"); } diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 80bc86fe..4d6dff44 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -191,13 +191,13 @@ static void parse_schedule (const char *string, int default_signal) if (schedule) free_schedulelist (&schedule); - schedule = rc_xmalloc (sizeof (schedulelist_t)); + schedule = xmalloc (sizeof (schedulelist_t)); schedule->gotolist = NULL; if (count == 0) { schedule->type = schedule_signal; schedule->value = default_signal; - schedule->next = rc_xmalloc (sizeof (schedulelist_t)); + schedule->next = xmalloc (sizeof (schedulelist_t)); next = schedule->next; next->type = schedule_timeout; next->gotolist = NULL; @@ -237,14 +237,14 @@ static void parse_schedule (const char *string, int default_signal) } if (string) { - next->next = rc_xmalloc (sizeof (schedulelist_t)); + next->next = xmalloc (sizeof (schedulelist_t)); next = next->next; next->gotolist = NULL; } } if (repeatat) { - next->next = rc_xmalloc (sizeof (schedulelist_t)); + next->next = xmalloc (sizeof (schedulelist_t)); next = next->next; next->type = schedule_goto; next->value = 0; @@ -593,7 +593,7 @@ int start_stop_daemon (int argc, char **argv) char *cu = strsep (&p, ":"); struct passwd *pw = NULL; - changeuser = rc_xstrdup (cu); + changeuser = strdup (cu); if (sscanf (cu, "%d", &tid) != 1) pw = getpwnam (cu); else @@ -728,7 +728,7 @@ int start_stop_daemon (int argc, char **argv) tmp = rc_strcatpaths (ch_root, exec, (char *) NULL); else tmp = exec; - if (! rc_exists (tmp)) { + if (! exists (tmp)) { eerror ("%s: %s does not exist", applet, tmp); if (ch_root) free (tmp); @@ -754,7 +754,7 @@ int start_stop_daemon (int argc, char **argv) if (result < 1) exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); - if (pidfile && rc_exists (pidfile)) + if (pidfile && exists (pidfile)) unlink (pidfile); if (svcname) @@ -886,7 +886,7 @@ int start_stop_daemon (int argc, char **argv) /* For the path, remove the rcscript bin dir from it */ if (strncmp (env, "PATH=", 5) == 0) { - char *path = rc_xstrdup (env); + char *path = strdup (env); char *newpath = NULL; char *p = path; char *token; -- cgit v1.2.3