Add --nocolor to more programs
This commit is contained in:
parent
10c3592147
commit
0fdc53d54d
@ -17,6 +17,3 @@ static void usage (int exit_status)
|
|||||||
exit (exit_status);
|
exit (exit_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define case_RC_COMMON_GETOPT \
|
|
||||||
case 'h': usage (EXIT_SUCCESS); \
|
|
||||||
default: usage (EXIT_FAILURE);
|
|
||||||
|
@ -61,10 +61,11 @@ static const char *space_separated[] = {
|
|||||||
|
|
||||||
static char *applet = NULL;
|
static char *applet = NULL;
|
||||||
|
|
||||||
#define getoptstring "hL"
|
#include "_usage.h"
|
||||||
|
#define getoptstring "L" getoptstring_COMMON
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{ "help", 0, NULL, 'h'},
|
|
||||||
{ "no-ldconfig", 0, NULL, 'L'},
|
{ "no-ldconfig", 0, NULL, 'L'},
|
||||||
|
longopts_COMMON
|
||||||
{ NULL, 0, NULL, 0}
|
{ NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
#include "_usage.c"
|
#include "_usage.c"
|
||||||
@ -98,12 +99,11 @@ int main (int argc, char **argv)
|
|||||||
case 'L':
|
case 'L':
|
||||||
ldconfig = false;
|
ldconfig = false;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
|
||||||
usage (EXIT_SUCCESS);
|
case_RC_COMMON_GETOPT
|
||||||
default:
|
|
||||||
usage (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! files)
|
if (! files)
|
||||||
eerrorx ("%s: no files in " ENVDIR " to process", applet);
|
eerrorx ("%s: no files in " ENVDIR " to process", applet);
|
||||||
|
|
||||||
|
@ -56,13 +56,14 @@ static struct mntent *getmntfile (FILE *fp, const char *file)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define getoptstring "f:m:o:p:h"
|
#include "_usage.h"
|
||||||
|
#define getoptstring "f:m:o:p:" getoptstring_COMMON
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{ "fstype", 1, NULL, 'f'},
|
{ "fstype", 1, NULL, 'f'},
|
||||||
{ "mountcmd", 1, NULL, 'm'},
|
{ "mountcmd", 1, NULL, 'm'},
|
||||||
{ "opts", 1, NULL, 'o'},
|
{ "opts", 1, NULL, 'o'},
|
||||||
{ "passno", 1, NULL, 'p'},
|
{ "passno", 1, NULL, 'p'},
|
||||||
{ "help", 0, NULL, 'h'},
|
longopts_COMMON
|
||||||
{ NULL, 0, NULL, 0}
|
{ NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
#include "_usage.c"
|
#include "_usage.c"
|
||||||
@ -139,12 +140,7 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case_RC_COMMON_GETOPT
|
||||||
END_ENT;
|
|
||||||
usage (EXIT_SUCCESS);
|
|
||||||
default:
|
|
||||||
END_ENT;
|
|
||||||
usage (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
END_ENT;
|
END_ENT;
|
||||||
|
@ -149,14 +149,14 @@ static bool colour_terminal (void)
|
|||||||
static int in_colour = -1;
|
static int in_colour = -1;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
if (is_env ("RC_NOCOLOR", "yes"))
|
||||||
|
return (false);
|
||||||
|
|
||||||
if (in_colour == 0)
|
if (in_colour == 0)
|
||||||
return (false);
|
return (false);
|
||||||
if (in_colour == 1)
|
if (in_colour == 1)
|
||||||
return (true);
|
return (true);
|
||||||
|
|
||||||
if (is_env ("RC_NOCOLOR", "yes"))
|
|
||||||
return (false);
|
|
||||||
|
|
||||||
if (! term) {
|
if (! term) {
|
||||||
term = getenv ("TERM");
|
term = getenv ("TERM");
|
||||||
if (! term)
|
if (! term)
|
||||||
|
@ -130,7 +130,8 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
|
|||||||
# error "Operating system not supported!"
|
# error "Operating system not supported!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define getoptstring "F:N:S:fnrhV"
|
#include "_usage.h"
|
||||||
|
#define getoptstring "F:N:S:fnrV" getoptstring_COMMON
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{ "fstype-regex", 1, NULL, 'F'},
|
{ "fstype-regex", 1, NULL, 'F'},
|
||||||
{ "node-regex", 1, NULL, 'N'},
|
{ "node-regex", 1, NULL, 'N'},
|
||||||
@ -138,7 +139,7 @@ static struct option longopts[] = {
|
|||||||
{ "fstype", 0, NULL, 'f'},
|
{ "fstype", 0, NULL, 'f'},
|
||||||
{ "node", 0, NULL, 'n'},
|
{ "node", 0, NULL, 'n'},
|
||||||
{ "reverse", 0, NULL, 'r'},
|
{ "reverse", 0, NULL, 'r'},
|
||||||
{ "help", 0, NULL, 'h'},
|
longopts_COMMON
|
||||||
{ NULL, 0, NULL, 0}
|
{ NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
#include "_usage.c"
|
#include "_usage.c"
|
||||||
|
@ -53,13 +53,14 @@ static void print_service (char *service)
|
|||||||
ebracket (cols, color, status);
|
ebracket (cols, color, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define getoptstring "alsuh"
|
#include "_usage.h"
|
||||||
|
#define getoptstring "alsu" getoptstring_COMMON
|
||||||
const struct option longopts[] = {
|
const struct option longopts[] = {
|
||||||
{"all", 0, NULL, 'a'},
|
{"all", 0, NULL, 'a'},
|
||||||
{"list", 0, NULL, 'l'},
|
{"list", 0, NULL, 'l'},
|
||||||
{"servicelist", 0, NULL, 's'},
|
{"servicelist", 0, NULL, 's'},
|
||||||
{"unused", 0, NULL, 'u'},
|
{"unused", 0, NULL, 'u'},
|
||||||
{"help", 0, NULL, 'h'},
|
longopts_COMMON
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
#include "_usage.c"
|
#include "_usage.c"
|
||||||
|
35
src/rc.c
35
src/rc.c
@ -11,12 +11,15 @@
|
|||||||
Released under the GPLv2
|
Released under the GPLv2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define APPLET "rc"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -600,6 +603,14 @@ static void run_script (const char *script) {
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "_usage.h"
|
||||||
|
#define getoptstring getoptstring_COMMON
|
||||||
|
static struct option longopts[] = {
|
||||||
|
longopts_COMMON
|
||||||
|
{ NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
#include "_usage.c"
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *RUNLEVEL = NULL;
|
char *RUNLEVEL = NULL;
|
||||||
@ -615,6 +626,7 @@ int main (int argc, char **argv)
|
|||||||
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
|
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
|
||||||
char ksoftbuffer [PATH_MAX];
|
char ksoftbuffer [PATH_MAX];
|
||||||
char pidstr[6];
|
char pidstr[6];
|
||||||
|
int opt;
|
||||||
|
|
||||||
if (argv[0])
|
if (argv[0])
|
||||||
applet = rc_xstrdup (basename (argv[0]));
|
applet = rc_xstrdup (basename (argv[0]));
|
||||||
@ -660,13 +672,7 @@ int main (int argc, char **argv)
|
|||||||
if (strcmp (applet, "rc" ) != 0)
|
if (strcmp (applet, "rc" ) != 0)
|
||||||
eerrorx ("%s: unknown applet", applet);
|
eerrorx ("%s: unknown applet", applet);
|
||||||
|
|
||||||
/* OK, so we really are the main RC process
|
|
||||||
Only root should be able to run us */
|
|
||||||
if (geteuid () != 0)
|
|
||||||
eerrorx ("%s: root access required", applet);
|
|
||||||
|
|
||||||
atexit (cleanup);
|
atexit (cleanup);
|
||||||
newlevel = argv[0];
|
|
||||||
|
|
||||||
/* Change dir to / to ensure all scripts don't use stuff in pwd */
|
/* Change dir to / to ensure all scripts don't use stuff in pwd */
|
||||||
chdir ("/");
|
chdir ("/");
|
||||||
@ -712,6 +718,23 @@ int main (int argc, char **argv)
|
|||||||
/* We don't free our list as that would be null in environ */
|
/* We don't free our list as that would be null in environ */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
argc++;
|
||||||
|
argv--;
|
||||||
|
while ((opt = getopt_long (argc, argv, getoptstring,
|
||||||
|
longopts, (int *) 0)) != -1)
|
||||||
|
{
|
||||||
|
switch (opt) {
|
||||||
|
case_RC_COMMON_GETOPT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newlevel = argv[optind++];
|
||||||
|
|
||||||
|
/* OK, so we really are the main RC process
|
||||||
|
Only root should be able to run us */
|
||||||
|
if (geteuid () != 0)
|
||||||
|
eerrorx ("%s: root access required", applet);
|
||||||
|
|
||||||
/* Enable logging */
|
/* Enable logging */
|
||||||
setenv ("RC_ELOG", "rc", 1);
|
setenv ("RC_ELOG", "rc", 1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user