strdup -> rc_xstrdup
This commit is contained in:
parent
3ed60d5202
commit
2569e85579
@ -131,7 +131,7 @@ int main (int argc, char **argv)
|
|||||||
"%s%s", isspecial_spaced ? " " : ":", value);
|
"%s%s", isspecial_spaced ? " " : ":", value);
|
||||||
} else {
|
} else {
|
||||||
free (envs[k - 1]);
|
free (envs[k - 1]);
|
||||||
envs[k - 1] = strdup (entry);
|
envs[k - 1] = rc_xstrdup (entry);
|
||||||
}
|
}
|
||||||
replaced = true;
|
replaced = true;
|
||||||
}
|
}
|
||||||
|
@ -305,21 +305,21 @@ void rc_set_service_daemon (const char *service, const char *exec,
|
|||||||
mexec = rc_xmalloc (sizeof (char *) * i);
|
mexec = rc_xmalloc (sizeof (char *) * i);
|
||||||
snprintf (mexec, i, "exec=%s", exec);
|
snprintf (mexec, i, "exec=%s", exec);
|
||||||
} else
|
} else
|
||||||
mexec = strdup ("exec=");
|
mexec = rc_xstrdup ("exec=");
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
i = strlen (name) + 6;
|
i = strlen (name) + 6;
|
||||||
mname = rc_xmalloc (sizeof (char *) * i);
|
mname = rc_xmalloc (sizeof (char *) * i);
|
||||||
snprintf (mname, i, "name=%s", name);
|
snprintf (mname, i, "name=%s", name);
|
||||||
} else
|
} else
|
||||||
mname = strdup ("name=");
|
mname = rc_xstrdup ("name=");
|
||||||
|
|
||||||
if (pidfile) {
|
if (pidfile) {
|
||||||
i = strlen (pidfile) + 9;
|
i = strlen (pidfile) + 9;
|
||||||
mpidfile = rc_xmalloc (sizeof (char *) * i);
|
mpidfile = rc_xmalloc (sizeof (char *) * i);
|
||||||
snprintf (mpidfile, i, "pidfile=%s", pidfile);
|
snprintf (mpidfile, i, "pidfile=%s", pidfile);
|
||||||
} else
|
} else
|
||||||
mpidfile = strdup ("pidfile=");
|
mpidfile = rc_xstrdup ("pidfile=");
|
||||||
|
|
||||||
/* Regardless, erase any existing daemon info */
|
/* Regardless, erase any existing daemon info */
|
||||||
if (rc_is_dir (dirpath)) {
|
if (rc_is_dir (dirpath)) {
|
||||||
@ -479,15 +479,15 @@ 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 = strdup (p);
|
exec = rc_xstrdup (p);
|
||||||
} else if (strcmp (token, "name") == 0) {
|
} else if (strcmp (token, "name") == 0) {
|
||||||
if (name)
|
if (name)
|
||||||
free (name);
|
free (name);
|
||||||
name = strdup (p);
|
name = rc_xstrdup (p);
|
||||||
} else if (strcmp (token, "pidfile") == 0) {
|
} else if (strcmp (token, "pidfile") == 0) {
|
||||||
if (pidfile)
|
if (pidfile)
|
||||||
free (pidfile);
|
free (pidfile);
|
||||||
pidfile = strdup (p);
|
pidfile = rc_xstrdup (p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
@ -109,7 +109,7 @@ rc_depinfo_t *rc_load_deptree (void)
|
|||||||
depinfo = depinfo->next;
|
depinfo = depinfo->next;
|
||||||
}
|
}
|
||||||
memset (depinfo, 0, sizeof (rc_depinfo_t));
|
memset (depinfo, 0, sizeof (rc_depinfo_t));
|
||||||
depinfo->service = strdup (e);
|
depinfo->service = rc_xstrdup (e);
|
||||||
deptype = NULL;
|
deptype = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ rc_depinfo_t *rc_load_deptree (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! deptype->type)
|
if (! deptype->type)
|
||||||
deptype->type = strdup (type);
|
deptype->type = rc_xstrdup (type);
|
||||||
|
|
||||||
deptype->services = rc_strlist_addsort (deptype->services, e);
|
deptype->services = rc_strlist_addsort (deptype->services, e);
|
||||||
}
|
}
|
||||||
@ -661,7 +661,7 @@ int rc_update_deptree (bool force)
|
|||||||
depinfo = last_depinfo->next;
|
depinfo = last_depinfo->next;
|
||||||
}
|
}
|
||||||
memset (depinfo, 0, sizeof (rc_depinfo_t));
|
memset (depinfo, 0, sizeof (rc_depinfo_t));
|
||||||
depinfo->service = strdup (service);
|
depinfo->service = rc_xstrdup (service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We may not have any depends */
|
/* We may not have any depends */
|
||||||
@ -689,7 +689,7 @@ int rc_update_deptree (bool force)
|
|||||||
deptype = last_deptype->next;
|
deptype = last_deptype->next;
|
||||||
}
|
}
|
||||||
memset (deptype, 0, sizeof (rc_deptype_t));
|
memset (deptype, 0, sizeof (rc_deptype_t));
|
||||||
deptype->type = strdup (type);
|
deptype->type = rc_xstrdup (type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now add each depend to our type.
|
/* Now add each depend to our type.
|
||||||
@ -730,7 +730,7 @@ int rc_update_deptree (bool force)
|
|||||||
last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
|
last_depinfo->next = rc_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 = strdup (service);
|
di->service = rc_xstrdup (service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -779,7 +779,7 @@ int rc_update_deptree (bool force)
|
|||||||
dt = last_deptype->next;
|
dt = last_deptype->next;
|
||||||
}
|
}
|
||||||
memset (dt, 0, sizeof (rc_deptype_t));
|
memset (dt, 0, sizeof (rc_deptype_t));
|
||||||
dt->type = strdup (deppairs[i].addto);
|
dt->type = rc_xstrdup (deppairs[i].addto);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_added = false;
|
already_added = false;
|
||||||
|
@ -59,7 +59,7 @@ char *rc_xstrdup (const char *str)
|
|||||||
if (! str)
|
if (! str)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
value = strdup (str);
|
value = rc_xstrdup (str);
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
return (value);
|
return (value);
|
||||||
@ -490,7 +490,7 @@ char **rc_filter_env (void)
|
|||||||
/* 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 = strdup (PATH_PREFIX);
|
char *np = rc_xstrdup (PATH_PREFIX);
|
||||||
char *npp = np;
|
char *npp = np;
|
||||||
char *tok = NULL;
|
char *tok = NULL;
|
||||||
while ((tok = strsep (&npp, ":")))
|
while ((tok = strsep (&npp, ":")))
|
||||||
|
@ -136,7 +136,7 @@ char *rc_resolve_service (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 strdup (buffer);
|
return (rc_xstrdup (buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf (buffer, sizeof (buffer), RC_INITDIR "%s", service);
|
snprintf (buffer, sizeof (buffer), RC_INITDIR "%s", service);
|
||||||
@ -467,7 +467,7 @@ static pid_t _exec_service (const char *service, const char *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((pid = fork ()) == 0) {
|
if ((pid = fork ()) == 0) {
|
||||||
char *myarg = strdup (arg);
|
char *myarg = rc_xstrdup (arg);
|
||||||
int e = 0;
|
int e = 0;
|
||||||
execl (file, file, myarg, (char *) NULL);
|
execl (file, file, myarg, (char *) NULL);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
@ -77,7 +77,7 @@ void rc_plugin_load (void)
|
|||||||
plugin = plugins = rc_xmalloc (sizeof (plugin_t));
|
plugin = plugins = rc_xmalloc (sizeof (plugin_t));
|
||||||
|
|
||||||
memset (plugin, 0, sizeof (plugin_t));
|
memset (plugin, 0, sizeof (plugin_t));
|
||||||
plugin->name = strdup (file);
|
plugin->name = rc_xstrdup (file);
|
||||||
plugin->handle = h;
|
plugin->handle = h;
|
||||||
plugin->hook = f;
|
plugin->hook = f;
|
||||||
}
|
}
|
||||||
|
4
src/rc.c
4
src/rc.c
@ -161,7 +161,7 @@ static int do_e (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message)
|
if (message)
|
||||||
fmt = strdup ("%s");
|
fmt = rc_xstrdup ("%s");
|
||||||
|
|
||||||
if (strcmp (applet, "einfo") == 0)
|
if (strcmp (applet, "einfo") == 0)
|
||||||
einfo (fmt, message);
|
einfo (fmt, message);
|
||||||
@ -482,7 +482,7 @@ int main (int argc, char **argv)
|
|||||||
char ksoftbuffer [PATH_MAX];
|
char ksoftbuffer [PATH_MAX];
|
||||||
|
|
||||||
if (argv[0])
|
if (argv[0])
|
||||||
applet = strdup (basename (argv[0]));
|
applet = rc_xstrdup (basename (argv[0]));
|
||||||
|
|
||||||
if (! applet)
|
if (! applet)
|
||||||
eerrorx ("arguments required");
|
eerrorx ("arguments required");
|
||||||
|
@ -15,16 +15,13 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifndef __linux__
|
|
||||||
#include <libgen.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "einfo.h"
|
#include "einfo.h"
|
||||||
#include "rc.h"
|
#include "rc.h"
|
||||||
#include "rc-misc.h"
|
#include "rc-misc.h"
|
||||||
@ -802,7 +799,7 @@ static void svc_restart (const char *service, bool deps)
|
|||||||
if (inactive) {
|
if (inactive) {
|
||||||
rc_schedule_start_service (service, svc);
|
rc_schedule_start_service (service, svc);
|
||||||
ewarn ("WARNING: %s is scheduled to started when %s has started",
|
ewarn ("WARNING: %s is scheduled to started when %s has started",
|
||||||
svc, basename (service));
|
svc, applet);
|
||||||
} else
|
} else
|
||||||
rc_start_service (svc);
|
rc_start_service (svc);
|
||||||
}
|
}
|
||||||
@ -821,11 +818,11 @@ static struct option longopts[] = {
|
|||||||
{ "help", 0, NULL, 'h'},
|
{ "help", 0, NULL, 'h'},
|
||||||
{ NULL, 0, NULL, 0}
|
{ NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
#include "_usage.c"
|
// #include "_usage.c"
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *service = argv[1];
|
char *service = argv[1];
|
||||||
int i;
|
int i;
|
||||||
bool deps = true;
|
bool deps = true;
|
||||||
bool doneone = false;
|
bool doneone = false;
|
||||||
@ -840,7 +837,7 @@ int main (int argc, char **argv)
|
|||||||
applet, strerror (errno));
|
applet, strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
applet = strdup (basename (service));
|
applet = rc_xstrdup (basename (service));
|
||||||
atexit (cleanup);
|
atexit (cleanup);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@ -956,7 +953,7 @@ int main (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_is_env ("IN_BACKGROUND", "true");
|
in_background = rc_is_env ("IN_BACKGROUND", "true");
|
||||||
ibsave = strdup (getenv ("IN_BACKGROUND"));
|
ibsave = rc_xstrdup (getenv ("IN_BACKGROUND"));
|
||||||
unsetenv ("IN_BACKGROUND");
|
unsetenv ("IN_BACKGROUND");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ int main (int argc, char **argv)
|
|||||||
char *cu = strsep (&p, ":");
|
char *cu = strsep (&p, ":");
|
||||||
struct passwd *pw = NULL;
|
struct passwd *pw = NULL;
|
||||||
|
|
||||||
changeuser = strdup (cu);
|
changeuser = rc_xstrdup (cu);
|
||||||
if (sscanf (cu, "%d", &tid) != 1)
|
if (sscanf (cu, "%d", &tid) != 1)
|
||||||
pw = getpwnam (cu);
|
pw = getpwnam (cu);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user