Punt rc_ from xstrdup, xalloc, xrealloc and exists as they're not in librc anymore

This commit is contained in:
Roy Marples 2007-10-08 11:11:21 +00:00
parent e7dab9bb91
commit a89ceb7e2c
13 changed files with 154 additions and 154 deletions

View File

@ -152,7 +152,7 @@ int env_update (int argc, char **argv)
entries = rc_config_load (path); entries = rc_config_load (path);
STRLIST_FOREACH (entries, entry, j) { STRLIST_FOREACH (entries, entry, j) {
char *tmpent = rc_xstrdup (entry); char *tmpent = strdup (entry);
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
@ -176,7 +176,7 @@ int env_update (int argc, char **argv)
eerrorx ("%s: nothing to process", applet); eerrorx ("%s: nothing to process", applet);
STRLIST_FOREACH (config, entry, i) { STRLIST_FOREACH (config, entry, i) {
char *tmpent = rc_xstrdup (entry); char *tmpent = strdup (entry);
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
char *match; char *match;
@ -220,19 +220,19 @@ int env_update (int argc, char **argv)
} }
STRLIST_FOREACH (envs, env, j) { STRLIST_FOREACH (envs, env, j) {
char *tmpenv = rc_xstrdup (env); char *tmpenv = strdup (env);
char *tmpvalue = tmpenv; char *tmpvalue = tmpenv;
char *tmpentry = strsep (&tmpvalue, "="); char *tmpentry = strsep (&tmpvalue, "=");
if (strcmp (tmpentry, var) == 0) { if (strcmp (tmpentry, var) == 0) {
if (colon || space) { if (colon || space) {
int len = strlen (envs[j - 1]) + strlen (entry) + 1; 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, snprintf (envs[j - 1] + strlen (envs[j - 1]), len,
"%s%s", colon ? ":" : " ", value); "%s%s", colon ? ":" : " ", value);
} else { } else {
free (envs[j - 1]); free (envs[j - 1]);
envs[j - 1] = rc_xstrdup (entry); envs[j - 1] = strdup (entry);
} }
replaced = true; replaced = true;
} }
@ -256,7 +256,7 @@ int env_update (int argc, char **argv)
fprintf (fp, NOTICE, "/etc/profile", PROFILE_ENV); fprintf (fp, NOTICE, "/etc/profile", PROFILE_ENV);
STRLIST_FOREACH (envs, env, i) { STRLIST_FOREACH (envs, env, i) {
char *tmpent = rc_xstrdup (env); char *tmpent = strdup (env);
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
if (strcmp (var, "LDPATH") != 0) { if (strcmp (var, "LDPATH") != 0) {
@ -274,7 +274,7 @@ int env_update (int argc, char **argv)
fprintf (fp, NOTICE, "/etc/csh.cshrc", PROFILE_ENV); fprintf (fp, NOTICE, "/etc/csh.cshrc", PROFILE_ENV);
STRLIST_FOREACH (envs, env, i) { STRLIST_FOREACH (envs, env, i) {
char *tmpent = rc_xstrdup (env); char *tmpent = strdup (env);
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
if (strcmp (var, "LDPATH") != 0) { if (strcmp (var, "LDPATH") != 0) {
@ -303,7 +303,7 @@ int env_update (int argc, char **argv)
if (ldconfig) { if (ldconfig) {
/* Update ld.so.conf only if different */ /* Update ld.so.conf only if different */
if (rc_exists (LDSOCONF)) { if (exists (LDSOCONF)) {
char **lines = rc_config_list (LDSOCONF); char **lines = rc_config_list (LDSOCONF);
char *line; char *line;
ld = false; ld = false;

View File

@ -304,31 +304,31 @@ bool rc_service_daemon_set (const char *service, const char *exec,
errno = EINVAL; errno = EINVAL;
return (false); return (false);
} }
svc = rc_xstrdup (service); svc = strdup (service);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", dirpath = rc_strcatpaths (RC_SVCDIR, "daemons",
basename (svc), (char *) NULL); basename (svc), (char *) NULL);
free (svc); free (svc);
if (exec) { if (exec) {
i = strlen (exec) + 6; i = strlen (exec) + 6;
mexec = rc_xmalloc (sizeof (char *) * i); mexec = xmalloc (sizeof (char *) * i);
snprintf (mexec, i, "exec=%s", exec); snprintf (mexec, i, "exec=%s", exec);
} else } else
mexec = rc_xstrdup ("exec="); mexec = strdup ("exec=");
if (name) { if (name) {
i = strlen (name) + 6; i = strlen (name) + 6;
mname = rc_xmalloc (sizeof (char *) * i); mname = xmalloc (sizeof (char *) * i);
snprintf (mname, i, "name=%s", name); snprintf (mname, i, "name=%s", name);
} else } else
mname = rc_xstrdup ("name="); mname = strdup ("name=");
if (pidfile) { if (pidfile) {
i = strlen (pidfile) + 9; i = strlen (pidfile) + 9;
mpidfile = rc_xmalloc (sizeof (char *) * i); mpidfile = xmalloc (sizeof (char *) * i);
snprintf (mpidfile, i, "pidfile=%s", pidfile); snprintf (mpidfile, i, "pidfile=%s", pidfile);
} else } else
mpidfile = rc_xstrdup ("pidfile="); mpidfile = strdup ("pidfile=");
/* Regardless, erase any existing daemon info */ /* Regardless, erase any existing daemon info */
if ((dp = opendir (dirpath))) { if ((dp = opendir (dirpath))) {
@ -398,18 +398,18 @@ bool rc_service_started_daemon (const char *service, const char *exec,
if (! service || ! exec) if (! service || ! exec)
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
i = strlen (exec) + 6; i = strlen (exec) + 6;
mexec = rc_xmalloc (sizeof (char *) * i); mexec = xmalloc (sizeof (char *) * i);
snprintf (mexec, i, "exec=%s", exec); snprintf (mexec, i, "exec=%s", exec);
if (indx > 0) { if (indx > 0) {
int len = sizeof (char *) * 10; int len = sizeof (char *) * 10;
file = rc_xmalloc (len); file = xmalloc (len);
snprintf (file, len, "%03d", indx); snprintf (file, len, "%03d", indx);
retval = _match_daemon (dirpath, file, mexec, NULL, NULL); retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
free (file); free (file);
@ -453,7 +453,7 @@ bool rc_service_daemons_crashed (const char *service)
if (! service) if (! service)
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
@ -488,22 +488,22 @@ bool rc_service_daemons_crashed (const char *service)
if (strcmp (token, "exec") == 0) { if (strcmp (token, "exec") == 0) {
if (exec) if (exec)
free (exec); free (exec);
exec = rc_xstrdup (p); exec = strdup (p);
} else if (strcmp (token, "name") == 0) { } else if (strcmp (token, "name") == 0) {
if (name) if (name)
free (name); free (name);
name = rc_xstrdup (p); name = strdup (p);
} else if (strcmp (token, "pidfile") == 0) { } else if (strcmp (token, "pidfile") == 0) {
if (pidfile) if (pidfile)
free (pidfile); free (pidfile);
pidfile = rc_xstrdup (p); pidfile = strdup (p);
} }
} }
fclose (fp); fclose (fp);
pid = 0; pid = 0;
if (pidfile) { if (pidfile) {
if (! rc_exists (pidfile)) { if (! exists (pidfile)) {
retval = true; retval = true;
break; break;
} }

View File

@ -101,16 +101,16 @@ rc_depinfo_t *rc_deptree_load (void)
if (! deptree) if (! deptree)
{ {
deptree = rc_xmalloc (sizeof (rc_depinfo_t)); deptree = xmalloc (sizeof (rc_depinfo_t));
depinfo = deptree; depinfo = deptree;
} }
else else
{ {
depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); depinfo->next = xmalloc (sizeof (rc_depinfo_t));
depinfo = depinfo->next; depinfo = depinfo->next;
} }
memset (depinfo, 0, sizeof (rc_depinfo_t)); memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = rc_xstrdup (e); depinfo->service = strdup (e);
deptype = NULL; deptype = NULL;
continue; continue;
} }
@ -126,20 +126,20 @@ rc_depinfo_t *rc_deptree_load (void)
if (! deptype) if (! deptype)
{ {
depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t)); depinfo->depends = xmalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends; deptype = depinfo->depends;
memset (deptype, 0, sizeof (rc_deptype_t)); memset (deptype, 0, sizeof (rc_deptype_t));
} }
else else
if (strcmp (deptype->type, type) != 0) if (strcmp (deptype->type, type) != 0)
{ {
deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); deptype->next = xmalloc (sizeof (rc_deptype_t));
deptype = deptype->next; deptype = deptype->next;
memset (deptype, 0, sizeof (rc_deptype_t)); memset (deptype, 0, sizeof (rc_deptype_t));
} }
if (! deptype->type) if (! deptype->type)
deptype->type = rc_xstrdup (type); deptype->type = strdup (type);
rc_strlist_addsort (&deptype->services, e); rc_strlist_addsort (&deptype->services, e);
} }
@ -683,7 +683,7 @@ bool rc_deptree_update (void)
if (! (fp = popen (GENDEP, "r"))) if (! (fp = popen (GENDEP, "r")))
return (false); return (false);
deptree = rc_xmalloc (sizeof (rc_depinfo_t)); deptree = xmalloc (sizeof (rc_depinfo_t));
memset (deptree, 0, sizeof (rc_depinfo_t)); memset (deptree, 0, sizeof (rc_depinfo_t));
memset (buffer, 0, RC_LINEBUFFER); memset (buffer, 0, RC_LINEBUFFER);
@ -713,11 +713,11 @@ bool rc_deptree_update (void)
depinfo = last_depinfo; depinfo = last_depinfo;
else else
{ {
last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); last_depinfo->next = xmalloc (sizeof (rc_depinfo_t));
depinfo = last_depinfo->next; depinfo = last_depinfo->next;
} }
memset (depinfo, 0, sizeof (rc_depinfo_t)); memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = rc_xstrdup (service); depinfo->service = strdup (service);
} }
/* We may not have any depends */ /* We may not have any depends */
@ -738,16 +738,16 @@ bool rc_deptree_update (void)
{ {
if (! last_deptype) if (! last_deptype)
{ {
depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t)); depinfo->depends = xmalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends; deptype = depinfo->depends;
} }
else else
{ {
last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); last_deptype->next = xmalloc (sizeof (rc_deptype_t));
deptype = last_deptype->next; deptype = last_deptype->next;
} }
memset (deptype, 0, sizeof (rc_deptype_t)); 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) if (! di)
{ {
last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); last_depinfo->next = xmalloc (sizeof (rc_depinfo_t));
di = last_depinfo->next; di = last_depinfo->next;
memset (di, 0, sizeof (rc_depinfo_t)); 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) if (! last_deptype)
{ {
di->depends = rc_xmalloc (sizeof (rc_deptype_t)); di->depends = xmalloc (sizeof (rc_deptype_t));
dt = di->depends; dt = di->depends;
} }
else else
{ {
last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); last_deptype->next = xmalloc (sizeof (rc_deptype_t));
dt = last_deptype->next; dt = last_deptype->next;
} }
memset (dt, 0, sizeof (rc_deptype_t)); memset (dt, 0, sizeof (rc_deptype_t));
dt->type = rc_xstrdup (deppairs[i].addto); dt->type = strdup (deppairs[i].addto);
} }
already_added = false; already_added = false;

View File

@ -58,7 +58,7 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...)
} }
va_end (ap); va_end (ap);
pathp = path = rc_xmalloc (length * sizeof (char *)); pathp = path = xmalloc (length * sizeof (char *));
memset (path, 0, length); memset (path, 0, length);
i = strlen (path1); i = strlen (path1);
memcpy (path, path1, i); memcpy (path, path1, i);
@ -120,7 +120,7 @@ char **rc_config_load (const char *file)
if (! token) if (! token)
continue; continue;
entry = rc_xstrdup (token); entry = strdup (token);
/* Preserve shell coloring */ /* Preserve shell coloring */
if (*p == '$') if (*p == '$')
@ -137,14 +137,14 @@ char **rc_config_load (const char *file)
token[i] = 0; token[i] = 0;
i = strlen (entry) + strlen (token) + 2; i = strlen (entry) + strlen (token) + 2;
newline = rc_xmalloc (i); newline = xmalloc (i);
snprintf (newline, i, "%s=%s", entry, token); snprintf (newline, i, "%s=%s", entry, token);
replaced = false; replaced = false;
/* In shells the last item takes precedence, so we need to remove /* In shells the last item takes precedence, so we need to remove
any prior values we may already have */ any prior values we may already have */
STRLIST_FOREACH (list, line, i) { STRLIST_FOREACH (list, line, i) {
char *tmp = rc_xstrdup (line); char *tmp = strdup (line);
linep = tmp; linep = tmp;
linetok = strsep (&linep, "="); linetok = strsep (&linep, "=");
if (strcmp (linetok, entry) == 0) { if (strcmp (linetok, entry) == 0) {

View File

@ -26,8 +26,8 @@ static char *_rc_strlist_add (char ***list, const char *item, bool uniq)
i++; i++;
} }
newlist = rc_xrealloc (lst, sizeof (char *) * (i + 2)); newlist = xrealloc (lst, sizeof (char *) * (i + 2));
newlist[i] = rc_xstrdup (item); newlist[i] = strdup (item);
newlist[i + 1] = NULL; newlist[i + 1] = NULL;
*list = newlist; *list = newlist;
@ -69,7 +69,7 @@ static char *_rc_strlist_addsort (char ***list, const char *item,
i++; i++;
} }
newlist = rc_xrealloc (lst, sizeof (char *) * (i + 2)); newlist = xrealloc (lst, sizeof (char *) * (i + 2));
if (! i) if (! i)
newlist[i] = NULL; newlist[i] = NULL;
@ -80,7 +80,7 @@ static char *_rc_strlist_addsort (char ***list, const char *item,
i++; i++;
tmp1 = newlist[i]; tmp1 = newlist[i];
retval = newlist[i] = rc_xstrdup (item); retval = newlist[i] = strdup (item);
do { do {
i++; i++;
tmp2 = newlist[i]; tmp2 = newlist[i];
@ -151,7 +151,7 @@ char *rc_strlist_join (char ***list1, char **list2)
while (list2[j]) while (list2[j])
j++; j++;
newlist = rc_xrealloc (lst1, sizeof (char *) * (i + j + 1)); newlist = xrealloc (lst1, sizeof (char *) * (i + j + 1));
j = 0; j = 0;
while (list2[j]) { while (list2[j]) {

View File

@ -61,7 +61,7 @@ static char **ls_dir (const char *dir, int options)
int l = strlen (d->d_name); int l = strlen (d->d_name);
char *init = rc_strcatpaths (RC_INITDIR, d->d_name, char *init = rc_strcatpaths (RC_INITDIR, d->d_name,
(char *) NULL); (char *) NULL);
bool ok = rc_exists (init); bool ok = exists (init);
free (init); free (init);
if (! ok) if (! ok)
continue; continue;
@ -137,13 +137,13 @@ static const char *rc_parse_service_state (rc_service_state_t state)
bool rc_runlevel_starting (void) bool rc_runlevel_starting (void)
{ {
return (rc_exists (RC_STARTING)); return (exists (RC_STARTING));
} }
librc_hidden_def(rc_runlevel_starting) librc_hidden_def(rc_runlevel_starting)
bool rc_runlevel_stopping (void) bool rc_runlevel_stopping (void)
{ {
return (rc_exists (RC_STOPPING)); return (exists (RC_STOPPING));
} }
librc_hidden_def(rc_runlevel_stopping) librc_hidden_def(rc_runlevel_stopping)
@ -164,13 +164,13 @@ char *rc_runlevel_get (void)
int i = strlen (buffer) - 1; int i = strlen (buffer) - 1;
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
runlevel = rc_xstrdup (buffer); runlevel = strdup (buffer);
} }
fclose (fp); fclose (fp);
} }
if (! runlevel) if (! runlevel)
runlevel = rc_xstrdup (RC_LEVEL_SYSINIT); runlevel = strdup (RC_LEVEL_SYSINIT);
return (runlevel); return (runlevel);
} }
@ -217,7 +217,7 @@ char *rc_service_resolve (const char *service)
return (NULL); return (NULL);
if (service[0] == '/') if (service[0] == '/')
return (rc_xstrdup (service)); return (strdup (service));
file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL);
if (lstat (file, &buf) || ! S_ISLNK (buf.st_mode)) { 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)); r = readlink (file, buffer, sizeof (buffer));
free (file); free (file);
if (r > 0) if (r > 0)
return (rc_xstrdup (buffer)); return (strdup (buffer));
} }
snprintf (buffer, sizeof (buffer), RC_INITDIR "/%s", service); snprintf (buffer, sizeof (buffer), RC_INITDIR "/%s", service);
return (rc_xstrdup (buffer)); return (strdup (buffer));
} }
librc_hidden_def(rc_service_resolve) 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)) { while (fgets (buffer, RC_LINEBUFFER, fp)) {
if (! desc) { if (! desc) {
desc = rc_xmalloc (strlen (buffer) + 1); desc = xmalloc (strlen (buffer) + 1);
*desc = '\0'; *desc = '\0';
} else { } else {
desc = rc_xrealloc (desc, strlen (desc) + strlen (buffer) + 1); desc = xrealloc (desc, strlen (desc) + strlen (buffer) + 1);
} }
i = strlen (desc); i = strlen (desc);
memcpy (desc + i, buffer, strlen (buffer)); memcpy (desc + i, buffer, strlen (buffer));
@ -344,11 +344,11 @@ bool rc_service_in_runlevel (const char *service, const char *runlevel)
if (! runlevel || ! service) if (! runlevel || ! service)
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
retval = rc_exists (file); retval = exists (file);
free (file); free (file);
return (retval); return (retval);
@ -368,11 +368,11 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
if (! service) if (! service)
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
base = basename (svc); base = basename (svc);
if (state != RC_SERVICE_STOPPED) { if (state != RC_SERVICE_STOPPED) {
if (! rc_exists (init)) { if (! exists (init)) {
free (init); free (init);
free (svc); free (svc);
return (false); 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, file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state), base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (exists (file))
unlink (file); unlink (file);
i = symlink (init, file); i = symlink (init, file);
if (i != 0) { 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, file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state(s), base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) { if (exists (file)) {
if ((state == RC_SERVICE_STARTING || if ((state == RC_SERVICE_STARTING ||
state == RC_SERVICE_STOPPING) && state == RC_SERVICE_STOPPING) &&
s == RC_SERVICE_INACTIVE) s == RC_SERVICE_INACTIVE)
@ -487,12 +487,12 @@ rc_service_state_t rc_service_state (const char *service)
{ {
int i; int i;
int state = RC_SERVICE_STOPPED; int state = RC_SERVICE_STOPPED;
char *svc = rc_xstrdup (service); char *svc = strdup (service);
for (i = 0; rc_service_state_names[i].name; i++) { for (i = 0; rc_service_state_names[i].name; i++) {
char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name, char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name,
basename (svc), (char*) NULL); basename (svc), (char*) NULL);
if (rc_exists (file)) { if (exists (file)) {
if (rc_service_state_names[i].state <= 0x10) if (rc_service_state_names[i].state <= 0x10)
state = rc_service_state_names[i].state; state = rc_service_state_names[i].state;
else else
@ -525,7 +525,7 @@ char *rc_service_value_get (const char *service, const char *option)
if ((fp = fopen (file, "r"))) { if ((fp = fopen (file, "r"))) {
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
if (fgets (buffer, RC_LINEBUFFER, fp)) if (fgets (buffer, RC_LINEBUFFER, fp))
value = rc_xstrdup (buffer); value = strdup (buffer);
fclose (fp); fclose (fp);
} }
free (file); free (file);
@ -569,14 +569,14 @@ static pid_t _exec_service (const char *service, const char *arg)
char *svc; char *svc;
file = rc_service_resolve (service); file = rc_service_resolve (service);
if (! rc_exists (file)) { if (! exists (file)) {
rc_service_mark (service, RC_SERVICE_STOPPED); rc_service_mark (service, RC_SERVICE_STOPPED);
free (file); free (file);
return (0); return (0);
} }
/* We create a fifo so that other services can wait until we complete */ /* 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), fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
@ -634,7 +634,7 @@ bool rc_service_schedule_start (const char *service,
if (! service || ! rc_service_exists (service_to_start)) if (! service || ! rc_service_exists (service_to_start))
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc), dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
@ -644,10 +644,10 @@ bool rc_service_schedule_start (const char *service,
} }
init = rc_service_resolve (service_to_start); 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); file = rc_strcatpaths (dir, basename (svc), (char *) NULL);
free (svc); free (svc);
retval = (rc_exists (file) || symlink (init, file) == 0); retval = (exists (file) || symlink (init, file) == 0);
free (init); free (init);
free (file); free (file);
free (dir); free (dir);
@ -658,7 +658,7 @@ librc_hidden_def(rc_service_schedule_start)
bool rc_service_schedule_clear (const char *service) 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 *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
(char *) NULL); (char *) NULL);
bool retval; bool retval;
@ -684,7 +684,7 @@ bool rc_service_wait (const char *service)
if (! service) if (! service)
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
base = basename (svc); base = basename (svc);
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL); fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
/* FIXME: find a better way of doing this /* FIXME: find a better way of doing this
@ -697,7 +697,7 @@ bool rc_service_wait (const char *service)
ts.tv_nsec = WAIT_INTERVAL; ts.tv_nsec = WAIT_INTERVAL;
while (nloops) { while (nloops) {
if (! rc_exists (fifo)) { if (! exists (fifo)) {
retval = true; retval = true;
break; break;
} }
@ -789,7 +789,7 @@ bool rc_service_add (const char *runlevel, const char *service)
} }
init = rc_service_resolve (service); init = rc_service_resolve (service);
svc = rc_xstrdup (service); svc = strdup (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
@ -809,7 +809,7 @@ bool rc_service_delete (const char *runlevel, const char *service)
if (! runlevel || ! service) if (! runlevel || ! service)
return (false); return (false);
svc = rc_xstrdup (service); svc = strdup (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
@ -831,7 +831,7 @@ char **rc_services_scheduled_by (const char *service)
STRLIST_FOREACH (dirs, dir, i) { STRLIST_FOREACH (dirs, dir, i) {
char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service, char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (exists (file))
rc_strlist_add (&list, file); rc_strlist_add (&list, file);
free (file); free (file);
} }
@ -843,7 +843,7 @@ librc_hidden_def(rc_services_scheduled_by)
char **rc_services_scheduled (const char *service) 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 *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
@ -866,7 +866,7 @@ bool rc_service_plugable (char *service)
if (! match) if (! match)
return true; return true;
list = rc_xstrdup (match); list = strdup (match);
p = list; p = list;
while ((token = strsep (&p, " "))) { while ((token = strsep (&p, " "))) {
bool truefalse = true; bool truefalse = true;

View File

@ -173,7 +173,7 @@ static char **find_mounts (struct args *args)
for (o = optnames; flags && o->o_opt; o++) { for (o = optnames; flags && o->o_opt; o++) {
if (flags & o->o_opt) { if (flags & o->o_opt) {
if (! options) if (! options)
options = rc_xstrdup (o->o_name); options = strdup (o->o_name);
else { else {
char *tmp = NULL; char *tmp = NULL;
asprintf (&tmp, "%s,%s", options, o->o_name); 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) 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; int result;
char buffer[256]; char buffer[256];

View File

@ -54,7 +54,7 @@ char **env_filter (void)
if (! whitelist) if (! whitelist)
return (NULL); return (NULL);
if (rc_exists (PROFILE_ENV)) if (exists (PROFILE_ENV))
profile = rc_config_load (PROFILE_ENV); profile = rc_config_load (PROFILE_ENV);
STRLIST_FOREACH (whitelist, env_name, count) { STRLIST_FOREACH (whitelist, env_name, count) {
@ -66,7 +66,7 @@ char **env_filter (void)
if (! env_var && profile) { if (! env_var && profile) {
env_len = strlen (env_name) + strlen ("export ") + 1; 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); snprintf (p, env_len, "export %s", env_name);
env_var = rc_config_value (profile, p); env_var = rc_config_value (profile, p);
free (p); free (p);
@ -82,13 +82,13 @@ char **env_filter (void)
{ {
got_path = true; got_path = true;
env_len = strlen (env_name) + strlen (env_var) + pplen + 2; 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); 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 */ /* Now go through the env var and only add bits not in our PREFIX */
sep = env_var; sep = env_var;
while ((token = strsep (&sep, ":"))) { while ((token = strsep (&sep, ":"))) {
char *np = rc_xstrdup (PATH_PREFIX); char *np = strdup (PATH_PREFIX);
char *npp = np; char *npp = np;
char *tok = NULL; char *tok = NULL;
while ((tok = strsep (&npp, ":"))) while ((tok = strsep (&npp, ":")))
@ -101,7 +101,7 @@ char **env_filter (void)
*p++ = 0; *p++ = 0;
} else { } else {
env_len = strlen (env_name) + strlen (env_var) + 2; 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); 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. */ However, we do need a path, so use a default. */
if (! got_path) { if (! got_path) {
env_len = strlen ("PATH=") + strlen (PATH_PREFIX) + 2; 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); snprintf (p, env_len, "PATH=%s", PATH_PREFIX);
rc_strlist_add (&env, p); rc_strlist_add (&env, p);
free (p); free (p);
@ -178,7 +178,7 @@ char **env_config (void)
/* Don't trust environ for softlevel yet */ /* Don't trust environ for softlevel yet */
snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel); snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel);
if (rc_exists (buffer)) if (exists (buffer))
config = rc_config_load (buffer); config = rc_config_load (buffer);
else else
config = rc_config_load (RC_CONFIG); config = rc_config_load (RC_CONFIG);
@ -195,7 +195,7 @@ char **env_config (void)
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
} else { } else {
int len = strlen (line) + strlen (e) + 2; 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); snprintf (new, len, "%s=%s", line, e);
rc_strlist_add (&env, new); rc_strlist_add (&env, new);
free (new); free (new);
@ -205,14 +205,14 @@ char **env_config (void)
/* One char less to drop the trailing / */ /* One char less to drop the trailing / */
i = strlen ("RC_LIBDIR=") + strlen (RC_LIBDIR) + 1; 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); snprintf (line, i, "RC_LIBDIR=" RC_LIBDIR);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
/* One char less to drop the trailing / */ /* One char less to drop the trailing / */
i = strlen ("RC_SVCDIR=") + strlen (RC_SVCDIR) + 1; 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); snprintf (line, i, "RC_SVCDIR=" RC_SVCDIR);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -220,7 +220,7 @@ char **env_config (void)
rc_strlist_add (&env, "RC_BOOTLEVEL=" RC_LEVEL_BOOT); rc_strlist_add (&env, "RC_BOOTLEVEL=" RC_LEVEL_BOOT);
i = strlen ("RC_SOFTLEVEL=") + strlen (runlevel) + 1; 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); snprintf (line, i, "RC_SOFTLEVEL=%s", runlevel);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -232,7 +232,7 @@ char **env_config (void)
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
i += strlen ("RC_DEFAULTLEVEL=") + 2; i += strlen ("RC_DEFAULTLEVEL=") + 2;
line = rc_xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char *) * i);
snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer); snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -247,7 +247,7 @@ char **env_config (void)
We store this special system in RC_SYS so our scripts run fast */ We store this special system in RC_SYS so our scripts run fast */
memset (sys, 0, sizeof (sys)); memset (sys, 0, sizeof (sys));
if (rc_exists ("/proc/xen")) { if (exists ("/proc/xen")) {
if ((fp = fopen ("/proc/xen/capabilities", "r"))) { if ((fp = fopen ("/proc/xen/capabilities", "r"))) {
fclose (fp); fclose (fp);
if (file_regex ("/proc/xen/capabilities", "control_d")) if (file_regex ("/proc/xen/capabilities", "control_d"))
@ -265,7 +265,7 @@ char **env_config (void)
if (sys[0]) { if (sys[0]) {
i = strlen ("RC_SYS=") + strlen (sys) + 2; 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); snprintf (line, i, "RC_SYS=%s", sys);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -282,7 +282,7 @@ char **env_config (void)
if (! has_net_fs_list) { if (! has_net_fs_list) {
i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1; 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); snprintf (line, i, "RC_NET_FS_LIST=%s", RC_NET_FS_LIST_DEFAULT);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -292,7 +292,7 @@ char **env_config (void)
To save on calling uname, we store it in an environment variable */ To save on calling uname, we store it in an environment variable */
if (uname (&uts) == 0) { if (uname (&uts) == 0) {
i = strlen ("RC_UNAME=") + strlen (uts.sysname) + 2; 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); snprintf (line, i, "RC_UNAME=%s", uts.sysname);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);

View File

@ -43,7 +43,7 @@
#define ERRX fprintf (stderr, "out of memory\n"); exit (1) #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); void *value = malloc (size);
@ -53,7 +53,7 @@ static inline void *rc_xmalloc (size_t size)
ERRX; 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); void *value = realloc (ptr, size);
@ -63,7 +63,7 @@ static inline void *rc_xrealloc (void *ptr, size_t size)
ERRX; ERRX;
} }
static inline char *rc_xstrdup (const char *str) static inline char *xstrdup (const char *str)
{ {
char *value; char *value;
@ -80,7 +80,7 @@ static inline char *rc_xstrdup (const char *str)
#undef ERRX #undef ERRX
static inline bool rc_exists (const char *pathname) static inline bool exists (const char *pathname)
{ {
struct stat buf; struct stat buf;

View File

@ -85,13 +85,13 @@ void rc_plugin_load (void)
dlclose (h); dlclose (h);
} else { } else {
if (plugin) { if (plugin) {
plugin->next = rc_xmalloc (sizeof (plugin_t)); plugin->next = xmalloc (sizeof (plugin_t));
plugin = plugin->next; plugin = plugin->next;
} else } else
plugin = plugins = rc_xmalloc (sizeof (plugin_t)); plugin = plugins = xmalloc (sizeof (plugin_t));
memset (plugin, 0, 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->handle = h;
plugin->hook = fptr; plugin->hook = fptr;
} }

View File

@ -192,7 +192,7 @@ static int do_e (int argc, char **argv)
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
l += strlen (argv[i]) + 1; l += strlen (argv[i]) + 1;
message = rc_xmalloc (l); message = xmalloc (l);
p = message; p = message;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
@ -205,7 +205,7 @@ static int do_e (int argc, char **argv)
} }
if (message) if (message)
fmt = rc_xstrdup ("%s"); fmt = strdup ("%s");
if (strcmp (applet, "einfo") == 0) if (strcmp (applet, "einfo") == 0)
einfo (fmt, message); einfo (fmt, message);
@ -338,10 +338,10 @@ static int do_mark_service (int argc, char **argv)
strlen (svcname) + strlen (svcname) +
strlen (runscript_pid) + strlen (runscript_pid) +
4; 4;
mtime = rc_xmalloc (l); mtime = xmalloc (l);
snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
svcname, runscript_pid); svcname, runscript_pid);
if (rc_exists (mtime) && unlink (mtime) != 0) if (exists (mtime) && unlink (mtime) != 0)
eerror ("%s: unlink: %s", applet, strerror (errno)); eerror ("%s: unlink: %s", applet, strerror (errno));
free (mtime); free (mtime);
} }
@ -384,7 +384,7 @@ static char *proc_getent (const char *ent)
char *value = NULL; char *value = NULL;
int i; int i;
if (! rc_exists ("/proc/cmdline")) if (! exists ("/proc/cmdline"))
return (NULL); return (NULL);
if (! (fp = fopen ("/proc/cmdline", "r"))) { 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 /* Now save our terminal settings. We need to restore them at exit as we
will be changing it for non-blocking reads for Interactive */ will be changing it for non-blocking reads for Interactive */
if (! termios_orig) { if (! termios_orig) {
termios_orig = rc_xmalloc (sizeof (struct termios)); termios_orig = xmalloc (sizeof (struct termios));
tcgetattr (fd, termios_orig); 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_SINGLE) == 0 ||
strcmp (level, RC_LEVEL_SYSINIT) == 0) strcmp (level, RC_LEVEL_SYSINIT) == 0)
{ {
if (rc_exists (RC_KSOFTLEVEL) && if (exists (RC_KSOFTLEVEL) &&
unlink (RC_KSOFTLEVEL) != 0) unlink (RC_KSOFTLEVEL) != 0)
eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno));
return; return;
@ -567,7 +567,7 @@ static int get_ksoftlevel (char *buffer, int buffer_len)
FILE *fp; FILE *fp;
int i = 0; int i = 0;
if (! rc_exists (RC_KSOFTLEVEL)) if (! exists (RC_KSOFTLEVEL))
return (0); return (0);
if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) {
@ -597,10 +597,10 @@ static void add_pid (pid_t pid)
if (sp) { if (sp) {
while (sp->next) while (sp->next)
sp = sp->next; sp = sp->next;
sp->next = rc_xmalloc (sizeof (pidlist_t)); sp->next = xmalloc (sizeof (pidlist_t));
sp = sp->next; sp = sp->next;
} else } else
sp = service_pids = rc_xmalloc (sizeof (pidlist_t)); sp = service_pids = xmalloc (sizeof (pidlist_t));
memset (sp, 0, sizeof (pidlist_t)); memset (sp, 0, sizeof (pidlist_t));
sp->pid = pid; sp->pid = pid;
} }
@ -757,7 +757,7 @@ int main (int argc, char **argv)
atexit (cleanup); atexit (cleanup);
if (argv[0]) if (argv[0])
applet = rc_xstrdup (basename (argv[0])); applet = strdup (basename (argv[0]));
if (! applet) if (! applet)
eerrorx ("arguments required"); eerrorx ("arguments required");
@ -858,7 +858,7 @@ int main (int argc, char **argv)
some kernels bitch about this according to the environ man pages some kernels bitch about this according to the environ man pages
so we walk though environ and call unsetenv for each value. */ so we walk though environ and call unsetenv for each value. */
while (environ[0]) { while (environ[0]) {
tmp = rc_xstrdup (environ[0]); tmp = strdup (environ[0]);
p = tmp; p = tmp;
var = strsep (&p, "="); var = strsep (&p, "=");
unsetenv (var); unsetenv (var);
@ -898,7 +898,7 @@ int main (int argc, char **argv)
snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); snprintf (pidstr, sizeof (pidstr), "%d", getpid ());
setenv ("RC_PID", pidstr, 1); setenv ("RC_PID", pidstr, 1);
interactive = rc_exists (INTERACTIVE); interactive = exists (INTERACTIVE);
rc_plugin_load (); rc_plugin_load ();
/* Load current softlevel */ /* Load current softlevel */
@ -925,7 +925,7 @@ int main (int argc, char **argv)
/* exec init-early.sh if it exists /* exec init-early.sh if it exists
* This should just setup the console to use the correct * This should just setup the console to use the correct
* font. Maybe it should setup the keyboard too? */ * font. Maybe it should setup the keyboard too? */
if (rc_exists (INITEARLYSH)) if (exists (INITEARLYSH))
run_script (INITEARLYSH); run_script (INITEARLYSH);
uname (&uts); uname (&uts);
@ -1104,7 +1104,7 @@ int main (int argc, char **argv)
if ((dp = opendir ("/dev/net"))) { if ((dp = opendir ("/dev/net"))) {
while ((d = readdir (dp))) { while ((d = readdir (dp))) {
i = (strlen ("net.") + strlen (d->d_name) + 1); 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); snprintf (tmp, i, "net.%s", d->d_name);
if (rc_service_exists (tmp) && if (rc_service_exists (tmp) &&
rc_service_plugable (tmp)) rc_service_plugable (tmp))
@ -1125,7 +1125,7 @@ int main (int argc, char **argv)
char *p = d->d_name + 3; char *p = d->d_name + 3;
if (p && isdigit (*p)) { if (p && isdigit (*p)) {
i = (strlen ("moused.") + strlen (d->d_name) + 1); 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); snprintf (tmp, i, "moused.%s", d->d_name);
if (rc_service_exists (tmp) && rc_service_plugable (tmp)) if (rc_service_exists (tmp) && rc_service_plugable (tmp))
rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED);
@ -1245,18 +1245,18 @@ int main (int argc, char **argv)
continue; continue;
len = strlen (service) + strlen (runlevel) + 2; len = strlen (service) + strlen (runlevel) + 2;
tmp = rc_xmalloc (sizeof (char *) * len); tmp = xmalloc (sizeof (char *) * len);
snprintf (tmp, len, "%s.%s", service, runlevel); snprintf (tmp, len, "%s.%s", service, runlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = rc_exists (conf); found = exists (conf);
CHAR_FREE (conf); CHAR_FREE (conf);
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (! found) { if (! found) {
len = strlen (service) + strlen (newlevel) + 2; len = strlen (service) + strlen (newlevel) + 2;
tmp = rc_xmalloc (sizeof (char *) * len); tmp = xmalloc (sizeof (char *) * len);
snprintf (tmp, len, "%s.%s", service, newlevel); snprintf (tmp, len, "%s.%s", service, newlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = rc_exists (conf); found = exists (conf);
CHAR_FREE (conf); CHAR_FREE (conf);
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (!found) if (!found)
@ -1310,7 +1310,7 @@ int main (int argc, char **argv)
if (newlevel) { if (newlevel) {
rc_runlevel_set (newlevel); rc_runlevel_set (newlevel);
free (runlevel); free (runlevel);
runlevel = rc_xstrdup (newlevel); runlevel = strdup (newlevel);
setenv ("RC_SOFTLEVEL", runlevel, 1); setenv ("RC_SOFTLEVEL", runlevel, 1);
} }
@ -1325,7 +1325,7 @@ int main (int argc, char **argv)
/* Single user is done now */ /* Single user is done now */
if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) {
if (rc_exists (INTERACTIVE)) if (exists (INTERACTIVE))
unlink (INTERACTIVE); unlink (INTERACTIVE);
sulogin (false); sulogin (false);
} }
@ -1423,7 +1423,7 @@ interactive_option:
if (interactive && strcmp (runlevel, bootlevel) == 0) if (interactive && strcmp (runlevel, bootlevel) == 0)
mark_interactive (); mark_interactive ();
else { else {
if (rc_exists (INTERACTIVE)) if (exists (INTERACTIVE))
unlink (INTERACTIVE); unlink (INTERACTIVE);
} }

View File

@ -83,7 +83,7 @@ static void setup_selinux (int argc, char **argv)
{ {
void *lib_handle = NULL; void *lib_handle = NULL;
if (! rc_exists (SELINUX_LIB)) if (! exists (SELINUX_LIB))
return; return;
lib_handle = dlopen (SELINUX_LIB, RTLD_NOW | RTLD_GLOBAL); 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 **)) selinux_run_init_new = (void (*)(int, char **))
dlfunc (lib_handle, "selinux_runscript2"); 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) if (selinux_run_init_new)
selinux_run_init_new (argc, argv); selinux_run_init_new (argc, argv);
else if (selinux_run_init_old) else if (selinux_run_init_old)
@ -186,7 +186,7 @@ static bool in_control ()
if (sighup) if (sighup)
return (false); return (false);
if (! mtime_test || ! rc_exists (mtime_test)) if (! mtime_test || ! exists (mtime_test))
return (false); return (false);
if (rc_service_state (applet) & RC_SERVICE_STOPPED) if (rc_service_state (applet) & RC_SERVICE_STOPPED)
@ -197,7 +197,7 @@ static bool in_control ()
while (tests[i]) { while (tests[i]) {
path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL); path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL);
if (rc_exists (path)) { if (exists (path)) {
time_t m = get_mtime (path, false); time_t m = get_mtime (path, false);
if (mtime < m && m != 0) { if (mtime < m && m != 0) {
free (path); free (path);
@ -214,7 +214,7 @@ static bool in_control ()
static void uncoldplug () static void uncoldplug ()
{ {
char *cold = rc_strcatpaths (RC_SVCDIR, "coldplugged", applet, (char *) NULL); 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)); eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno));
free (cold); free (cold);
} }
@ -284,7 +284,7 @@ static void cleanup (void)
else else
rc_service_mark (applet, RC_SERVICE_STARTED); rc_service_mark (applet, RC_SERVICE_STARTED);
} }
if (exclusive && rc_exists (exclusive)) if (exclusive && exists (exclusive))
unlink (exclusive); unlink (exclusive);
} }
@ -401,7 +401,7 @@ static bool svc_exec (const char *arg1, const char *arg2)
close (slave_tty); 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, execl (RC_SVCDIR "/runscript.sh", service, service, arg1, arg2,
(char *) NULL); (char *) NULL);
eerror ("%s: exec `" RC_SVCDIR "/runscript.sh': %s", 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); path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL);
i = strlen (path) + 16; 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 ()); snprintf (mtime_test, i, "%s.%d", path, getpid ());
free (path); free (path);
if (rc_exists (mtime_test) && unlink (mtime_test) != 0) { if (exists (mtime_test) && unlink (mtime_test) != 0) {
eerror ("%s: unlink `%s': %s", eerror ("%s: unlink `%s': %s",
applet, mtime_test, strerror (errno)); applet, mtime_test, strerror (errno));
free (mtime_test); free (mtime_test);
@ -711,7 +711,7 @@ static void svc_start (bool deps)
} }
len += 5; len += 5;
tmp = rc_xmalloc (sizeof (char *) * len); tmp = xmalloc (sizeof (char *) * len);
p = tmp; p = tmp;
STRLIST_FOREACH (tmplist, svc, i) { STRLIST_FOREACH (tmplist, svc, i) {
if (i > 1) { if (i > 1) {
@ -1009,7 +1009,7 @@ int runscript (int argc, char **argv)
/* We need the full path to the service */ /* We need the full path to the service */
if (*argv[1] == '/') if (*argv[1] == '/')
service = rc_xstrdup (argv[1]); service = strdup (argv[1]);
else { else {
char pwd[PATH_MAX]; char pwd[PATH_MAX];
if (! getcwd (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); service = rc_strcatpaths (pwd, argv[1], (char *) NULL);
} }
applet = rc_xstrdup (basename (service)); applet = strdup (basename (service));
atexit (cleanup); atexit (cleanup);
/* Change dir to / to ensure all init scripts don't use stuff in pwd */ /* 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__ #ifdef __linux__
/* coldplug events can trigger init scripts, but we don't want to run them /* 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 */ 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); eerror ("%s: cannot run until sysvinit completes", applet);
if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST) if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST)
eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno)); eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno));
@ -1043,7 +1043,7 @@ int runscript (int argc, char **argv)
} }
#endif #endif
if ((softlevel = rc_xstrdup (getenv ("RC_SOFTLEVEL"))) == NULL) { if ((softlevel = strdup (getenv ("RC_SOFTLEVEL"))) == NULL) {
/* Ensure our environment is pure /* Ensure our environment is pure
Also, add our configuration to it */ Also, add our configuration to it */
tmplist = env_config (); tmplist = env_config ();
@ -1066,7 +1066,7 @@ int runscript (int argc, char **argv)
some kernels bitch about this according to the environ man pages some kernels bitch about this according to the environ man pages
so we walk though environ and call unsetenv for each value. */ so we walk though environ and call unsetenv for each value. */
while (environ[0]) { while (environ[0]) {
tmp = rc_xstrdup (environ[0]); tmp = strdup (environ[0]);
p = tmp; p = tmp;
var = strsep (&p, "="); var = strsep (&p, "=");
unsetenv (var); unsetenv (var);
@ -1106,7 +1106,7 @@ int runscript (int argc, char **argv)
} }
/* Make our prefix string */ /* Make our prefix string */
prefix = rc_xmalloc (sizeof (char *) * l); prefix = xmalloc (sizeof (char *) * l);
ll = strlen (applet); ll = strlen (applet);
memcpy (prefix, applet, ll); memcpy (prefix, applet, ll);
memset (prefix + ll, ' ', l - ll); memset (prefix + ll, ' ', l - ll);
@ -1144,7 +1144,7 @@ int runscript (int argc, char **argv)
that is being called and not any dependents */ that is being called and not any dependents */
if (getenv ("IN_BACKGROUND")) { if (getenv ("IN_BACKGROUND")) {
in_background = rc_env_bool ("IN_BACKGROUND"); in_background = rc_env_bool ("IN_BACKGROUND");
ibsave = rc_xstrdup (getenv ("IN_BACKGROUND")); ibsave = strdup (getenv ("IN_BACKGROUND"));
unsetenv ("IN_BACKGROUND"); unsetenv ("IN_BACKGROUND");
} }

View File

@ -191,13 +191,13 @@ static void parse_schedule (const char *string, int default_signal)
if (schedule) if (schedule)
free_schedulelist (&schedule); free_schedulelist (&schedule);
schedule = rc_xmalloc (sizeof (schedulelist_t)); schedule = xmalloc (sizeof (schedulelist_t));
schedule->gotolist = NULL; schedule->gotolist = NULL;
if (count == 0) { if (count == 0) {
schedule->type = schedule_signal; schedule->type = schedule_signal;
schedule->value = default_signal; schedule->value = default_signal;
schedule->next = rc_xmalloc (sizeof (schedulelist_t)); schedule->next = xmalloc (sizeof (schedulelist_t));
next = schedule->next; next = schedule->next;
next->type = schedule_timeout; next->type = schedule_timeout;
next->gotolist = NULL; next->gotolist = NULL;
@ -237,14 +237,14 @@ static void parse_schedule (const char *string, int default_signal)
} }
if (string) { if (string) {
next->next = rc_xmalloc (sizeof (schedulelist_t)); next->next = xmalloc (sizeof (schedulelist_t));
next = next->next; next = next->next;
next->gotolist = NULL; next->gotolist = NULL;
} }
} }
if (repeatat) { if (repeatat) {
next->next = rc_xmalloc (sizeof (schedulelist_t)); next->next = xmalloc (sizeof (schedulelist_t));
next = next->next; next = next->next;
next->type = schedule_goto; next->type = schedule_goto;
next->value = 0; next->value = 0;
@ -593,7 +593,7 @@ int start_stop_daemon (int argc, char **argv)
char *cu = strsep (&p, ":"); char *cu = strsep (&p, ":");
struct passwd *pw = NULL; struct passwd *pw = NULL;
changeuser = rc_xstrdup (cu); changeuser = strdup (cu);
if (sscanf (cu, "%d", &tid) != 1) if (sscanf (cu, "%d", &tid) != 1)
pw = getpwnam (cu); pw = getpwnam (cu);
else else
@ -728,7 +728,7 @@ int start_stop_daemon (int argc, char **argv)
tmp = rc_strcatpaths (ch_root, exec, (char *) NULL); tmp = rc_strcatpaths (ch_root, exec, (char *) NULL);
else else
tmp = exec; tmp = exec;
if (! rc_exists (tmp)) { if (! exists (tmp)) {
eerror ("%s: %s does not exist", applet, tmp); eerror ("%s: %s does not exist", applet, tmp);
if (ch_root) if (ch_root)
free (tmp); free (tmp);
@ -754,7 +754,7 @@ int start_stop_daemon (int argc, char **argv)
if (result < 1) if (result < 1)
exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
if (pidfile && rc_exists (pidfile)) if (pidfile && exists (pidfile))
unlink (pidfile); unlink (pidfile);
if (svcname) if (svcname)
@ -886,7 +886,7 @@ int start_stop_daemon (int argc, char **argv)
/* For the path, remove the rcscript bin dir from it */ /* For the path, remove the rcscript bin dir from it */
if (strncmp (env, "PATH=", 5) == 0) { if (strncmp (env, "PATH=", 5) == 0) {
char *path = rc_xstrdup (env); char *path = strdup (env);
char *newpath = NULL; char *newpath = NULL;
char *p = path; char *p = path;
char *token; char *token;