mirror of
https://github.com/troglobit/finit.git
synced 2026-10-28 12:30:44 +00:00
Refactor, add new helper fn paste() to concat directory compoents
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
6f06c432ec
commit
a1f79e263a
5 files changed
+19
-8
No files matched your search
+3
-3
@@ -67,8 +67,8 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
|
|||||||
char fn[PATH_MAX];
|
char fn[PATH_MAX];
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
_d("Got dir: %s, name: %s, mask: %08x", dir, name, mask);
|
paste(fn, sizeof(fn), dir, name);
|
||||||
snprintf(fn, sizeof(fn), "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
|
_d("path: %s, mask: %08x", fn, mask);
|
||||||
|
|
||||||
if (fnmatch("*\\.pid", fn, 0) && fnmatch("*/pid", fn, 0))
|
if (fnmatch("*\\.pid", fn, 0) && fnmatch("*/pid", fn, 0))
|
||||||
return;
|
return;
|
||||||
@@ -131,7 +131,7 @@ static void pidfile_handle_dir(struct iwatch *iw, char *dir, char *name, int mas
|
|||||||
char path[strlen(dir) + strlen(name) + 2];
|
char path[strlen(dir) + strlen(name) + 2];
|
||||||
struct iwatch_path *iwp;
|
struct iwatch_path *iwp;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
|
paste(path, sizeof(path), dir, name);
|
||||||
_d("path: %s", path);
|
_d("path: %s", path);
|
||||||
|
|
||||||
iwp = iwatch_find_by_path(iw, path);
|
iwp = iwatch_find_by_path(iw, path);
|
||||||
|
|||||||
+1
-1
@@ -775,7 +775,7 @@ static int do_change(char *dir, char *name, uint32_t mask)
|
|||||||
char fn[strlen(dir) + strlen(name) + 2];
|
char fn[strlen(dir) + strlen(name) + 2];
|
||||||
struct conf_change *node;
|
struct conf_change *node;
|
||||||
|
|
||||||
snprintf(fn, sizeof(fn), "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
|
paste(fn, sizeof(fn), dir, name);
|
||||||
_d("path: %s mask: %08x", fn, mask);
|
_d("path: %s mask: %08x", fn, mask);
|
||||||
|
|
||||||
node = conf_find(fn);
|
node = conf_find(fn);
|
||||||
|
|||||||
+3
-3
@@ -441,20 +441,20 @@ int run_parts(char *dir, char *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
|
const char *name = e[i]->d_name;
|
||||||
|
char path[strlen(dir) + strlen(name) + 2];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char path[512];
|
|
||||||
char *argv[4] = {
|
char *argv[4] = {
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
path,
|
path,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
char *name = e[i]->d_name;
|
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
int status;
|
int status;
|
||||||
int exit_status;
|
int exit_status;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
|
paste(path, sizeof(path), dir, name);
|
||||||
if (stat(path, &st)) {
|
if (stat(path, &st)) {
|
||||||
_d("Failed stat(%s): %s", path, strerror(errno));
|
_d("Failed stat(%s): %s", path, strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -103,6 +103,17 @@ static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* paste dir/file into buf */
|
||||||
|
static inline int paste(char *buf, size_t len, const char *dir, const char *file)
|
||||||
|
{
|
||||||
|
if (!dir)
|
||||||
|
dir = "";
|
||||||
|
if (!file)
|
||||||
|
file = "";
|
||||||
|
|
||||||
|
return snprintf(buf, len, "%s%s%s", dir, fisslashdir(dir) ? "" : "/", file);
|
||||||
|
}
|
||||||
|
|
||||||
int ismnt (char *file, char *dir, char *mode);
|
int ismnt (char *file, char *dir, char *mode);
|
||||||
int fismnt (char *dir);
|
int fismnt (char *dir);
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ 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;
|
||||||
|
|
||||||
rc = snprintf(path, len, "%s/%s", prefix, file);
|
rc = paste(path, len, prefix, file);
|
||||||
if (rc < 0 || (size_t)rc >= len)
|
if (rc < 0 || (size_t)rc >= len)
|
||||||
_e("File path '%s' truncated, should end with '%s'", path, file);
|
_e("File path '%s' truncated, should end with '%s'", path, file);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user