openrc: convert snprintf calls to xasprintf
This commit is contained in:
parent
e14edd765f
commit
64354831da
40
src/rc/rc.c
40
src/rc/rc.c
@ -101,7 +101,6 @@ clean_failed(void)
|
|||||||
{
|
{
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
size_t l;
|
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
/* Clean the failed services state dir now */
|
/* Clean the failed services state dir now */
|
||||||
@ -112,16 +111,11 @@ clean_failed(void)
|
|||||||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
|
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
l = strlen(RC_SVCDIR "/failed/") +
|
xasprintf(&path, RC_SVCDIR "/failed/%s", d->d_name);
|
||||||
strlen(d->d_name) + 1;
|
if (unlink(path))
|
||||||
path = xmalloc(sizeof(char) * l);
|
eerror("%s: unlink `%s': %s",
|
||||||
snprintf(path, l, RC_SVCDIR "/failed/%s", d->d_name);
|
applet, path, strerror(errno));
|
||||||
if (path) {
|
free(path);
|
||||||
if (unlink(path))
|
|
||||||
eerror("%s: unlink `%s': %s",
|
|
||||||
applet, path, strerror(errno));
|
|
||||||
free(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
}
|
}
|
||||||
@ -391,7 +385,7 @@ static void
|
|||||||
handle_signal(int sig)
|
handle_signal(int sig)
|
||||||
{
|
{
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
char signame[10] = { '\0' };
|
char *signame = NULL;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
RC_PID *pi;
|
RC_PID *pi;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@ -422,16 +416,16 @@ handle_signal(int sig)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
if (!signame[0])
|
if (!signame)
|
||||||
snprintf(signame, sizeof(signame), "SIGINT");
|
xasprintf(&signame, "SIGINT");
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
if (!signame[0])
|
if (!signame)
|
||||||
snprintf(signame, sizeof(signame), "SIGTERM");
|
xasprintf(&signame, "SIGTERM");
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case SIGQUIT:
|
case SIGQUIT:
|
||||||
if (!signame[0])
|
if (!signame)
|
||||||
snprintf(signame, sizeof(signame), "SIGQUIT");
|
xasprintf(&signame, "SIGQUIT");
|
||||||
eerrorx("%s: caught %s, aborting", applet, signame);
|
eerrorx("%s: caught %s, aborting", applet, signame);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
@ -512,14 +506,11 @@ runlevel_config(const char *service, const char *level)
|
|||||||
{
|
{
|
||||||
char *init = rc_service_resolve(service);
|
char *init = rc_service_resolve(service);
|
||||||
char *conf, *dir;
|
char *conf, *dir;
|
||||||
size_t l;
|
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
dir = dirname(init);
|
dir = dirname(init);
|
||||||
dir = dirname(init);
|
dir = dirname(init);
|
||||||
l = strlen(dir) + strlen(level) + strlen(service) + 10;
|
xasprintf(&conf, "%s/conf.d/%s.%s", dir, service, level);
|
||||||
conf = xmalloc(sizeof(char) * l);
|
|
||||||
snprintf(conf, l, "%s/conf.d/%s.%s", dir, service, level);
|
|
||||||
retval = exists(conf);
|
retval = exists(conf);
|
||||||
free(conf);
|
free(conf);
|
||||||
free(init);
|
free(init);
|
||||||
@ -744,7 +735,7 @@ int main(int argc, char **argv)
|
|||||||
bool going_down = false;
|
bool going_down = false;
|
||||||
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
|
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
|
||||||
char *krunlevel = NULL;
|
char *krunlevel = NULL;
|
||||||
char pidstr[10];
|
char *pidstr = NULL;
|
||||||
int opt;
|
int opt;
|
||||||
bool parallel;
|
bool parallel;
|
||||||
int regen = 0;
|
int regen = 0;
|
||||||
@ -844,8 +835,9 @@ int main(int argc, char **argv)
|
|||||||
setenv("EINFO_LOG", "openrc", 1);
|
setenv("EINFO_LOG", "openrc", 1);
|
||||||
|
|
||||||
/* Export our PID */
|
/* Export our PID */
|
||||||
snprintf(pidstr, sizeof(pidstr), "%d", getpid());
|
xasprintf(&pidstr, "%d", getpid());
|
||||||
setenv("RC_PID", pidstr, 1);
|
setenv("RC_PID", pidstr, 1);
|
||||||
|
free(pidstr);
|
||||||
|
|
||||||
/* Create a list of all services which should be started for the new or
|
/* Create a list of all services which should be started for the new or
|
||||||
* current runlevel including those in boot, sysinit and hotplugged
|
* current runlevel including those in boot, sysinit and hotplugged
|
||||||
|
Loading…
x
Reference in New Issue
Block a user