Cuddle up to LKML C style
This commit is contained in:
parent
55884f7959
commit
e6674b2cae
14
src/einfo.h
14
src/einfo.h
@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
einfo_good,
|
einfo_good,
|
||||||
einfo_warn,
|
einfo_warn,
|
||||||
einfo_bad,
|
einfo_bad,
|
||||||
einfo_hilite,
|
einfo_hilite,
|
||||||
einfo_bracket,
|
einfo_bracket,
|
||||||
einfo_normal
|
einfo_normal
|
||||||
} einfo_color_t;
|
} einfo_color_t;
|
||||||
|
|
||||||
/* Colour codes used by the below functions. */
|
/* Colour codes used by the below functions. */
|
||||||
@ -50,7 +50,7 @@ typedef enum
|
|||||||
NOTE We use the v suffix here so we can add veinfo for va_list
|
NOTE We use the v suffix here so we can add veinfo for va_list
|
||||||
in the future, but veinfo is used by shell scripts as they don't
|
in the future, but veinfo is used by shell scripts as they don't
|
||||||
have the va_list concept
|
have the va_list concept
|
||||||
*/
|
*/
|
||||||
bool colour_terminal (void);
|
bool colour_terminal (void);
|
||||||
int einfon (const char *fmt, ...) EINFO_PRINTF (1, 2);
|
int einfon (const char *fmt, ...) EINFO_PRINTF (1, 2);
|
||||||
int ewarnn (const char *fmt, ...) EINFO_PRINTF (1, 2);
|
int ewarnn (const char *fmt, ...) EINFO_PRINTF (1, 2);
|
||||||
|
346
src/env-update.c
346
src/env-update.c
@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
Copyright 2007 Gentoo Foundation
|
Copyright 2007 Gentoo Foundation
|
||||||
Released under the GPLv2
|
Released under the GPLv2
|
||||||
*/
|
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -26,221 +27,206 @@
|
|||||||
#define LDSOCONF "/etc/ld.so.conf"
|
#define LDSOCONF "/etc/ld.so.conf"
|
||||||
|
|
||||||
#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \
|
#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \
|
||||||
"# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \
|
"# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \
|
||||||
"# GO INTO %s NOT %s\n\n"
|
"# GO INTO %s NOT %s\n\n"
|
||||||
|
|
||||||
#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \
|
#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \
|
||||||
"# changes to contents of /etc/env.d directory\n"
|
"# changes to contents of /etc/env.d directory\n"
|
||||||
|
|
||||||
static const char *specials[] =
|
static const char *specials[] = {
|
||||||
{
|
"ADA_INCLUDE_PATH",
|
||||||
"ADA_INCLUDE_PATH",
|
"ADA_OBJECTS_PATH",
|
||||||
"ADA_OBJECTS_PATH",
|
"CLASSPATH",
|
||||||
"CLASSPATH",
|
"INFOPATH",
|
||||||
"INFOPATH",
|
"KDEDIRS",
|
||||||
"KDEDIRS",
|
"LDPATH",
|
||||||
"LDPATH",
|
"MANPATH",
|
||||||
"MANPATH",
|
"PATH",
|
||||||
"PATH",
|
"PKG_CONFIG_PATH",
|
||||||
"PKG_CONFIG_PATH",
|
"PRELINK_PATH",
|
||||||
"PRELINK_PATH",
|
"PRELINK_PATH_MASK",
|
||||||
"PRELINK_PATH_MASK",
|
"PYTHONPATH",
|
||||||
"PYTHONPATH",
|
"ROOTPATH",
|
||||||
"ROOTPATH",
|
NULL
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *special_spaces[] =
|
static const char *special_spaces[] = {
|
||||||
{
|
"CONFIG_PROTECT",
|
||||||
"CONFIG_PROTECT",
|
"CONFIG_PROTECT_MASK",
|
||||||
"CONFIG_PROTECT_MASK",
|
NULL,
|
||||||
NULL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *applet = NULL;
|
static char *applet = NULL;
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char **files = rc_ls_dir (NULL, ENVDIR, 0);
|
char **files = rc_ls_dir (NULL, ENVDIR, 0);
|
||||||
char *file;
|
char *file;
|
||||||
char **envs = NULL;
|
char **envs = NULL;
|
||||||
char *env;
|
char *env;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
bool ld = true;
|
bool ld = true;
|
||||||
char *ldent;
|
char *ldent;
|
||||||
char **ldents = NULL;
|
char **ldents = NULL;
|
||||||
int nents = 0;
|
int nents = 0;
|
||||||
|
|
||||||
applet = argv[0];
|
applet = argv[0];
|
||||||
|
|
||||||
if (! files)
|
if (! files)
|
||||||
eerrorx ("%s: no files in " ENVDIR " to process", applet);
|
eerrorx ("%s: no files in " ENVDIR " to process", applet);
|
||||||
|
|
||||||
STRLIST_FOREACH (files, file, i)
|
STRLIST_FOREACH (files, file, i) {
|
||||||
{
|
char *path = rc_strcatpaths (ENVDIR, file, (char *) NULL);
|
||||||
char *path = rc_strcatpaths (ENVDIR, file, (char *) NULL);
|
char **entries = NULL;
|
||||||
char **entries = NULL;
|
char *entry;
|
||||||
char *entry;
|
int j;
|
||||||
int j;
|
|
||||||
|
|
||||||
if (! rc_is_dir (path))
|
if (! rc_is_dir (path))
|
||||||
entries = rc_get_config (NULL, path);
|
entries = rc_get_config (NULL, path);
|
||||||
free (path);
|
free (path);
|
||||||
|
|
||||||
STRLIST_FOREACH (entries, entry, j)
|
STRLIST_FOREACH (entries, entry, j) {
|
||||||
{
|
char *tmpent = rc_xstrdup (entry);
|
||||||
char *tmpent = rc_xstrdup (entry);
|
char *value = tmpent;
|
||||||
char *value = tmpent;
|
char *var = strsep (&value, "=");
|
||||||
char *var = strsep (&value, "=");
|
int k;
|
||||||
int k;
|
bool isspecial = false;
|
||||||
bool isspecial = false;
|
bool isspecial_spaced = false;
|
||||||
bool isspecial_spaced = false;
|
bool replaced = false;
|
||||||
bool replaced = false;
|
|
||||||
|
|
||||||
for (k = 0; special_spaces[k]; k++)
|
for (k = 0; special_spaces[k]; k++)
|
||||||
if (strcmp (special_spaces[k], var) == 0)
|
if (strcmp (special_spaces[k], var) == 0) {
|
||||||
{
|
isspecial = true;
|
||||||
isspecial = true;
|
isspecial_spaced = true;
|
||||||
isspecial_spaced = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (! isspecial)
|
if (! isspecial) {
|
||||||
{
|
for (k = 0; specials[k]; k++)
|
||||||
for (k = 0; specials[k]; k++)
|
if (strcmp (specials[k], var) == 0) {
|
||||||
if (strcmp (specials[k], var) == 0)
|
isspecial = true;
|
||||||
{
|
break;
|
||||||
isspecial = true;
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skip blank vars */
|
/* Skip blank vars */
|
||||||
if (isspecial &&
|
if (isspecial &&
|
||||||
(! value || strlen (value)) == 0)
|
(! value || strlen (value)) == 0)
|
||||||
{
|
{
|
||||||
free (tmpent);
|
free (tmpent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
STRLIST_FOREACH (envs, env, k)
|
STRLIST_FOREACH (envs, env, k) {
|
||||||
{
|
char *tmpenv = rc_xstrdup (env);
|
||||||
char *tmpenv = rc_xstrdup (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 (isspecial) {
|
||||||
if (isspecial)
|
int len = strlen (envs[k - 1]) + strlen (entry) + 1;
|
||||||
{
|
envs[k - 1] = rc_xrealloc (envs[k - 1], len);
|
||||||
int len = strlen (envs[k - 1]) + strlen (entry) + 1;
|
snprintf (envs[k - 1] + strlen (envs[k - 1]), len,
|
||||||
envs[k - 1] = rc_xrealloc (envs[k - 1], len);
|
"%s%s", isspecial_spaced ? " " : ":", value);
|
||||||
snprintf (envs[k - 1] + strlen (envs[k - 1]), len,
|
} else {
|
||||||
"%s%s", isspecial_spaced ? " " : ":", value);
|
free (envs[k - 1]);
|
||||||
}
|
envs[k - 1] = strdup (entry);
|
||||||
else
|
}
|
||||||
{
|
replaced = true;
|
||||||
free (envs[k - 1]);
|
}
|
||||||
envs[k - 1] = strdup (entry);
|
free (tmpenv);
|
||||||
}
|
|
||||||
replaced = true;
|
|
||||||
}
|
|
||||||
free (tmpenv);
|
|
||||||
|
|
||||||
if (replaced)
|
if (replaced)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! replaced)
|
if (! replaced)
|
||||||
envs = rc_strlist_addsort (envs, entry);
|
envs = rc_strlist_addsort (envs, entry);
|
||||||
|
|
||||||
free (tmpent);
|
free (tmpent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fp = fopen (PROFILE_ENV, "w")) == NULL)
|
if ((fp = fopen (PROFILE_ENV, "w")) == NULL)
|
||||||
eerrorx ("%s: fopen `%s': %s", applet, PROFILE_ENV, strerror (errno));
|
eerrorx ("%s: fopen `%s': %s", applet, PROFILE_ENV, strerror (errno));
|
||||||
fprintf (fp, NOTICE, "/etc/profile", PROFILE_ENV);
|
fprintf (fp, NOTICE, "/etc/profile", PROFILE_ENV);
|
||||||
STRLIST_FOREACH (envs, env, i)
|
|
||||||
{
|
|
||||||
char *tmpent = rc_xstrdup (env);
|
|
||||||
char *value = tmpent;
|
|
||||||
char *var = strsep (&value, "=");
|
|
||||||
if (strcmp (var, "LDPATH") != 0)
|
|
||||||
fprintf (fp, "export %s='%s'\n", var, value);
|
|
||||||
free (tmpent);
|
|
||||||
}
|
|
||||||
fclose (fp);
|
|
||||||
|
|
||||||
if ((fp = fopen (CSH_ENV, "w")) == NULL)
|
STRLIST_FOREACH (envs, env, i) {
|
||||||
eerrorx ("%s: fopen `%s': %s", applet, PROFILE_ENV, strerror (errno));
|
char *tmpent = rc_xstrdup (env);
|
||||||
fprintf (fp, NOTICE, "/etc/csh.cshrc", PROFILE_ENV);
|
char *value = tmpent;
|
||||||
STRLIST_FOREACH (envs, env, i)
|
char *var = strsep (&value, "=");
|
||||||
{
|
if (strcmp (var, "LDPATH") != 0)
|
||||||
char *tmpent = rc_xstrdup (env);
|
fprintf (fp, "export %s='%s'\n", var, value);
|
||||||
char *value = tmpent;
|
free (tmpent);
|
||||||
char *var = strsep (&value, "=");
|
}
|
||||||
if (strcmp (var, "LDPATH") != 0)
|
fclose (fp);
|
||||||
fprintf (fp, "setenv %s '%s'\n", var, value);
|
|
||||||
free (tmpent);
|
|
||||||
}
|
|
||||||
fclose (fp);
|
|
||||||
|
|
||||||
ldent = rc_get_config_entry (envs, "LDPATH");
|
if ((fp = fopen (CSH_ENV, "w")) == NULL)
|
||||||
|
eerrorx ("%s: fopen `%s': %s", applet, PROFILE_ENV, strerror (errno));
|
||||||
|
fprintf (fp, NOTICE, "/etc/csh.cshrc", PROFILE_ENV);
|
||||||
|
|
||||||
if (! ldent ||
|
STRLIST_FOREACH (envs, env, i) {
|
||||||
(argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0))
|
char *tmpent = rc_xstrdup (env);
|
||||||
{
|
char *value = tmpent;
|
||||||
free (envs);
|
char *var = strsep (&value, "=");
|
||||||
return (EXIT_SUCCESS);
|
if (strcmp (var, "LDPATH") != 0)
|
||||||
}
|
fprintf (fp, "setenv %s '%s'\n", var, value);
|
||||||
|
free (tmpent);
|
||||||
|
}
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
while ((file = strsep (&ldent, ":")))
|
ldent = rc_get_config_entry (envs, "LDPATH");
|
||||||
{
|
|
||||||
if (strlen (file) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ldents = rc_strlist_add (ldents, file);
|
if (! ldent ||
|
||||||
nents++;
|
(argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0))
|
||||||
}
|
{
|
||||||
|
free (envs);
|
||||||
|
return (EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
/* Update ld.so.conf only if different */
|
while ((file = strsep (&ldent, ":"))) {
|
||||||
if (rc_exists (LDSOCONF))
|
if (strlen (file) == 0)
|
||||||
{
|
continue;
|
||||||
char **lines = rc_get_list (NULL, LDSOCONF);
|
|
||||||
char *line;
|
|
||||||
ld = false;
|
|
||||||
STRLIST_FOREACH (lines, line, i)
|
|
||||||
if (i > nents || strcmp (line, ldents[i - 1]) != 0)
|
|
||||||
{
|
|
||||||
ld = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i - 1 != nents)
|
|
||||||
ld = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ld)
|
ldents = rc_strlist_add (ldents, file);
|
||||||
{
|
nents++;
|
||||||
int retval = 0;
|
}
|
||||||
|
|
||||||
if ((fp = fopen (LDSOCONF, "w")) == NULL)
|
/* Update ld.so.conf only if different */
|
||||||
eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, strerror (errno));
|
if (rc_exists (LDSOCONF)) {
|
||||||
fprintf (fp, LDNOTICE);
|
char **lines = rc_get_list (NULL, LDSOCONF);
|
||||||
STRLIST_FOREACH (ldents, ldent, i)
|
char *line;
|
||||||
fprintf (fp, "%s\n", ldent);
|
ld = false;
|
||||||
fclose (fp);
|
STRLIST_FOREACH (lines, line, i)
|
||||||
|
if (i > nents || strcmp (line, ldents[i - 1]) != 0)
|
||||||
|
{
|
||||||
|
ld = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i - 1 != nents)
|
||||||
|
ld = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ld) {
|
||||||
|
int retval = 0;
|
||||||
|
|
||||||
|
if ((fp = fopen (LDSOCONF, "w")) == NULL)
|
||||||
|
eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, strerror (errno));
|
||||||
|
fprintf (fp, LDNOTICE);
|
||||||
|
STRLIST_FOREACH (ldents, ldent, i)
|
||||||
|
fprintf (fp, "%s\n", ldent);
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||||
ebegin ("Regenerating /var/run/ld-elf.so.hints");
|
ebegin ("Regenerating /var/run/ld-elf.so.hints");
|
||||||
retval = system ("/sbin/ldconfig -elf -i '" LDSOCONF "'");
|
retval = system ("/sbin/ldconfig -elf -i '" LDSOCONF "'");
|
||||||
#else
|
#else
|
||||||
ebegin ("Regenerating /etc/ld.so.cache");
|
ebegin ("Regenerating /etc/ld.so.cache");
|
||||||
retval = system ("/sbin/ldconfig");
|
retval = system ("/sbin/ldconfig");
|
||||||
#endif
|
#endif
|
||||||
eend (retval, NULL);
|
eend (retval, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(EXIT_SUCCESS);
|
return(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
144
src/fstabinfo.c
144
src/fstabinfo.c
@ -43,104 +43,96 @@
|
|||||||
#ifdef HAVE_GETMNTENT
|
#ifdef HAVE_GETMNTENT
|
||||||
static struct mntent *getmntfile (FILE *fp, const char *file)
|
static struct mntent *getmntfile (FILE *fp, const char *file)
|
||||||
{
|
{
|
||||||
struct mntent *ent;
|
struct mntent *ent;
|
||||||
|
|
||||||
while ((ent = getmntent (fp)))
|
while ((ent = getmntent (fp)))
|
||||||
if (strcmp (file, ent->mnt_dir) == 0)
|
if (strcmp (file, ent->mnt_dir) == 0)
|
||||||
return (ent);
|
return (ent);
|
||||||
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
#ifdef HAVE_GETMNTENT
|
#ifdef HAVE_GETMNTENT
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct mntent *ent;
|
struct mntent *ent;
|
||||||
#else
|
#else
|
||||||
struct fstab *ent;
|
struct fstab *ent;
|
||||||
#endif
|
#endif
|
||||||
int result = EXIT_FAILURE;
|
int result = EXIT_FAILURE;
|
||||||
char *p;
|
char *p;
|
||||||
char *token;
|
char *token;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++) {
|
||||||
{
|
|
||||||
#ifdef HAVE_GETMNTENT
|
#ifdef HAVE_GETMNTENT
|
||||||
fp = setmntent ("/etc/fstab", "r");
|
fp = setmntent ("/etc/fstab", "r");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (strcmp (argv[i], "--fstype") == 0 && i + 1 < argc)
|
if (strcmp (argv[i], "--fstype") == 0 && i + 1 < argc) {
|
||||||
{
|
i++;
|
||||||
i++;
|
p = argv[i];
|
||||||
p = argv[i];
|
while ((token = strsep (&p, ",")))
|
||||||
while ((token = strsep (&p, ",")))
|
while ((ent = GET_ENT))
|
||||||
while ((ent = GET_ENT))
|
if (strcmp (token, ENT_TYPE (ent)) == 0)
|
||||||
if (strcmp (token, ENT_TYPE (ent)) == 0)
|
printf ("%s\n", ENT_FILE (ent));
|
||||||
printf ("%s\n", ENT_FILE (ent));
|
result = EXIT_SUCCESS;
|
||||||
result = EXIT_SUCCESS;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--mount-cmd") == 0 && i + 1 < argc)
|
if (strcmp (argv[i], "--mount-cmd") == 0 && i + 1 < argc) {
|
||||||
{
|
i++;
|
||||||
i++;
|
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
||||||
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
continue;
|
||||||
continue;
|
printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
|
||||||
printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
|
ENT_DEVICE (ent), ENT_FILE (ent));
|
||||||
ENT_DEVICE (ent), ENT_FILE (ent));
|
result = EXIT_SUCCESS;
|
||||||
result = EXIT_SUCCESS;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--opts") == 0 && i + 1 < argc)
|
if (strcmp (argv[i], "--opts") == 0 && i + 1 < argc) {
|
||||||
{
|
i++;
|
||||||
i++;
|
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
||||||
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
continue;
|
||||||
continue;
|
printf ("%s\n", ENT_OPTS (ent));
|
||||||
printf ("%s\n", ENT_OPTS (ent));
|
result = EXIT_SUCCESS;
|
||||||
result = EXIT_SUCCESS;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--passno") == 0 && i + 1 < argc)
|
if (strcmp (argv[i], "--passno") == 0 && i + 1 < argc) {
|
||||||
{
|
i++;
|
||||||
i++;
|
switch (argv[i][0]) {
|
||||||
switch (argv[i][0])
|
case '=':
|
||||||
{
|
case '<':
|
||||||
case '=':
|
case '>':
|
||||||
case '<':
|
if (sscanf (argv[i] + 1, "%d", &n) != 1)
|
||||||
case '>':
|
eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1);
|
||||||
if (sscanf (argv[i] + 1, "%d", &n) != 1)
|
|
||||||
eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1);
|
|
||||||
|
|
||||||
while ((ent = GET_ENT))
|
while ((ent = GET_ENT)) {
|
||||||
{
|
if (((argv[i][0] == '=' && n == ENT_PASS (ent)) ||
|
||||||
if (((argv[i][0] == '=' && n == ENT_PASS (ent)) ||
|
(argv[i][0] == '<' && n > ENT_PASS (ent)) ||
|
||||||
(argv[i][0] == '<' && n > ENT_PASS (ent)) ||
|
(argv[i][0] == '>' && n < ENT_PASS (ent))) &&
|
||||||
(argv[i][0] == '>' && n < ENT_PASS (ent))) &&
|
strcmp (ENT_FILE (ent), "none") != 0)
|
||||||
strcmp (ENT_FILE (ent), "none") != 0)
|
printf ("%s\n", ENT_FILE (ent));
|
||||||
printf ("%s\n", ENT_FILE (ent));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
if ((ent = GET_ENT_FILE (argv[i])) == NULL)
|
||||||
continue;
|
continue;
|
||||||
printf ("%d\n", ENT_PASS (ent));
|
printf ("%d\n", ENT_PASS (ent));
|
||||||
result = EXIT_SUCCESS;
|
result = EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END_ENT;
|
END_ENT;
|
||||||
|
|
||||||
if (result != EXIT_SUCCESS)
|
if (result != EXIT_SUCCESS) {
|
||||||
{
|
eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]);
|
||||||
eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit (result);
|
exit (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1132
src/libeinfo.c
1132
src/libeinfo.c
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#if defined(__DragonFly__) || defined(__FreeBSD__) || \
|
#if defined(__DragonFly__) || defined(__FreeBSD__) || \
|
||||||
defined(__NetBSD__) || defined (__OpenBSD__)
|
defined(__NetBSD__) || defined (__OpenBSD__)
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/user.h>
|
#include <sys/user.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
@ -37,150 +37,143 @@
|
|||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
static bool pid_is_cmd (pid_t pid, const char *cmd)
|
static bool pid_is_cmd (pid_t pid, const char *cmd)
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
snprintf(buffer, sizeof (buffer), "/proc/%d/stat", pid);
|
snprintf(buffer, sizeof (buffer), "/proc/%d/stat", pid);
|
||||||
if ((fp = fopen (buffer, "r")) == NULL)
|
if ((fp = fopen (buffer, "r")) == NULL)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
while ((c = getc (fp)) != EOF && c != '(')
|
while ((c = getc (fp)) != EOF && c != '(')
|
||||||
;
|
;
|
||||||
|
|
||||||
if (c != '(')
|
if (c != '(') {
|
||||||
{
|
fclose(fp);
|
||||||
fclose(fp);
|
return (false);
|
||||||
return (false);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while ((c = getc (fp)) != EOF && c == *cmd)
|
while ((c = getc (fp)) != EOF && c == *cmd)
|
||||||
cmd++;
|
cmd++;
|
||||||
|
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
return ((c == ')' && *cmd == '\0') ? true : false);
|
return ((c == ')' && *cmd == '\0') ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pid_is_exec (pid_t pid, const char *exec)
|
static bool pid_is_exec (pid_t pid, const char *exec)
|
||||||
{
|
{
|
||||||
char cmdline[32];
|
char cmdline[32];
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
char *p;
|
char *p;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
snprintf (cmdline, sizeof (cmdline), "/proc/%u/exe", pid);
|
snprintf (cmdline, sizeof (cmdline), "/proc/%u/exe", pid);
|
||||||
memset (buffer, 0, sizeof (buffer));
|
memset (buffer, 0, sizeof (buffer));
|
||||||
if (readlink (cmdline, buffer, sizeof (buffer)) != -1)
|
if (readlink (cmdline, buffer, sizeof (buffer)) != -1) {
|
||||||
{
|
if (strcmp (exec, buffer) == 0)
|
||||||
if (strcmp (exec, buffer) == 0)
|
return (true);
|
||||||
return (true);
|
|
||||||
|
|
||||||
/* We should cater for deleted binaries too */
|
/* We should cater for deleted binaries too */
|
||||||
if (strlen (buffer) > 10)
|
if (strlen (buffer) > 10) {
|
||||||
{
|
p = buffer + (strlen (buffer) - 10);
|
||||||
p = buffer + (strlen (buffer) - 10);
|
if (strcmp (p, " (deleted)") == 0) {
|
||||||
if (strcmp (p, " (deleted)") == 0)
|
*p = 0;
|
||||||
{
|
if (strcmp (buffer, exec) == 0)
|
||||||
*p = 0;
|
return (true);
|
||||||
if (strcmp (buffer, exec) == 0)
|
}
|
||||||
return (true);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf (cmdline, sizeof (cmdline), "/proc/%u/cmdline", pid);
|
snprintf (cmdline, sizeof (cmdline), "/proc/%u/cmdline", pid);
|
||||||
if ((fd = open (cmdline, O_RDONLY)) < 0)
|
if ((fd = open (cmdline, O_RDONLY)) < 0)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
r = read(fd, buffer, sizeof (buffer));
|
r = read(fd, buffer, sizeof (buffer));
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
buffer[r] = 0;
|
buffer[r] = 0;
|
||||||
return (strcmp (exec, buffer) == 0 ? true : false);
|
return (strcmp (exec, buffer) == 0 ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
||||||
uid_t uid, pid_t pid)
|
uid_t uid, pid_t pid)
|
||||||
{
|
{
|
||||||
DIR *procdir;
|
DIR *procdir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
int npids = 0;
|
int npids = 0;
|
||||||
int foundany = false;
|
int foundany = false;
|
||||||
pid_t p;
|
pid_t p;
|
||||||
pid_t *pids = NULL;
|
pid_t *pids = NULL;
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
pid_t runscript_pid = 0;
|
pid_t runscript_pid = 0;
|
||||||
char *pp;
|
char *pp;
|
||||||
|
|
||||||
if ((procdir = opendir ("/proc")) == NULL)
|
if ((procdir = opendir ("/proc")) == NULL)
|
||||||
eerrorx ("opendir `/proc': %s", strerror (errno));
|
eerrorx ("opendir `/proc': %s", strerror (errno));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We never match RC_RUNSCRIPT_PID if present so we avoid the below
|
We never match RC_RUNSCRIPT_PID if present so we avoid the below
|
||||||
scenario
|
scenario
|
||||||
|
|
||||||
/etc/init.d/ntpd stop does
|
/etc/init.d/ntpd stop does
|
||||||
start-stop-daemon --stop --name ntpd
|
start-stop-daemon --stop --name ntpd
|
||||||
catching /etc/init.d/ntpd stop
|
catching /etc/init.d/ntpd stop
|
||||||
|
|
||||||
nasty
|
nasty
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((pp = getenv ("RC_RUNSCRIPT_PID")))
|
if ((pp = getenv ("RC_RUNSCRIPT_PID"))) {
|
||||||
{
|
if (sscanf (pp, "%d", &runscript_pid) != 1)
|
||||||
if (sscanf (pp, "%d", &runscript_pid) != 1)
|
runscript_pid = 0;
|
||||||
runscript_pid = 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while ((entry = readdir (procdir)) != NULL)
|
while ((entry = readdir (procdir)) != NULL) {
|
||||||
{
|
if (sscanf (entry->d_name, "%d", &p) != 1)
|
||||||
if (sscanf (entry->d_name, "%d", &p) != 1)
|
continue;
|
||||||
continue;
|
foundany = true;
|
||||||
foundany = true;
|
|
||||||
|
|
||||||
if (runscript_pid != 0 && runscript_pid == p)
|
if (runscript_pid != 0 && runscript_pid == p)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pid != 0 && pid != p)
|
if (pid != 0 && pid != p)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (uid)
|
if (uid) {
|
||||||
{
|
snprintf (buffer, sizeof (buffer), "/proc/%d", pid);
|
||||||
snprintf (buffer, sizeof (buffer), "/proc/%d", pid);
|
if (stat (buffer, &sb) != 0 || sb.st_uid != uid)
|
||||||
if (stat (buffer, &sb) != 0 || sb.st_uid != uid)
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd && ! pid_is_cmd (p, cmd))
|
if (cmd && ! pid_is_cmd (p, cmd))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (exec && ! cmd && ! pid_is_exec (p, exec))
|
if (exec && ! cmd && ! pid_is_exec (p, exec))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pids = realloc (pids, sizeof (pid_t) * (npids + 2));
|
pids = realloc (pids, sizeof (pid_t) * (npids + 2));
|
||||||
if (! pids)
|
if (! pids)
|
||||||
eerrorx ("memory exhausted");
|
eerrorx ("memory exhausted");
|
||||||
|
|
||||||
pids[npids] = p;
|
pids[npids] = p;
|
||||||
pids[npids + 1] = 0;
|
pids[npids + 1] = 0;
|
||||||
npids++;
|
npids++;
|
||||||
}
|
}
|
||||||
closedir (procdir);
|
closedir (procdir);
|
||||||
|
|
||||||
if (! foundany)
|
if (! foundany)
|
||||||
eerrorx ("nothing in /proc");
|
eerrorx ("nothing in /proc");
|
||||||
|
|
||||||
return (pids);
|
return (pids);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
|
#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
|
||||||
defined(__NetBSD__) || defined(__OpenBSD__)
|
defined(__NetBSD__) || defined(__OpenBSD__)
|
||||||
|
|
||||||
# if defined(__DragonFly__) || defined(__FreeBSD__)
|
# if defined(__DragonFly__) || defined(__FreeBSD__)
|
||||||
# ifndef KERN_PROC_PROC
|
# ifndef KERN_PROC_PROC
|
||||||
@ -200,63 +193,60 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
||||||
uid_t uid, pid_t pid)
|
uid_t uid, pid_t pid)
|
||||||
{
|
{
|
||||||
static kvm_t *kd = NULL;
|
static kvm_t *kd = NULL;
|
||||||
char errbuf[_POSIX2_LINE_MAX];
|
char errbuf[_POSIX2_LINE_MAX];
|
||||||
struct _KINFO_PROC *kp;
|
struct _KINFO_PROC *kp;
|
||||||
int i;
|
int i;
|
||||||
int processes = 0;
|
int processes = 0;
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
char **argv;
|
char **argv;
|
||||||
pid_t *pids = NULL;
|
pid_t *pids = NULL;
|
||||||
int npids = 0;
|
int npids = 0;
|
||||||
|
|
||||||
if ((kd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf)) == NULL)
|
if ((kd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf)) == NULL)
|
||||||
eerrorx ("kvm_open: %s", errbuf);
|
eerrorx ("kvm_open: %s", errbuf);
|
||||||
|
|
||||||
#if defined(__DragonFly__) || defined( __FreeBSD__)
|
#if defined(__DragonFly__) || defined( __FreeBSD__)
|
||||||
kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
|
kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
|
||||||
#else
|
#else
|
||||||
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
|
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
|
||||||
&processes);
|
&processes);
|
||||||
#endif
|
#endif
|
||||||
for (i = 0; i < processes; i++)
|
for (i = 0; i < processes; i++) {
|
||||||
{
|
pid_t p = _GET_KINFO_PID (kp[i]);
|
||||||
pid_t p = _GET_KINFO_PID (kp[i]);
|
if (pid != 0 && pid != p)
|
||||||
if (pid != 0 && pid != p)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (uid != 0 && uid != _GET_KINFO_UID (kp[i]))
|
if (uid != 0 && uid != _GET_KINFO_UID (kp[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cmd)
|
if (cmd) {
|
||||||
{
|
if (! _GET_KINFO_COMM (kp[i]) ||
|
||||||
if (! _GET_KINFO_COMM (kp[i]) ||
|
strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0)
|
||||||
strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0)
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (exec && ! cmd)
|
if (exec && ! cmd) {
|
||||||
{
|
if ((argv = _KVM_GETARGV (kd, &kp[i], argc)) == NULL || ! *argv)
|
||||||
if ((argv = _KVM_GETARGV (kd, &kp[i], argc)) == NULL || ! *argv)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (strcmp (*argv, exec) != 0)
|
if (strcmp (*argv, exec) != 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pids = realloc (pids, sizeof (pid_t) * (npids + 2));
|
pids = realloc (pids, sizeof (pid_t) * (npids + 2));
|
||||||
if (! pids)
|
if (! pids)
|
||||||
eerrorx ("memory exhausted");
|
eerrorx ("memory exhausted");
|
||||||
|
|
||||||
pids[npids] = p;
|
pids[npids] = p;
|
||||||
pids[npids + 1] = 0;
|
pids[npids + 1] = 0;
|
||||||
npids++;
|
npids++;
|
||||||
}
|
}
|
||||||
kvm_close(kd);
|
kvm_close(kd);
|
||||||
|
|
||||||
return (pids);
|
return (pids);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -264,349 +254,309 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool _match_daemon (const char *path, const char *file,
|
static bool _match_daemon (const char *path, const char *file,
|
||||||
const char *mexec, const char *mname,
|
const char *mexec, const char *mname,
|
||||||
const char *mpidfile)
|
const char *mpidfile)
|
||||||
{
|
{
|
||||||
char buffer[RC_LINEBUFFER];
|
char buffer[RC_LINEBUFFER];
|
||||||
char *ffile = rc_strcatpaths (path, file, (char *) NULL);
|
char *ffile = rc_strcatpaths (path, file, (char *) NULL);
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int lc = 0;
|
int lc = 0;
|
||||||
int m = 0;
|
int m = 0;
|
||||||
|
|
||||||
if (! rc_exists (ffile))
|
if (! rc_exists (ffile)) {
|
||||||
{
|
free (ffile);
|
||||||
free (ffile);
|
return (false);
|
||||||
return (false);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((fp = fopen (ffile, "r")) == NULL)
|
if ((fp = fopen (ffile, "r")) == NULL) {
|
||||||
{
|
eerror ("fopen `%s': %s", ffile, strerror (errno));
|
||||||
eerror ("fopen `%s': %s", ffile, strerror (errno));
|
free (ffile);
|
||||||
free (ffile);
|
return (false);
|
||||||
return (false);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (! mname)
|
if (! mname)
|
||||||
m += 10;
|
m += 10;
|
||||||
if (! mpidfile)
|
if (! mpidfile)
|
||||||
m += 100;
|
m += 100;
|
||||||
|
|
||||||
memset (buffer, 0, sizeof (buffer));
|
memset (buffer, 0, sizeof (buffer));
|
||||||
while ((fgets (buffer, RC_LINEBUFFER, fp)))
|
while ((fgets (buffer, RC_LINEBUFFER, fp))) {
|
||||||
{
|
int lb = strlen (buffer) - 1;
|
||||||
int lb = strlen (buffer) - 1;
|
if (buffer[lb] == '\n')
|
||||||
if (buffer[lb] == '\n')
|
buffer[lb] = 0;
|
||||||
buffer[lb] = 0;
|
|
||||||
|
|
||||||
if (strcmp (buffer, mexec) == 0)
|
if (strcmp (buffer, mexec) == 0)
|
||||||
m += 1;
|
m += 1;
|
||||||
else if (mname && strcmp (buffer, mname) == 0)
|
else if (mname && strcmp (buffer, mname) == 0)
|
||||||
m += 10;
|
m += 10;
|
||||||
else if (mpidfile && strcmp (buffer, mpidfile) == 0)
|
else if (mpidfile && strcmp (buffer, mpidfile) == 0)
|
||||||
m += 100;
|
m += 100;
|
||||||
|
|
||||||
if (m == 111)
|
if (m == 111)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lc++;
|
lc++;
|
||||||
if (lc > 5)
|
if (lc > 5)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
free (ffile);
|
free (ffile);
|
||||||
|
|
||||||
return (m == 111 ? true : false);
|
return (m == 111 ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rc_set_service_daemon (const char *service, const char *exec,
|
void rc_set_service_daemon (const char *service, const char *exec,
|
||||||
const char *name, const char *pidfile,
|
const char *name, const char *pidfile,
|
||||||
bool started)
|
bool started)
|
||||||
{
|
{
|
||||||
char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
|
char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
char **files = NULL;
|
char **files = NULL;
|
||||||
char *file;
|
char *file;
|
||||||
char *ffile = NULL;
|
char *ffile = NULL;
|
||||||
int i;
|
int i;
|
||||||
char *mexec;
|
char *mexec;
|
||||||
char *mname;
|
char *mname;
|
||||||
char *mpidfile;
|
char *mpidfile;
|
||||||
int nfiles = 0;
|
int nfiles = 0;
|
||||||
|
|
||||||
if (! exec && ! name && ! pidfile)
|
if (! exec && ! name && ! pidfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (exec)
|
if (exec) {
|
||||||
{
|
i = strlen (exec) + 6;
|
||||||
i = strlen (exec) + 6;
|
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
|
||||||
}
|
mexec = strdup ("exec=");
|
||||||
else
|
|
||||||
mexec = strdup ("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
|
||||||
}
|
mname = strdup ("name=");
|
||||||
else
|
|
||||||
mname = strdup ("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
|
||||||
}
|
mpidfile = strdup ("pidfile=");
|
||||||
else
|
|
||||||
mpidfile = strdup ("pidfile=");
|
|
||||||
|
|
||||||
/* Regardless, erase any existing daemon info */
|
/* Regardless, erase any existing daemon info */
|
||||||
if (rc_is_dir (dirpath))
|
if (rc_is_dir (dirpath)) {
|
||||||
{
|
char *oldfile = NULL;
|
||||||
char *oldfile = NULL;
|
files = rc_ls_dir (NULL, dirpath, 0);
|
||||||
files = rc_ls_dir (NULL, dirpath, 0);
|
STRLIST_FOREACH (files, file, i) {
|
||||||
STRLIST_FOREACH (files, file, i)
|
ffile = rc_strcatpaths (dirpath, file, (char *) NULL);
|
||||||
{
|
nfiles++;
|
||||||
ffile = rc_strcatpaths (dirpath, file, (char *) NULL);
|
|
||||||
nfiles++;
|
|
||||||
|
|
||||||
if (! oldfile)
|
if (! oldfile) {
|
||||||
{
|
if (_match_daemon (dirpath, file, mexec, mname, mpidfile)) {
|
||||||
if (_match_daemon (dirpath, file, mexec, mname, mpidfile))
|
unlink (ffile);
|
||||||
{
|
oldfile = ffile;
|
||||||
unlink (ffile);
|
nfiles--;
|
||||||
oldfile = ffile;
|
}
|
||||||
nfiles--;
|
} else {
|
||||||
}
|
rename (ffile, oldfile);
|
||||||
}
|
free (oldfile);
|
||||||
else
|
oldfile = ffile;
|
||||||
{
|
}
|
||||||
rename (ffile, oldfile);
|
}
|
||||||
free (oldfile);
|
if (ffile)
|
||||||
oldfile = ffile;
|
free (ffile);
|
||||||
}
|
free (files);
|
||||||
}
|
}
|
||||||
if (ffile)
|
|
||||||
free (ffile);
|
|
||||||
free (files);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now store our daemon info */
|
/* Now store our daemon info */
|
||||||
if (started)
|
if (started) {
|
||||||
{
|
char buffer[10];
|
||||||
char buffer[10];
|
FILE *fp;
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if (! rc_is_dir (dirpath))
|
if (! rc_is_dir (dirpath))
|
||||||
if (mkdir (dirpath, 0755) != 0)
|
if (mkdir (dirpath, 0755) != 0)
|
||||||
eerror ("mkdir `%s': %s", dirpath, strerror (errno));
|
eerror ("mkdir `%s': %s", dirpath, strerror (errno));
|
||||||
|
|
||||||
snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1);
|
snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1);
|
||||||
file = rc_strcatpaths (dirpath, buffer, (char *) NULL);
|
file = rc_strcatpaths (dirpath, buffer, (char *) NULL);
|
||||||
if ((fp = fopen (file, "w")) == NULL)
|
if ((fp = fopen (file, "w")) == NULL)
|
||||||
eerror ("fopen `%s': %s", file, strerror (errno));
|
eerror ("fopen `%s': %s", file, strerror (errno));
|
||||||
else
|
else {
|
||||||
{
|
fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
|
||||||
fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
|
fclose (fp);
|
||||||
fclose (fp);
|
}
|
||||||
}
|
free (file);
|
||||||
free (file);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
free (mexec);
|
free (mexec);
|
||||||
free (mname);
|
free (mname);
|
||||||
free (mpidfile);
|
free (mpidfile);
|
||||||
free (dirpath);
|
free (dirpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rc_service_started_daemon (const char *service, const char *exec,
|
bool rc_service_started_daemon (const char *service, const char *exec,
|
||||||
int indx)
|
int indx)
|
||||||
{
|
{
|
||||||
char *dirpath;
|
char *dirpath;
|
||||||
char *file;
|
char *file;
|
||||||
int i;
|
int i;
|
||||||
char *mexec;
|
char *mexec;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
if (! service || ! exec)
|
if (! service || ! exec)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
|
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
if (! rc_is_dir (dirpath))
|
if (! rc_is_dir (dirpath)) {
|
||||||
{
|
free (dirpath);
|
||||||
free (dirpath);
|
return (false);
|
||||||
return (false);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
i = strlen (exec) + 6;
|
i = strlen (exec) + 6;
|
||||||
mexec = rc_xmalloc (sizeof (char *) * i);
|
mexec = rc_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 = rc_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);
|
} else {
|
||||||
}
|
char **files = rc_ls_dir (NULL, dirpath, 0);
|
||||||
else
|
STRLIST_FOREACH (files, file, i) {
|
||||||
{
|
retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
|
||||||
char **files = rc_ls_dir (NULL, dirpath, 0);
|
if (retval)
|
||||||
STRLIST_FOREACH (files, file, i)
|
break;
|
||||||
{
|
}
|
||||||
retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
|
free (files);
|
||||||
if (retval)
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
free (files);
|
|
||||||
}
|
|
||||||
|
|
||||||
free (mexec);
|
free (mexec);
|
||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rc_service_daemons_crashed (const char *service)
|
bool rc_service_daemons_crashed (const char *service)
|
||||||
{
|
{
|
||||||
char *dirpath;
|
char *dirpath;
|
||||||
char **files;
|
char **files;
|
||||||
char *file;
|
char *file;
|
||||||
char *path;
|
char *path;
|
||||||
int i;
|
int i;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buffer[RC_LINEBUFFER];
|
char buffer[RC_LINEBUFFER];
|
||||||
char *exec = NULL;
|
char *exec = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char *pidfile = NULL;
|
char *pidfile = NULL;
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
pid_t *pids = NULL;
|
pid_t *pids = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
char *token;
|
char *token;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
if (! service)
|
if (! service)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
|
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
if (! rc_is_dir (dirpath))
|
if (! rc_is_dir (dirpath)) {
|
||||||
{
|
free (dirpath);
|
||||||
free (dirpath);
|
return (false);
|
||||||
return (false);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
memset (buffer, 0, sizeof (buffer));
|
memset (buffer, 0, sizeof (buffer));
|
||||||
files = rc_ls_dir (NULL, dirpath, 0);
|
files = rc_ls_dir (NULL, dirpath, 0);
|
||||||
STRLIST_FOREACH (files, file, i)
|
STRLIST_FOREACH (files, file, i) {
|
||||||
{
|
path = rc_strcatpaths (dirpath, file, (char *) NULL);
|
||||||
path = rc_strcatpaths (dirpath, file, (char *) NULL);
|
fp = fopen (path, "r");
|
||||||
fp = fopen (path, "r");
|
free (path);
|
||||||
free (path);
|
if (! fp) {
|
||||||
if (! fp)
|
eerror ("fopen `%s': %s", file, strerror (errno));
|
||||||
{
|
continue;
|
||||||
eerror ("fopen `%s': %s", file, strerror (errno));
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((fgets (buffer, RC_LINEBUFFER, fp)))
|
while ((fgets (buffer, RC_LINEBUFFER, fp))) {
|
||||||
{
|
int lb = strlen (buffer) - 1;
|
||||||
int lb = strlen (buffer) - 1;
|
if (buffer[lb] == '\n')
|
||||||
if (buffer[lb] == '\n')
|
buffer[lb] = 0;
|
||||||
buffer[lb] = 0;
|
|
||||||
|
|
||||||
p = buffer;
|
p = buffer;
|
||||||
if ((token = strsep (&p, "=")) == NULL || ! p)
|
if ((token = strsep (&p, "=")) == NULL || ! p)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strlen (p) == 0)
|
if (strlen (p) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcmp (token, "exec") == 0)
|
if (strcmp (token, "exec") == 0) {
|
||||||
{
|
if (exec)
|
||||||
if (exec)
|
free (exec);
|
||||||
free (exec);
|
exec = strdup (p);
|
||||||
exec = strdup (p);
|
} else if (strcmp (token, "name") == 0) {
|
||||||
}
|
if (name)
|
||||||
else if (strcmp (token, "name") == 0)
|
free (name);
|
||||||
{
|
name = strdup (p);
|
||||||
if (name)
|
} else if (strcmp (token, "pidfile") == 0) {
|
||||||
free (name);
|
if (pidfile)
|
||||||
name = strdup (p);
|
free (pidfile);
|
||||||
}
|
pidfile = strdup (p);
|
||||||
else if (strcmp (token, "pidfile") == 0)
|
}
|
||||||
{
|
}
|
||||||
if (pidfile)
|
fclose (fp);
|
||||||
free (pidfile);
|
|
||||||
pidfile = strdup (p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose (fp);
|
|
||||||
|
|
||||||
pid = 0;
|
pid = 0;
|
||||||
if (pidfile)
|
if (pidfile) {
|
||||||
{
|
if (! rc_exists (pidfile)) {
|
||||||
if (! rc_exists (pidfile))
|
retval = true;
|
||||||
{
|
break;
|
||||||
retval = true;
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fp = fopen (pidfile, "r")) == NULL)
|
if ((fp = fopen (pidfile, "r")) == NULL) {
|
||||||
{
|
eerror ("fopen `%s': %s", pidfile, strerror (errno));
|
||||||
eerror ("fopen `%s': %s", pidfile, strerror (errno));
|
retval = true;
|
||||||
retval = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (fscanf (fp, "%d", &pid) != 1)
|
if (fscanf (fp, "%d", &pid) != 1) {
|
||||||
{
|
eerror ("no pid found in `%s'", pidfile);
|
||||||
eerror ("no pid found in `%s'", pidfile);
|
fclose (fp);
|
||||||
fclose (fp);
|
retval = true;
|
||||||
retval = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
free (pidfile);
|
free (pidfile);
|
||||||
pidfile = NULL;
|
pidfile = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL)
|
if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL) {
|
||||||
{
|
retval = true;
|
||||||
retval = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
free (pids);
|
||||||
free (pids);
|
|
||||||
|
|
||||||
if (exec)
|
if (exec) {
|
||||||
{
|
free (exec);
|
||||||
free (exec);
|
exec = NULL;
|
||||||
exec = NULL;
|
}
|
||||||
}
|
if (name) {
|
||||||
if (name)
|
free (name);
|
||||||
{
|
name = NULL;
|
||||||
free (name);
|
}
|
||||||
name = NULL;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exec)
|
if (exec) {
|
||||||
{
|
free (exec);
|
||||||
free (exec);
|
exec = NULL;
|
||||||
exec = NULL;
|
}
|
||||||
}
|
if (name) {
|
||||||
if (name)
|
free (name);
|
||||||
{
|
name = NULL;
|
||||||
free (name);
|
}
|
||||||
name = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
free (dirpath);
|
free (dirpath);
|
||||||
rc_strlist_free (files);
|
rc_strlist_free (files);
|
||||||
|
|
||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
1023
src/librc-misc.c
1023
src/librc-misc.c
File diff suppressed because it is too large
Load Diff
@ -16,136 +16,130 @@
|
|||||||
|
|
||||||
char **rc_strlist_add (char **list, const char *item)
|
char **rc_strlist_add (char **list, const char *item)
|
||||||
{
|
{
|
||||||
char **newlist;
|
char **newlist;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (! item)
|
if (! item)
|
||||||
return (list);
|
return (list);
|
||||||
|
|
||||||
while (list && list[i])
|
while (list && list[i])
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
newlist = rc_xrealloc (list, sizeof (char *) * (i + 2));
|
newlist = rc_xrealloc (list, sizeof (char *) * (i + 2));
|
||||||
newlist[i] = rc_xstrdup (item);
|
newlist[i] = rc_xstrdup (item);
|
||||||
newlist[i + 1] = NULL;
|
newlist[i + 1] = NULL;
|
||||||
|
|
||||||
return (newlist);
|
return (newlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **_rc_strlist_addsort (char **list, const char *item,
|
static char **_rc_strlist_addsort (char **list, const char *item,
|
||||||
int (*sortfunc) (const char *s1,
|
int (*sortfunc) (const char *s1,
|
||||||
const char *s2),
|
const char *s2),
|
||||||
bool uniq)
|
bool uniq)
|
||||||
{
|
{
|
||||||
char **newlist;
|
char **newlist;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *tmp1;
|
char *tmp1;
|
||||||
char *tmp2;
|
char *tmp2;
|
||||||
|
|
||||||
if (! item)
|
if (! item)
|
||||||
return (list);
|
return (list);
|
||||||
|
|
||||||
while (list && list[i])
|
while (list && list[i]) {
|
||||||
{
|
if (uniq && strcmp (list[i], item) == 0)
|
||||||
if (uniq && strcmp (list[i], item) == 0)
|
return (list);
|
||||||
return (list);
|
i++;
|
||||||
i++;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newlist = rc_xrealloc (list, sizeof (char *) * (i + 2));
|
newlist = rc_xrealloc (list, sizeof (char *) * (i + 2));
|
||||||
|
|
||||||
if (! i)
|
if (! i)
|
||||||
newlist[i] = NULL;
|
newlist[i] = NULL;
|
||||||
newlist[i + 1] = NULL;
|
newlist[i + 1] = NULL;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (newlist[i] && sortfunc (newlist[i], item) < 0)
|
while (newlist[i] && sortfunc (newlist[i], item) < 0)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
tmp1 = newlist[i];
|
tmp1 = newlist[i];
|
||||||
newlist[i] = rc_xstrdup (item);
|
newlist[i] = rc_xstrdup (item);
|
||||||
do
|
do {
|
||||||
{
|
i++;
|
||||||
i++;
|
tmp2 = newlist[i];
|
||||||
tmp2 = newlist[i];
|
newlist[i] = tmp1;
|
||||||
newlist[i] = tmp1;
|
tmp1 = tmp2;
|
||||||
tmp1 = tmp2;
|
} while (tmp1);
|
||||||
} while (tmp1);
|
|
||||||
|
|
||||||
return (newlist);
|
return (newlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **rc_strlist_addsort (char **list, const char *item)
|
char **rc_strlist_addsort (char **list, const char *item)
|
||||||
{
|
{
|
||||||
return (_rc_strlist_addsort (list, item, strcoll, false));
|
return (_rc_strlist_addsort (list, item, strcoll, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
char **rc_strlist_addsortc (char **list, const char *item)
|
char **rc_strlist_addsortc (char **list, const char *item)
|
||||||
{
|
{
|
||||||
return (_rc_strlist_addsort (list, item, strcmp, false));
|
return (_rc_strlist_addsort (list, item, strcmp, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
char **rc_strlist_addsortu (char **list, const char *item)
|
char **rc_strlist_addsortu (char **list, const char *item)
|
||||||
{
|
{
|
||||||
return (_rc_strlist_addsort (list, item, strcmp, true));
|
return (_rc_strlist_addsort (list, item, strcmp, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
char **rc_strlist_delete (char **list, const char *item)
|
char **rc_strlist_delete (char **list, const char *item)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!list || ! item)
|
if (!list || ! item)
|
||||||
return (list);
|
return (list);
|
||||||
|
|
||||||
while (list[i])
|
while (list[i])
|
||||||
if (! strcmp (list[i], item))
|
if (! strcmp (list[i], item)) {
|
||||||
{
|
free (list[i]);
|
||||||
free (list[i]);
|
do {
|
||||||
do
|
list[i] = list[i + 1];
|
||||||
{
|
i++;
|
||||||
list[i] = list[i + 1];
|
} while (list[i]);
|
||||||
i++;
|
}
|
||||||
} while (list[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (list);
|
return (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rc_strlist_reverse (char **list)
|
void rc_strlist_reverse (char **list)
|
||||||
{
|
{
|
||||||
char *item;
|
char *item;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
if (! list)
|
if (! list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (list[j])
|
while (list[j])
|
||||||
j++;
|
j++;
|
||||||
j--;
|
j--;
|
||||||
|
|
||||||
while (i < j && list[i] && list[j])
|
while (i < j && list[i] && list[j]) {
|
||||||
{
|
item = list[i];
|
||||||
item = list[i];
|
list[i] = list[j];
|
||||||
list[i] = list[j];
|
list[j] = item;
|
||||||
list[j] = item;
|
i++;
|
||||||
i++;
|
j--;
|
||||||
j--;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rc_strlist_free (char **list)
|
void rc_strlist_free (char **list)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (! list)
|
if (! list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (list[i])
|
while (list[i]) {
|
||||||
{
|
free (list[i]);
|
||||||
free (list[i]);
|
list[i++] = NULL;
|
||||||
list[i++] = NULL;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
free (list);
|
free (list);
|
||||||
}
|
}
|
||||||
|
1103
src/librc.c
1103
src/librc.c
File diff suppressed because it is too large
Load Diff
338
src/mountinfo.c
338
src/mountinfo.c
@ -28,104 +28,98 @@
|
|||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__)
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__)
|
||||||
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
|
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
|
||||||
char **mounts, bool list_nodes, bool list_fstype)
|
char **mounts, bool list_nodes, bool list_fstype)
|
||||||
{
|
{
|
||||||
struct statfs *mnts;
|
struct statfs *mnts;
|
||||||
int nmnts;
|
int nmnts;
|
||||||
int i;
|
int i;
|
||||||
char **list = NULL;
|
char **list = NULL;
|
||||||
|
|
||||||
if ((nmnts = getmntinfo (&mnts, MNT_NOWAIT)) == 0)
|
if ((nmnts = getmntinfo (&mnts, MNT_NOWAIT)) == 0)
|
||||||
eerrorx ("getmntinfo: %s", strerror (errno));
|
eerrorx ("getmntinfo: %s", strerror (errno));
|
||||||
|
|
||||||
for (i = 0; i < nmnts; i++)
|
for (i = 0; i < nmnts; i++) {
|
||||||
{
|
if (node_regex &&
|
||||||
if (node_regex &&
|
regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0)
|
||||||
regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0)
|
continue;
|
||||||
continue;
|
if (fstype_regex &&
|
||||||
if (fstype_regex &&
|
regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0)
|
||||||
regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (mounts)
|
if (mounts) {
|
||||||
{
|
bool found = false;
|
||||||
bool found = false;
|
int j;
|
||||||
int j;
|
char *mnt;
|
||||||
char *mnt;
|
STRLIST_FOREACH (mounts, mnt, j)
|
||||||
STRLIST_FOREACH (mounts, mnt, j)
|
if (strcmp (mnt, mnts[i].f_mntonname) == 0) {
|
||||||
if (strcmp (mnt, mnts[i].f_mntonname) == 0)
|
found = true;
|
||||||
{
|
break;
|
||||||
found = true;
|
}
|
||||||
break;
|
if (! found)
|
||||||
}
|
continue;
|
||||||
if (! found)
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = rc_strlist_addsortc (list, list_nodes ?
|
list = rc_strlist_addsortc (list, list_nodes ?
|
||||||
mnts[i].f_mntfromname :
|
mnts[i].f_mntfromname :
|
||||||
list_fstype ? mnts[i].f_fstypename :
|
list_fstype ? mnts[i].f_fstypename :
|
||||||
mnts[i].f_mntonname);
|
mnts[i].f_mntonname);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (list);
|
return (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined (__linux__)
|
#elif defined (__linux__)
|
||||||
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
|
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
|
||||||
char **mounts, bool list_nodes, bool list_fstype)
|
char **mounts, bool list_nodes, bool list_fstype)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buffer[PATH_MAX * 3];
|
char buffer[PATH_MAX * 3];
|
||||||
char *p;
|
char *p;
|
||||||
char *from;
|
char *from;
|
||||||
char *to;
|
char *to;
|
||||||
char *fstype;
|
char *fstype;
|
||||||
char **list = NULL;
|
char **list = NULL;
|
||||||
|
|
||||||
if ((fp = fopen ("/proc/mounts", "r")) == NULL)
|
if ((fp = fopen ("/proc/mounts", "r")) == NULL)
|
||||||
eerrorx ("getmntinfo: %s", strerror (errno));
|
eerrorx ("getmntinfo: %s", strerror (errno));
|
||||||
|
|
||||||
while (fgets (buffer, sizeof (buffer), fp))
|
while (fgets (buffer, sizeof (buffer), fp)) {
|
||||||
{
|
p = buffer;
|
||||||
p = buffer;
|
from = strsep (&p, " ");
|
||||||
from = strsep (&p, " ");
|
if (node_regex &&
|
||||||
if (node_regex &&
|
regexec (node_regex, from, 0, NULL, 0) != 0)
|
||||||
regexec (node_regex, from, 0, NULL, 0) != 0)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
to = strsep (&p, " ");
|
to = strsep (&p, " ");
|
||||||
fstype = strsep (&p, " ");
|
fstype = strsep (&p, " ");
|
||||||
/* Skip the really silly rootfs */
|
/* Skip the really silly rootfs */
|
||||||
if (strcmp (fstype, "rootfs") == 0)
|
if (strcmp (fstype, "rootfs") == 0)
|
||||||
continue;
|
continue;
|
||||||
if (fstype_regex &&
|
if (fstype_regex &&
|
||||||
regexec (fstype_regex, fstype, 0, NULL, 0) != 0)
|
regexec (fstype_regex, fstype, 0, NULL, 0) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (mounts)
|
if (mounts) {
|
||||||
{
|
bool found = false;
|
||||||
bool found = false;
|
int j;
|
||||||
int j;
|
char *mnt;
|
||||||
char *mnt;
|
STRLIST_FOREACH (mounts, mnt, j)
|
||||||
STRLIST_FOREACH (mounts, mnt, j)
|
if (strcmp (mnt, to) == 0) {
|
||||||
if (strcmp (mnt, to) == 0)
|
found = true;
|
||||||
{
|
break;
|
||||||
found = true;
|
}
|
||||||
break;
|
if (! found)
|
||||||
}
|
continue;
|
||||||
if (! found)
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = rc_strlist_addsortc (list,
|
list = rc_strlist_addsortc (list,
|
||||||
list_nodes ?
|
list_nodes ?
|
||||||
list_fstype ? fstype :
|
list_fstype ? fstype :
|
||||||
from : to);
|
from : to);
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
return (list);
|
return (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -134,113 +128,105 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
|
|||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
regex_t *fstype_regex = NULL;
|
regex_t *fstype_regex = NULL;
|
||||||
regex_t *node_regex = NULL;
|
regex_t *node_regex = NULL;
|
||||||
regex_t *skip_regex = NULL;
|
regex_t *skip_regex = NULL;
|
||||||
char **nodes = NULL;
|
char **nodes = NULL;
|
||||||
char *node;
|
char *node;
|
||||||
int result;
|
int result;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
bool list_nodes = false;
|
bool list_nodes = false;
|
||||||
bool list_fstype = false;
|
bool list_fstype = false;
|
||||||
bool reverse = false;
|
bool reverse = false;
|
||||||
char **mounts = NULL;
|
char **mounts = NULL;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++) {
|
||||||
{
|
if (strcmp (argv[i], "--fstype-regex") == 0 && (i + 1 < argc)) {
|
||||||
if (strcmp (argv[i], "--fstype-regex") == 0 && (i + 1 < argc))
|
i++;
|
||||||
{
|
if (fstype_regex)
|
||||||
i++;
|
free (fstype_regex);
|
||||||
if (fstype_regex)
|
fstype_regex = rc_xmalloc (sizeof (regex_t));
|
||||||
free (fstype_regex);
|
if ((result = regcomp (fstype_regex, argv[i],
|
||||||
fstype_regex = rc_xmalloc (sizeof (regex_t));
|
REG_EXTENDED | REG_NOSUB)) != 0)
|
||||||
if ((result = regcomp (fstype_regex, argv[i],
|
{
|
||||||
REG_EXTENDED | REG_NOSUB)) != 0)
|
regerror (result, fstype_regex, buffer, sizeof (buffer));
|
||||||
{
|
eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
|
||||||
regerror (result, fstype_regex, buffer, sizeof (buffer));
|
}
|
||||||
eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--node-regex") == 0 && (i + 1 < argc))
|
if (strcmp (argv[i], "--node-regex") == 0 && (i + 1 < argc)) {
|
||||||
{
|
i++;
|
||||||
i++;
|
if (node_regex)
|
||||||
if (node_regex)
|
free (node_regex);
|
||||||
free (node_regex);
|
node_regex = rc_xmalloc (sizeof (regex_t));
|
||||||
node_regex = rc_xmalloc (sizeof (regex_t));
|
if ((result = regcomp (node_regex, argv[i],
|
||||||
if ((result = regcomp (node_regex, argv[i],
|
REG_EXTENDED | REG_NOSUB)) != 0)
|
||||||
REG_EXTENDED | REG_NOSUB)) != 0)
|
{
|
||||||
{
|
regerror (result, node_regex, buffer, sizeof (buffer));
|
||||||
regerror (result, node_regex, buffer, sizeof (buffer));
|
eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
|
||||||
eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
|
}
|
||||||
}
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--skip-regex") == 0 && (i + 1 < argc))
|
if (strcmp (argv[i], "--skip-regex") == 0 && (i + 1 < argc)) {
|
||||||
{
|
i++;
|
||||||
i++;
|
if (skip_regex)
|
||||||
if (skip_regex)
|
free (skip_regex);
|
||||||
free (skip_regex);
|
skip_regex = rc_xmalloc (sizeof (regex_t));
|
||||||
skip_regex = rc_xmalloc (sizeof (regex_t));
|
if ((result = regcomp (skip_regex, argv[i],
|
||||||
if ((result = regcomp (skip_regex, argv[i],
|
REG_EXTENDED | REG_NOSUB)) != 0)
|
||||||
REG_EXTENDED | REG_NOSUB)) != 0)
|
{
|
||||||
{
|
regerror (result, skip_regex, buffer, sizeof (buffer));
|
||||||
regerror (result, skip_regex, buffer, sizeof (buffer));
|
eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
|
||||||
eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
|
}
|
||||||
}
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--fstype") == 0)
|
if (strcmp (argv[i], "--fstype") == 0) {
|
||||||
{
|
list_fstype = true;
|
||||||
list_fstype = true;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--node") == 0)
|
if (strcmp (argv[i], "--node") == 0) {
|
||||||
{
|
list_nodes = true;
|
||||||
list_nodes = true;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
if (strcmp (argv[i], "--reverse") == 0) {
|
||||||
if (strcmp (argv[i], "--reverse") == 0)
|
reverse = true;
|
||||||
{
|
continue;
|
||||||
reverse = true;
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argv[i][0] != '/')
|
if (argv[i][0] != '/')
|
||||||
eerrorx ("%s: `%s' is not a mount point", argv[0], argv[i]);
|
eerrorx ("%s: `%s' is not a mount point", argv[0], argv[i]);
|
||||||
|
|
||||||
mounts = rc_strlist_add (mounts, argv[i]);
|
mounts = rc_strlist_add (mounts, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes = find_mounts (node_regex, fstype_regex, mounts,
|
nodes = find_mounts (node_regex, fstype_regex, mounts,
|
||||||
list_nodes, list_fstype);
|
list_nodes, list_fstype);
|
||||||
|
|
||||||
if (node_regex)
|
if (node_regex)
|
||||||
regfree (node_regex);
|
regfree (node_regex);
|
||||||
if (fstype_regex)
|
if (fstype_regex)
|
||||||
regfree (fstype_regex);
|
regfree (fstype_regex);
|
||||||
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
rc_strlist_reverse (nodes);
|
rc_strlist_reverse (nodes);
|
||||||
|
|
||||||
result = EXIT_FAILURE;
|
result = EXIT_FAILURE;
|
||||||
STRLIST_FOREACH (nodes, node, i)
|
STRLIST_FOREACH (nodes, node, i) {
|
||||||
{
|
if (skip_regex && regexec (skip_regex, node, 0, NULL, 0) == 0)
|
||||||
if (skip_regex && regexec (skip_regex, node, 0, NULL, 0) == 0)
|
continue;
|
||||||
continue;
|
printf ("%s\n", node);
|
||||||
printf ("%s\n", node);
|
result = EXIT_SUCCESS;
|
||||||
result = EXIT_SUCCESS;
|
}
|
||||||
}
|
rc_strlist_free (nodes);
|
||||||
rc_strlist_free (nodes);
|
|
||||||
|
|
||||||
if (skip_regex)
|
if (skip_regex)
|
||||||
free (skip_regex);
|
free (skip_regex);
|
||||||
|
|
||||||
exit (result);
|
exit (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
154
src/rc-depend.c
154
src/rc-depend.c
@ -20,101 +20,89 @@
|
|||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char **types = NULL;
|
char **types = NULL;
|
||||||
char **services = NULL;
|
char **services = NULL;
|
||||||
char **depends = NULL;
|
char **depends = NULL;
|
||||||
rc_depinfo_t *deptree = NULL;
|
rc_depinfo_t *deptree = NULL;
|
||||||
rc_depinfo_t *di;
|
rc_depinfo_t *di;
|
||||||
char *service;
|
char *service;
|
||||||
int options = RC_DEP_TRACE;
|
int options = RC_DEP_TRACE;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
int i;
|
int i;
|
||||||
bool update = false;
|
bool update = false;
|
||||||
char *runlevel = getenv ("RC_SOFTLEVEL");
|
char *runlevel = getenv ("RC_SOFTLEVEL");
|
||||||
|
|
||||||
if (! runlevel)
|
if (! runlevel)
|
||||||
runlevel = rc_get_runlevel ();
|
runlevel = rc_get_runlevel ();
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++) {
|
||||||
{
|
if (strcmp (argv[i], "--update") == 0) {
|
||||||
if (strcmp (argv[i], "--update") == 0)
|
if (! update) {
|
||||||
{
|
rc_update_deptree (true);
|
||||||
if (! update)
|
update = true;
|
||||||
{
|
}
|
||||||
rc_update_deptree (true);
|
continue;
|
||||||
update = true;
|
}
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--strict") == 0)
|
if (strcmp (argv[i], "--strict") == 0) {
|
||||||
{
|
options |= RC_DEP_STRICT;
|
||||||
options |= RC_DEP_STRICT;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp (argv[i], "--notrace") == 0)
|
if (strcmp (argv[i], "--notrace") == 0) {
|
||||||
{
|
options &= RC_DEP_TRACE;
|
||||||
options &= RC_DEP_TRACE;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (argv[i][0] == '-')
|
if (argv[i][0] == '-') {
|
||||||
{
|
argv[i]++;
|
||||||
argv[i]++;
|
types = rc_strlist_add (types, argv[i]);
|
||||||
types = rc_strlist_add (types, argv[i]);
|
} else {
|
||||||
}
|
if ((deptree = rc_load_deptree ()) == NULL)
|
||||||
else
|
eerrorx ("failed to load deptree");
|
||||||
{
|
|
||||||
if ((deptree = rc_load_deptree ()) == NULL)
|
|
||||||
eerrorx ("failed to load deptree");
|
|
||||||
|
|
||||||
di = rc_get_depinfo (deptree, argv[i]);
|
di = rc_get_depinfo (deptree, argv[i]);
|
||||||
if (! di)
|
if (! di)
|
||||||
eerror ("no dependency info for service `%s'", argv[i]);
|
eerror ("no dependency info for service `%s'", argv[i]);
|
||||||
else
|
else
|
||||||
services = rc_strlist_add (services, argv[i]);
|
services = rc_strlist_add (services, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! services)
|
if (! services) {
|
||||||
{
|
rc_strlist_free (types);
|
||||||
rc_strlist_free (types);
|
rc_free_deptree (deptree);
|
||||||
rc_free_deptree (deptree);
|
if (update)
|
||||||
if (update)
|
return (EXIT_SUCCESS);
|
||||||
return (EXIT_SUCCESS);
|
eerrorx ("no services specified");
|
||||||
eerrorx ("no services specified");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* If we don't have any types, then supply some defaults */
|
/* If we don't have any types, then supply some defaults */
|
||||||
if (! types)
|
if (! types) {
|
||||||
{
|
types = rc_strlist_add (NULL, "ineed");
|
||||||
types = rc_strlist_add (NULL, "ineed");
|
rc_strlist_add (types, "iuse");
|
||||||
rc_strlist_add (types, "iuse");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
depends = rc_get_depends (deptree, types, services, runlevel, options);
|
depends = rc_get_depends (deptree, types, services, runlevel, options);
|
||||||
|
|
||||||
if (depends)
|
if (depends) {
|
||||||
{
|
STRLIST_FOREACH (depends, service, i) {
|
||||||
STRLIST_FOREACH (depends, service, i)
|
if (first)
|
||||||
{
|
first = false;
|
||||||
if (first)
|
else
|
||||||
first = false;
|
printf (" ");
|
||||||
else
|
|
||||||
printf (" ");
|
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
printf ("%s", service);
|
printf ("%s", service);
|
||||||
|
|
||||||
}
|
}
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
rc_strlist_free (types);
|
rc_strlist_free (types);
|
||||||
rc_strlist_free (services);
|
rc_strlist_free (services);
|
||||||
rc_strlist_free (depends);
|
rc_strlist_free (depends);
|
||||||
rc_free_deptree (deptree);
|
rc_free_deptree (deptree);
|
||||||
|
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
137
src/rc-plugin.c
137
src/rc-plugin.c
@ -19,103 +19,94 @@
|
|||||||
|
|
||||||
typedef struct plugin
|
typedef struct plugin
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
void *handle;
|
void *handle;
|
||||||
int (*hook) (rc_hook_t hook, const char *name);
|
int (*hook) (rc_hook_t hook, const char *name);
|
||||||
struct plugin *next;
|
struct plugin *next;
|
||||||
} plugin_t;
|
} plugin_t;
|
||||||
|
|
||||||
static plugin_t *plugins = NULL;
|
static plugin_t *plugins = NULL;
|
||||||
|
|
||||||
void rc_plugin_load (void)
|
void rc_plugin_load (void)
|
||||||
{
|
{
|
||||||
char **files;
|
char **files;
|
||||||
char *file;
|
char *file;
|
||||||
int i;
|
int i;
|
||||||
plugin_t *plugin = plugins;
|
plugin_t *plugin = plugins;
|
||||||
|
|
||||||
/* Ensure some sanity here */
|
/* Ensure some sanity here */
|
||||||
rc_plugin_unload ();
|
rc_plugin_unload ();
|
||||||
|
|
||||||
if (! rc_exists (RC_PLUGINDIR))
|
if (! rc_exists (RC_PLUGINDIR))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
files = rc_ls_dir (NULL, RC_PLUGINDIR, 0);
|
files = rc_ls_dir (NULL, RC_PLUGINDIR, 0);
|
||||||
STRLIST_FOREACH (files, file, i)
|
STRLIST_FOREACH (files, file, i) {
|
||||||
{
|
char *p = rc_strcatpaths (RC_PLUGINDIR, file, NULL);
|
||||||
char *p = rc_strcatpaths (RC_PLUGINDIR, file, NULL);
|
void *h = dlopen (p, RTLD_LAZY);
|
||||||
void *h = dlopen (p, RTLD_LAZY);
|
char *func;
|
||||||
char *func;
|
void *f;
|
||||||
void *f;
|
int len;
|
||||||
int len;
|
|
||||||
|
|
||||||
if (! h)
|
if (! h) {
|
||||||
{
|
eerror ("dlopen `%s': %s", p, dlerror ());
|
||||||
eerror ("dlopen `%s': %s", p, dlerror ());
|
free (p);
|
||||||
free (p);
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func = file;
|
func = file;
|
||||||
file = strsep (&func, ".");
|
file = strsep (&func, ".");
|
||||||
len = strlen (file) + 7;
|
len = strlen (file) + 7;
|
||||||
func = rc_xmalloc (sizeof (char *) * len);
|
func = rc_xmalloc (sizeof (char *) * len);
|
||||||
snprintf (func, len, "_%s_hook", file);
|
snprintf (func, len, "_%s_hook", file);
|
||||||
|
|
||||||
f = dlsym (h, func);
|
f = dlsym (h, func);
|
||||||
if (! f)
|
if (! f) {
|
||||||
{
|
eerror ("`%s' does not expose the symbol `%s'", p, func);
|
||||||
eerror ("`%s' does not expose the symbol `%s'", p, func);
|
dlclose (h);
|
||||||
dlclose (h);
|
} else {
|
||||||
}
|
if (plugin) {
|
||||||
else
|
plugin->next = rc_xmalloc (sizeof (plugin_t));
|
||||||
{
|
plugin = plugin->next;
|
||||||
if (plugin)
|
} else
|
||||||
{
|
plugin = plugins = rc_xmalloc (sizeof (plugin_t));
|
||||||
plugin->next = rc_xmalloc (sizeof (plugin_t));
|
|
||||||
plugin = plugin->next;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
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 = strdup (file);
|
||||||
plugin->handle = h;
|
plugin->handle = h;
|
||||||
plugin->hook = f;
|
plugin->hook = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (func);
|
free (func);
|
||||||
free (p);
|
free (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc_strlist_free (files);
|
rc_strlist_free (files);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rc_plugin_run (rc_hook_t hook, const char *value)
|
void rc_plugin_run (rc_hook_t hook, const char *value)
|
||||||
{
|
{
|
||||||
plugin_t *plugin = plugins;
|
plugin_t *plugin = plugins;
|
||||||
|
|
||||||
while (plugin)
|
while (plugin) {
|
||||||
{
|
if (plugin->hook)
|
||||||
if (plugin->hook)
|
plugin->hook (hook, value);
|
||||||
plugin->hook (hook, value);
|
|
||||||
|
|
||||||
plugin = plugin->next;
|
plugin = plugin->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rc_plugin_unload (void)
|
void rc_plugin_unload (void)
|
||||||
{
|
{
|
||||||
plugin_t *plugin = plugins;
|
plugin_t *plugin = plugins;
|
||||||
plugin_t *next;
|
plugin_t *next;
|
||||||
|
|
||||||
while (plugin)
|
while (plugin) {
|
||||||
{
|
next = plugin->next;
|
||||||
next = plugin->next;
|
dlclose (plugin->handle);
|
||||||
dlclose (plugin->handle);
|
free (plugin->name);
|
||||||
free (plugin->name);
|
free (plugin);
|
||||||
free (plugin);
|
plugin = next;
|
||||||
plugin = next;
|
}
|
||||||
}
|
plugins = NULL;
|
||||||
plugins = NULL;
|
|
||||||
}
|
}
|
||||||
|
197
src/rc-status.c
197
src/rc-status.c
@ -18,125 +18,112 @@
|
|||||||
|
|
||||||
static void print_level (char *level)
|
static void print_level (char *level)
|
||||||
{
|
{
|
||||||
printf ("Runlevel: ");
|
printf ("Runlevel: ");
|
||||||
PEINFO_HILITE;
|
PEINFO_HILITE;
|
||||||
printf ("%s\n", level);
|
printf ("%s\n", level);
|
||||||
PEINFO_NORMAL;
|
PEINFO_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_service (char *service)
|
static void print_service (char *service)
|
||||||
{
|
{
|
||||||
char status[10];
|
char status[10];
|
||||||
int cols = printf (" %s\n", service);
|
int cols = printf (" %s\n", service);
|
||||||
einfo_color_t color = einfo_bad;
|
einfo_color_t color = einfo_bad;
|
||||||
|
|
||||||
if (rc_service_state (service, rc_service_stopping))
|
if (rc_service_state (service, rc_service_stopping))
|
||||||
snprintf (status, sizeof (status), "stopping ");
|
snprintf (status, sizeof (status), "stopping ");
|
||||||
else if (rc_service_state (service, rc_service_starting))
|
else if (rc_service_state (service, rc_service_starting)) {
|
||||||
{
|
snprintf (status, sizeof (status), "starting ");
|
||||||
snprintf (status, sizeof (status), "starting ");
|
color = einfo_warn;
|
||||||
color = einfo_warn;
|
} else if (rc_service_state (service, rc_service_inactive)) {
|
||||||
}
|
snprintf (status, sizeof (status), "inactive ");
|
||||||
else if (rc_service_state (service, rc_service_inactive))
|
color = einfo_warn;
|
||||||
{
|
} else if (geteuid () == 0 && rc_service_state (service, rc_service_crashed))
|
||||||
snprintf (status, sizeof (status), "inactive ");
|
snprintf (status, sizeof (status), " crashed ");
|
||||||
color = einfo_warn;
|
else if (rc_service_state (service, rc_service_started)) {
|
||||||
}
|
snprintf (status, sizeof (status), " started ");
|
||||||
else if (geteuid () == 0 && rc_service_state (service, rc_service_crashed))
|
color = einfo_good;
|
||||||
snprintf (status, sizeof (status), " crashed ");
|
} else if (rc_service_state (service, rc_service_scheduled)) {
|
||||||
else if (rc_service_state (service, rc_service_started))
|
snprintf (status, sizeof (status), "scheduled");
|
||||||
{
|
color = einfo_warn;
|
||||||
snprintf (status, sizeof (status), " started ");
|
} else
|
||||||
color = einfo_good;
|
snprintf (status, sizeof (status), " stopped ");
|
||||||
}
|
ebracket (cols, color, status);
|
||||||
else if (rc_service_state (service, rc_service_scheduled))
|
|
||||||
{
|
|
||||||
snprintf (status, sizeof (status), "scheduled");
|
|
||||||
color = einfo_warn;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
snprintf (status, sizeof (status), " stopped ");
|
|
||||||
ebracket (cols, color, status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char **levels = NULL;
|
char **levels = NULL;
|
||||||
char **services = NULL;
|
char **services = NULL;
|
||||||
char *level;
|
char *level;
|
||||||
char *service;
|
char *service;
|
||||||
char c;
|
char c;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
const struct option longopts[] =
|
const struct option longopts[] = {
|
||||||
{
|
{"all", no_argument, NULL, 'a'},
|
||||||
{"all", no_argument, NULL, 'a'},
|
{"list", no_argument, NULL, 'l'},
|
||||||
{"list", no_argument, NULL, 'l'},
|
{"servicelist", no_argument, NULL, 's'},
|
||||||
{"servicelist", no_argument, NULL, 's'},
|
{"unused", no_argument, NULL, 'u'},
|
||||||
{"unused", no_argument, NULL, 'u'},
|
{NULL, 0, NULL, 0}
|
||||||
{NULL, 0, NULL, 0}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "alsu", longopts, &option_index)) != -1)
|
while ((c = getopt_long(argc, argv, "alsu", longopts, &option_index)) != -1)
|
||||||
switch (c)
|
switch (c) {
|
||||||
{
|
case 'a':
|
||||||
case 'a':
|
levels = rc_get_runlevels ();
|
||||||
levels = rc_get_runlevels ();
|
break;
|
||||||
break;
|
case 'l':
|
||||||
case 'l':
|
levels = rc_get_runlevels ();
|
||||||
levels = rc_get_runlevels ();
|
STRLIST_FOREACH (levels, level, i)
|
||||||
STRLIST_FOREACH (levels, level, i)
|
printf ("%s\n", level);
|
||||||
printf ("%s\n", level);
|
rc_strlist_free (levels);
|
||||||
rc_strlist_free (levels);
|
exit (EXIT_SUCCESS);
|
||||||
exit (EXIT_SUCCESS);
|
case 's':
|
||||||
case 's':
|
services = rc_services_in_runlevel (NULL);
|
||||||
services = rc_services_in_runlevel (NULL);
|
STRLIST_FOREACH (services, service, i)
|
||||||
STRLIST_FOREACH (services, service, i)
|
print_service (service);
|
||||||
print_service (service);
|
rc_strlist_free (services);
|
||||||
rc_strlist_free (services);
|
exit (EXIT_SUCCESS);
|
||||||
exit (EXIT_SUCCESS);
|
case 'u':
|
||||||
case 'u':
|
services = rc_services_in_runlevel (NULL);
|
||||||
services = rc_services_in_runlevel (NULL);
|
levels = rc_get_runlevels ();
|
||||||
levels = rc_get_runlevels ();
|
STRLIST_FOREACH (services, service, i) {
|
||||||
STRLIST_FOREACH (services, service, i)
|
bool found = false;
|
||||||
{
|
STRLIST_FOREACH (levels, level, j)
|
||||||
bool found = false;
|
if (rc_service_in_runlevel (service, level)) {
|
||||||
STRLIST_FOREACH (levels, level, j)
|
found = true;
|
||||||
if (rc_service_in_runlevel (service, level))
|
break;
|
||||||
{
|
}
|
||||||
found = true;
|
if (! found)
|
||||||
break;
|
print_service (service);
|
||||||
}
|
}
|
||||||
if (! found)
|
rc_strlist_free (levels);
|
||||||
print_service (service);
|
rc_strlist_free (services);
|
||||||
}
|
exit (EXIT_SUCCESS);
|
||||||
rc_strlist_free (levels);
|
case '?':
|
||||||
rc_strlist_free (services);
|
exit (EXIT_FAILURE);
|
||||||
exit (EXIT_SUCCESS);
|
default:
|
||||||
case '?':
|
exit (EXIT_FAILURE);
|
||||||
exit (EXIT_FAILURE);
|
}
|
||||||
default:
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (optind < argc)
|
while (optind < argc)
|
||||||
levels = rc_strlist_add (levels, argv[optind++]);
|
levels = rc_strlist_add (levels, argv[optind++]);
|
||||||
|
|
||||||
if (! levels)
|
if (! levels)
|
||||||
levels = rc_strlist_add (NULL, rc_get_runlevel ());
|
levels = rc_strlist_add (NULL, rc_get_runlevel ());
|
||||||
|
|
||||||
STRLIST_FOREACH (levels, level, i)
|
STRLIST_FOREACH (levels, level, i) {
|
||||||
{
|
print_level (level);
|
||||||
print_level (level);
|
services = rc_services_in_runlevel (level);
|
||||||
services = rc_services_in_runlevel (level);
|
STRLIST_FOREACH (services, service, j)
|
||||||
STRLIST_FOREACH (services, service, j)
|
print_service (service);
|
||||||
print_service (service);
|
rc_strlist_free (services);
|
||||||
rc_strlist_free (services);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
rc_strlist_free (levels);
|
rc_strlist_free (levels);
|
||||||
|
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
211
src/rc-update.c
211
src/rc-update.c
@ -22,141 +22,130 @@ static char *applet = NULL;
|
|||||||
|
|
||||||
static bool add (const char *runlevel, const char *service)
|
static bool add (const char *runlevel, const char *service)
|
||||||
{
|
{
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
|
|
||||||
if (! rc_runlevel_exists (runlevel))
|
if (! rc_runlevel_exists (runlevel)) {
|
||||||
{
|
ewarn ("runlevel `%s' does not exist", runlevel);
|
||||||
ewarn ("runlevel `%s' does not exist", runlevel);
|
return (false);
|
||||||
return (false);
|
}
|
||||||
}
|
if (rc_service_in_runlevel (service, runlevel)) {
|
||||||
if (rc_service_in_runlevel (service, runlevel))
|
ewarn ("%s already installed in runlevel `%s'; skipping",
|
||||||
{
|
service, runlevel);
|
||||||
ewarn ("%s already installed in runlevel `%s'; skipping",
|
return (false);
|
||||||
service, runlevel);
|
}
|
||||||
return (false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc_service_add (runlevel, service))
|
if (rc_service_add (runlevel, service))
|
||||||
einfo ("%s added to runlevel %s", service, runlevel);
|
einfo ("%s added to runlevel %s", service, runlevel);
|
||||||
else
|
else {
|
||||||
{
|
eerror ("%s: failed to add service `%s' to runlevel `%s': %s",
|
||||||
eerror ("%s: failed to add service `%s' to runlevel `%s': %s",
|
applet, service, runlevel, strerror (errno));
|
||||||
applet, service, runlevel, strerror (errno));
|
retval = false;
|
||||||
retval = false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
char *service;
|
char *service;
|
||||||
char **runlevels = NULL;
|
char **runlevels = NULL;
|
||||||
char *runlevel;
|
char *runlevel;
|
||||||
|
|
||||||
applet = argv[0];
|
applet = argv[0];
|
||||||
if (argc < 2 ||
|
if (argc < 2 ||
|
||||||
strcmp (argv[1], "show") == 0 ||
|
strcmp (argv[1], "show") == 0 ||
|
||||||
strcmp (argv[1], "-s") == 0)
|
strcmp (argv[1], "-s") == 0)
|
||||||
{
|
{
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
char **services = rc_services_in_runlevel (NULL);
|
char **services = rc_services_in_runlevel (NULL);
|
||||||
|
|
||||||
for (i = 2; i < argc; i++)
|
for (i = 2; i < argc; i++) {
|
||||||
{
|
if (strcmp (argv[i], "--verbose") == 0 ||
|
||||||
if (strcmp (argv[i], "--verbose") == 0 ||
|
strcmp (argv[i], "-v") == 0)
|
||||||
strcmp (argv[i], "-v") == 0)
|
verbose = true;
|
||||||
verbose = true;
|
else
|
||||||
else
|
runlevels = rc_strlist_add (runlevels, argv[i]);
|
||||||
runlevels = rc_strlist_add (runlevels, argv[i]);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (! runlevels)
|
if (! runlevels)
|
||||||
runlevels = rc_get_runlevels ();
|
runlevels = rc_get_runlevels ();
|
||||||
|
|
||||||
STRLIST_FOREACH (services, service, i)
|
STRLIST_FOREACH (services, service, i) {
|
||||||
{
|
char **in = NULL;
|
||||||
char **in = NULL;
|
bool inone = false;
|
||||||
bool inone = false;
|
|
||||||
|
|
||||||
STRLIST_FOREACH (runlevels, runlevel, j)
|
STRLIST_FOREACH (runlevels, runlevel, j) {
|
||||||
{
|
if (rc_service_in_runlevel (service, runlevel)) {
|
||||||
if (rc_service_in_runlevel (service, runlevel))
|
in = rc_strlist_add (in, runlevel);
|
||||||
{
|
inone = true;
|
||||||
in = rc_strlist_add (in, runlevel);
|
} else {
|
||||||
inone = true;
|
char buffer[PATH_MAX];
|
||||||
}
|
memset (buffer, ' ', strlen (runlevel));
|
||||||
else
|
buffer[strlen (runlevel)] = 0;
|
||||||
{
|
in = rc_strlist_add (in, buffer);
|
||||||
char buffer[PATH_MAX];
|
}
|
||||||
memset (buffer, ' ', strlen (runlevel));
|
}
|
||||||
buffer[strlen (runlevel)] = 0;
|
|
||||||
in = rc_strlist_add (in, buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! inone && ! verbose)
|
if (! inone && ! verbose)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
printf (" %20s |", service);
|
printf (" %20s |", service);
|
||||||
STRLIST_FOREACH (in, runlevel, j)
|
STRLIST_FOREACH (in, runlevel, j)
|
||||||
printf (" %s", runlevel);
|
printf (" %s", runlevel);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geteuid () != 0)
|
if (geteuid () != 0)
|
||||||
eerrorx ("%s: must be root to add or delete services from runlevels",
|
eerrorx ("%s: must be root to add or delete services from runlevels",
|
||||||
applet);
|
applet);
|
||||||
|
|
||||||
if (! (service = argv[2]))
|
if (! (service = argv[2]))
|
||||||
eerrorx ("%s: no service specified", applet);
|
eerrorx ("%s: no service specified", applet);
|
||||||
|
|
||||||
if (strcmp (argv[1], "add") == 0 ||
|
if (strcmp (argv[1], "add") == 0 ||
|
||||||
strcmp (argv[1], "-a") == 0)
|
strcmp (argv[1], "-a") == 0)
|
||||||
{
|
{
|
||||||
if (! service)
|
if (! service)
|
||||||
eerrorx ("%s: no service specified", applet);
|
eerrorx ("%s: no service specified", applet);
|
||||||
if (! rc_service_exists (service))
|
if (! rc_service_exists (service))
|
||||||
eerrorx ("%s: service `%s' does not exist", applet, service);
|
eerrorx ("%s: service `%s' does not exist", applet, service);
|
||||||
|
|
||||||
if (argc < 4)
|
if (argc < 4)
|
||||||
add (rc_get_runlevel (), service);
|
add (rc_get_runlevel (), service);
|
||||||
|
|
||||||
for (i = 3; i < argc; i++)
|
for (i = 3; i < argc; i++)
|
||||||
add (argv[i], service);
|
add (argv[i], service);
|
||||||
|
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (argv[1], "delete") == 0 ||
|
if (strcmp (argv[1], "delete") == 0 ||
|
||||||
strcmp (argv[1], "del") == 0 ||
|
strcmp (argv[1], "del") == 0 ||
|
||||||
strcmp (argv[1], "-d") == 0)
|
strcmp (argv[1], "-d") == 0)
|
||||||
{
|
{
|
||||||
for (i = 3; i < argc; i++)
|
for (i = 3; i < argc; i++)
|
||||||
runlevels = rc_strlist_add (runlevels, argv[i]);
|
runlevels = rc_strlist_add (runlevels, argv[i]);
|
||||||
|
|
||||||
if (! runlevels)
|
if (! runlevels)
|
||||||
runlevels = rc_strlist_add (runlevels, rc_get_runlevel ());
|
runlevels = rc_strlist_add (runlevels, rc_get_runlevel ());
|
||||||
|
|
||||||
STRLIST_FOREACH (runlevels, runlevel, i)
|
STRLIST_FOREACH (runlevels, runlevel, i) {
|
||||||
{
|
if (rc_service_in_runlevel (service, runlevel)) {
|
||||||
if (rc_service_in_runlevel (service, runlevel))
|
if (rc_service_delete (runlevel, service))
|
||||||
{
|
einfo ("%s removed from runlevel %s", service, runlevel);
|
||||||
if (rc_service_delete (runlevel, service))
|
else
|
||||||
einfo ("%s removed from runlevel %s", service, runlevel);
|
eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
|
||||||
else
|
applet, service, runlevel, strerror (errno));
|
||||||
eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
|
}
|
||||||
applet, service, runlevel, strerror (errno));
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
eerrorx ("%s: unknown command `%s'", applet, argv[1]);
|
eerrorx ("%s: unknown command `%s'", applet, argv[1]);
|
||||||
}
|
}
|
||||||
|
76
src/rc.h
76
src/rc.h
@ -25,16 +25,16 @@
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
rc_service_started,
|
rc_service_started,
|
||||||
rc_service_stopped,
|
rc_service_stopped,
|
||||||
rc_service_starting,
|
rc_service_starting,
|
||||||
rc_service_stopping,
|
rc_service_stopping,
|
||||||
rc_service_inactive,
|
rc_service_inactive,
|
||||||
rc_service_wasinactive,
|
rc_service_wasinactive,
|
||||||
rc_service_coldplugged,
|
rc_service_coldplugged,
|
||||||
rc_service_failed,
|
rc_service_failed,
|
||||||
rc_service_scheduled,
|
rc_service_scheduled,
|
||||||
rc_service_crashed
|
rc_service_crashed
|
||||||
} rc_service_state_t;
|
} rc_service_state_t;
|
||||||
|
|
||||||
char *rc_resolve_service (const char *service);
|
char *rc_resolve_service (const char *service);
|
||||||
@ -45,19 +45,19 @@ bool rc_mark_service (const char *service, rc_service_state_t state);
|
|||||||
pid_t rc_stop_service (const char *service);
|
pid_t rc_stop_service (const char *service);
|
||||||
pid_t rc_start_service (const char *service);
|
pid_t rc_start_service (const char *service);
|
||||||
void rc_schedule_start_service (const char *service,
|
void rc_schedule_start_service (const char *service,
|
||||||
const char *service_to_start);
|
const char *service_to_start);
|
||||||
char **rc_services_scheduled_by (const char *service);
|
char **rc_services_scheduled_by (const char *service);
|
||||||
void rc_schedule_clear (const char *service);
|
void rc_schedule_clear (const char *service);
|
||||||
bool rc_wait_service (const char *service);
|
bool rc_wait_service (const char *service);
|
||||||
bool rc_get_service_option (const char *service, const char *option,
|
bool rc_get_service_option (const char *service, const char *option,
|
||||||
char *value);
|
char *value);
|
||||||
bool rc_set_service_option (const char *service, const char *option,
|
bool rc_set_service_option (const char *service, const char *option,
|
||||||
const char *value);
|
const char *value);
|
||||||
void rc_set_service_daemon (const char *service, const char *exec,
|
void rc_set_service_daemon (const char *service, const char *exec,
|
||||||
const char *name, const char *pidfile,
|
const char *name, const char *pidfile,
|
||||||
bool started);
|
bool started);
|
||||||
bool rc_service_started_daemon (const char *service, const char *exec,
|
bool rc_service_started_daemon (const char *service, const char *exec,
|
||||||
int indx);
|
int indx);
|
||||||
|
|
||||||
bool rc_allow_plug (char *service);
|
bool rc_allow_plug (char *service);
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ char **rc_services_scheduled (const char *service);
|
|||||||
|
|
||||||
/* Find pids based on criteria - free the pointer returned after use */
|
/* Find pids based on criteria - free the pointer returned after use */
|
||||||
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
||||||
uid_t uid, pid_t pid);
|
uid_t uid, pid_t pid);
|
||||||
/* Checks that all daemons started with start-stop-daemon by the service
|
/* Checks that all daemons started with start-stop-daemon by the service
|
||||||
are still running. If so, return false otherwise true.
|
are still running. If so, return false otherwise true.
|
||||||
You should check that the service has been started before calling this. */
|
You should check that the service has been started before calling this. */
|
||||||
@ -84,16 +84,16 @@ bool rc_service_daemons_crashed (const char *service);
|
|||||||
/* Dependency tree structs and functions. */
|
/* Dependency tree structs and functions. */
|
||||||
typedef struct rc_deptype
|
typedef struct rc_deptype
|
||||||
{
|
{
|
||||||
char *type;
|
char *type;
|
||||||
char **services;
|
char **services;
|
||||||
struct rc_deptype *next;
|
struct rc_deptype *next;
|
||||||
} rc_deptype_t;
|
} rc_deptype_t;
|
||||||
|
|
||||||
typedef struct rc_depinfo
|
typedef struct rc_depinfo
|
||||||
{
|
{
|
||||||
char *service;
|
char *service;
|
||||||
rc_deptype_t *depends;
|
rc_deptype_t *depends;
|
||||||
struct rc_depinfo *next;
|
struct rc_depinfo *next;
|
||||||
} rc_depinfo_t;
|
} rc_depinfo_t;
|
||||||
|
|
||||||
|
|
||||||
@ -110,14 +110,14 @@ rc_depinfo_t *rc_load_deptree (void);
|
|||||||
rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
|
rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
|
||||||
rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
|
rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
|
||||||
char **rc_get_depends (rc_depinfo_t *deptree, char **types,
|
char **rc_get_depends (rc_depinfo_t *deptree, char **types,
|
||||||
char **services, const char *runlevel, int options);
|
char **services, const char *runlevel, int options);
|
||||||
/* List all the services that should be started, in order, the the
|
/* List all the services that should be started, in order, the the
|
||||||
given runlevel, including sysinit and boot services where
|
given runlevel, including sysinit and boot services where
|
||||||
approriate.
|
approriate.
|
||||||
If reboot, shutdown or single are given then we list all the services
|
If reboot, shutdown or single are given then we list all the services
|
||||||
we that we need to shutdown in order. */
|
we that we need to shutdown in order. */
|
||||||
char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
|
char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
|
||||||
int options);
|
int options);
|
||||||
|
|
||||||
void rc_free_deptree (rc_depinfo_t *deptree);
|
void rc_free_deptree (rc_depinfo_t *deptree);
|
||||||
|
|
||||||
@ -134,19 +134,19 @@ void rc_free_deptree (rc_depinfo_t *deptree);
|
|||||||
when we have done it as may start scheduled services at this point. */
|
when we have done it as may start scheduled services at this point. */
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
rc_hook_runlevel_stop_in = 1,
|
rc_hook_runlevel_stop_in = 1,
|
||||||
rc_hook_runlevel_stop_out = 4,
|
rc_hook_runlevel_stop_out = 4,
|
||||||
rc_hook_runlevel_start_in = 5,
|
rc_hook_runlevel_start_in = 5,
|
||||||
rc_hook_runlevel_start_out = 8,
|
rc_hook_runlevel_start_out = 8,
|
||||||
/* We reserved a few numbers if we need rc_runlevel_stop_now and done */
|
/* We reserved a few numbers if we need rc_runlevel_stop_now and done */
|
||||||
rc_hook_service_stop_in = 101,
|
rc_hook_service_stop_in = 101,
|
||||||
rc_hook_service_stop_now,
|
rc_hook_service_stop_now,
|
||||||
rc_hook_service_stop_done,
|
rc_hook_service_stop_done,
|
||||||
rc_hook_service_stop_out,
|
rc_hook_service_stop_out,
|
||||||
rc_hook_service_start_in,
|
rc_hook_service_start_in,
|
||||||
rc_hook_service_start_now,
|
rc_hook_service_start_now,
|
||||||
rc_hook_service_start_done,
|
rc_hook_service_start_done,
|
||||||
rc_hook_service_start_out
|
rc_hook_service_start_out
|
||||||
} rc_hook_t;
|
} rc_hook_t;
|
||||||
|
|
||||||
/* RC utility functions.
|
/* RC utility functions.
|
||||||
|
1639
src/runscript.c
1639
src/runscript.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@
|
|||||||
it should usually by +1 from what you expect, and should only be
|
it should usually by +1 from what you expect, and should only be
|
||||||
used in the scope of the macro) */
|
used in the scope of the macro) */
|
||||||
#define STRLIST_FOREACH(_list, _pos, _counter) \
|
#define STRLIST_FOREACH(_list, _pos, _counter) \
|
||||||
if ((_list) && _list[0] && ! (_counter = 0)) \
|
if ((_list) && _list[0] && ! (_counter = 0)) \
|
||||||
while ((_pos = _list[_counter++]))
|
while ((_pos = _list[_counter++]))
|
||||||
|
|
||||||
#endif /* __STRLIST_H__ */
|
#endif /* __STRLIST_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user