mirror of
https://github.com/troglobit/finit.git
synced 2026-10-24 11:54:36 +00:00
Fix GCC 9 string trunction warning
- Increase size of resulting path buffer, unlikely a real problem - Check return value from snprintf() to detect errors and truncation - Add logit() function wrapper to initctl, maps to _e()/_d()/_pe() Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
744719219e
commit
8d271ac5b8
5 files changed
+22
-6
No files matched your search
+2
-2
@@ -50,11 +50,11 @@ const char *condstr(enum cond_state s)
|
|||||||
const char *cond_path(const char *name)
|
const char *cond_path(const char *name)
|
||||||
{
|
{
|
||||||
char tmp[MAX_ARG_LEN];
|
char tmp[MAX_ARG_LEN];
|
||||||
static char file[MAX_ARG_LEN];
|
static char path[256];
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), COND_PATH "/%s", name);
|
snprintf(tmp, sizeof(tmp), COND_PATH "/%s", name);
|
||||||
|
|
||||||
return pid_runpath(tmp, file, sizeof(file));
|
return pid_runpath(tmp, path, sizeof(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int cond_get_gen(const char *file)
|
unsigned int cond_get_gen(const char *file)
|
||||||
|
|||||||
@@ -688,6 +688,19 @@ int main(int argc, char *argv[])
|
|||||||
return usage(1);
|
return usage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void logit(int prio, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
if (prio <= LOG_ERR)
|
||||||
|
verrx(1, fmt, ap);
|
||||||
|
else
|
||||||
|
vwarnx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ char *pid_get_name(pid_t pid, char *name, size_t len)
|
|||||||
char *pid_file(svc_t *svc)
|
char *pid_file(svc_t *svc)
|
||||||
{
|
{
|
||||||
char fn[MAX_ARG_LEN];
|
char fn[MAX_ARG_LEN];
|
||||||
static char path[MAX_ARG_LEN];
|
static char path[256];
|
||||||
|
|
||||||
if (svc->pidfile[0]) {
|
if (svc->pidfile[0]) {
|
||||||
if (svc->pidfile[0] == '!')
|
if (svc->pidfile[0] == '!')
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ int pid_file_parse (svc_t *svc, char *arg);
|
|||||||
*/
|
*/
|
||||||
static inline char *pid_runpath(const char *file, char *path, size_t len)
|
static inline char *pid_runpath(const char *file, char *path, size_t len)
|
||||||
{
|
{
|
||||||
static int unknown = 1;
|
|
||||||
static char *prefix = "/var/run";
|
static char *prefix = "/var/run";
|
||||||
|
static int unknown = 1;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (unknown) {
|
if (unknown) {
|
||||||
if (fisdir("/run"))
|
if (fisdir("/run"))
|
||||||
@@ -60,7 +61,9 @@ static inline char *pid_runpath(const char *file, char *path, size_t len)
|
|||||||
else if (!strncmp(file, "/run/", 5))
|
else if (!strncmp(file, "/run/", 5))
|
||||||
file += 5;
|
file += 5;
|
||||||
|
|
||||||
snprintf(path, len, "%s/%s", prefix, file);
|
rc = snprintf(path, len, "%s/%s", prefix, file);
|
||||||
|
if (rc < 0 || (size_t)rc >= len)
|
||||||
|
_e("File path '%s' truncated, should end with '%s'", path, file);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ typedef struct svc {
|
|||||||
|
|
||||||
/* Service details */
|
/* Service details */
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char pidfile[MAX_ARG_LEN];
|
char pidfile[256];
|
||||||
long start_time; /* Start time, as seconds since boot, from sysinfo() */
|
long start_time; /* Start time, as seconds since boot, from sysinfo() */
|
||||||
const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */
|
const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */
|
||||||
svc_type_t type; /* Service, run, task, inetd, ... */
|
svc_type_t type; /* Service, run, task, inetd, ... */
|
||||||
|
|||||||
Reference in new issue
Block a user