aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/src/main.c b/src/main.c
index 2a20ba9..9b98ec5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -75,18 +75,18 @@ static int import_option;
static int read_option;
static int list_option;
static char *check_mode = 0;
static char *user_option = NULL;
static char *html_template_option = NULL;
const char *program_version = "tagr (" PACKAGE_STRING ")";
-static char doc[] = "tagr -- traffic analyzer and grapher";
-static char args_doc[] = "";
+static char doc[] = N_("tagr -- traffic analyzer and grapher");
+static char args_doc[] = "[FILES or DIRS...]";
enum {
OPT_IMPORT = 256,
OPT_TEST_TEMPLATE,
OPT_SHOW_DEFAULTS,
OPT_SYSLOG,
OPT_STDERR,
OPT_PREPROCESSOR,
@@ -107,17 +107,17 @@ static struct argp_option options[] = {
N_("preprocess configuration file and exit"),
GRID+1},
{"test-template", OPT_TEST_TEMPLATE, NULL, 0,
N_("test page template file syntax"), GRID+1},
{"import", OPT_IMPORT, NULL, 0,
N_("import old (mrtg-style) log files from DIR (or the basedir, if not given)"),
GRID+1 },
{"read", OPT_READ, NULL, 0,
- N_("read statistics from the given file or standard input") },
+ N_("read statistics from given FILEs or standard input") },
{"rebuild", 'b', NULL, 0,
N_("rebuild graphs using existing statistics"), GRID+1},
{"list", 'l', NULL, 0, N_("list contents of the rate database"), GRID+1},
{"show-defaults", OPT_SHOW_DEFAULTS, NULL, 0,
N_("Show configuration default values"), GRID+1},
#undef GRID
#define GRID 20
@@ -182,22 +182,22 @@ static struct argp_option options[] = {
#undef GRID
{NULL}
};
static void
show_defaults ()
{
- printf ("Configuration file: %s\n", TAGR_CONFIGFILE);
- printf ("Page template file: %s\n", TAGR_TEMPLATE);
- printf ("PID file: %s\n", TAGR_PIDFILE);
- printf ("DB file name: %s\n", TAGR_DBNAME);
- printf ("DB file permissions: %#o\n", TAGR_DBMODE);
- printf ("Syslog facility number: %d\n", LOGFACILITY);
+ printf (_("Configuration file: %s\n"), TAGR_CONFIGFILE);
+ printf (_("Page template file: %s\n"), TAGR_TEMPLATE);
+ printf (_("PID file: %s\n"), TAGR_PIDFILE);
+ printf (_("DB file name: %s\n"), TAGR_DBNAME);
+ printf (_("DB file permissions: %#o\n"), TAGR_DBMODE);
+ printf (_("Syslog facility number: %d\n"), LOG_FACILITY);
}
static void
add_check_mode (int c)
{
char s[2];
s[0] = c;
s[1] = 0;
@@ -330,45 +330,46 @@ change_privs (uid_t uid, gid_t gid)
{
int rc = 0;
gid_t emptygidset[1];
/* Reset group permissions */
emptygidset[0] = gid ? gid : getegid ();
if (geteuid () == 0 && setgroups (1, emptygidset))
{
- logmsg (L_ERR, "setgroups(1, %lu) failed: %s",
+ logmsg (L_ERR, _("setgroups(1, %lu) failed: %s"),
(u_long) emptygidset[0], strerror (errno));
rc = 1;
}
/* Switch to the user's gid. On some OSes the effective gid must
be reset first */
#if defined(HAVE_SETEGID)
if ((rc = setegid (gid)) < 0)
- logmsg (L_ERR, "setegid(%lu) failed: %s", (u_long) gid, strerror (errno));
+ logmsg (L_ERR, _("setegid(%lu) failed: %s"),
+ (u_long) gid, strerror (errno));
#elif defined(HAVE_SETREGID)
if ((rc = setregid (gid, gid)) < 0)
- logmsg (L_ERR, "setregid(%lu,%lu) failed: %s",
+ logmsg (L_ERR, _("setregid(%lu,%lu) failed: %s"),
(u_long) gid, (u_long) gid, strerror (errno));
#elif defined(HAVE_SETRESGID)
if ((rc = setresgid (gid, gid, gid)) < 0)
- logmsg (L_ERR, "setresgid(%lu,%lu,%lu) failed: %s",
+ logmsg (L_ERR, _("setresgid(%lu,%lu,%lu) failed: %s"),
(u_long) gid, (u_long) gid, (u_long) gid, strerror (errno));
#endif
if (rc == 0 && gid != 0)
{
if ((rc = setgid (gid)) < 0 && getegid () != gid)
- logmsg (L_ERR, "setgid(%lu) failed: %s",
+ logmsg (L_ERR, _("setgid(%lu) failed: %s"),
(u_long) gid, strerror (errno));
if (rc == 0 && getegid () != gid)
{
- logmsg (L_ERR, "cannot set effective gid to %lu: %s",
+ logmsg (L_ERR, _("cannot set effective gid to %lu: %s"),
(u_long) gid, strerror (errno));
rc = 1;
}
}
/* now reset uid */
if (rc == 0 && uid != 0)
{
@@ -380,66 +381,66 @@ change_privs (uid_t uid, gid_t gid)
{
#if defined(HAVE_SETREUID)
if (geteuid () != uid)
{
if (setreuid (uid, -1) < 0)
{
logmsg (L_ERR,
- "setreuid(%lu,-1) failed: %s",
+ _("setreuid(%lu,-1) failed: %s"),
(u_long) uid, strerror (errno));
rc = 1;
}
if (setuid (uid) < 0)
{
logmsg (L_ERR,
- "second setuid(%lu) failed: %s",
+ _("second setuid(%lu) failed: %s"),
(u_long) uid, strerror (errno));
rc = 1;
}
}
else
#endif
{
- logmsg (L_ERR, "setuid(%lu) failed: %s",
+ logmsg (L_ERR, _("setuid(%lu) failed: %s"),
(u_long) uid, strerror (errno));
rc = 1;
}
}
if (html_template_option)
html_template = html_template_option;
euid = geteuid ();
if (uid != 0 && setuid (0) == 0)
{
- logmsg (L_ERR, "seteuid(0) succeeded when it should not");
+ logmsg (L_ERR, _("seteuid(0) succeeded when it should not"));
rc = 1;
}
else if (uid != euid && setuid (euid) == 0)
{
- logmsg (L_ERR, "cannot drop non-root setuid privileges");
+ logmsg (L_ERR, _("cannot drop non-root setuid privileges"));
rc = 1;
}
}
return rc;
}
void
change_user ()
{
struct passwd *pwd;
if (user == NULL)
return;
if (getuid () == 0)
{
- logmsg (L_NOTICE, "not a superuser: ignoring the `user' statement");
+ logmsg (L_NOTICE, _("not a superuser: ignoring the `user' statement"));
return;
}
pwd = getpwnam (user);
if (pwd)
{
if (change_privs (pwd->pw_uid, pwd->pw_gid))
exit (EX_NOUSER);
@@ -457,52 +458,53 @@ decode_buffer ()
Stat *sp;
int child = 0;
reply = (Stat_reply *) recv_buffer;
reply->n_addr = ntohl (reply->n_addr);
if (reply->n_addr > MAXADDR)
{
- logmsg (L_NOTICE, "got invalid packet: n_addr = %d", reply->n_addr);
+ logmsg (L_NOTICE, _("got invalid packet: n_addr = %d"),
+ reply->n_addr);
return;
}
reply->timestamp = ntohl (reply->timestamp);
if (verbose_level)
{
char tbuf[sizeof("2009-04-01 00:00:00")];
strftime (tbuf, sizeof tbuf, "%Y-%m-%d %H:%M:%S",
gmtime (&reply->timestamp));
- logmsg (L_INFO, "Received packet: %d %lu - %s", reply->n_addr,
+ logmsg (L_INFO, _("Received packet: %d %lu - %s"), reply->n_addr,
(unsigned long) reply->timestamp, tbuf);
}
sp = reply->stat;
if (!single_process_option)
{
pid_t pid = fork ();
if (pid > 0)
return;
else if (pid < 0)
- logmsg (L_ERR, "can't fork: %s", strerror (errno));
+ logmsg (L_ERR, _("cannot fork: %s"), strerror (errno));
else
{
signal (SIGHUP, SIG_IGN);
signal (SIGCHLD, SIG_IGN);
child = 1;
}
}
open_db (TAGR_DB_WR);
for (i = 0; i < reply->n_addr; i++, sp++)
{
sp->in = ntohl (sp->in);
sp->out = ntohl (sp->out);
- verbose (1, "Monitor %s: %lu %lu", sp->name, sp->in, sp->out);
+ verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out);
report (sp, reply->timestamp);
}
close_db ();
if (child)
exit (0);
}
@@ -520,20 +522,21 @@ read_input (const char *name)
{
name = "-";
fp = stdin;
}
else
{
fp = fopen (name, "r");
if (!fp)
- die (EX_OSERR, "cannot open file `%s': %s", name, strerror (errno));
+ die (EX_OSERR, _("cannot open file `%s': %s"),
+ name, strerror (errno));
}
- verbose (2, "Reading `%s'", name);
+ verbose (2, _("Reading `%s'"), name);
open_db (TAGR_DB_WR);
while (getline (&buf, &bufsize, fp) > 0)
{
char *p;
int i;
Stat st;
@@ -542,45 +545,45 @@ read_input (const char *name)
;
if (*p == '#' || *p == 0)
continue;
i = 0;
while (*p && !isspace (*p))
{
if (i > MAX_NAME_LENGTH)
- die (EX_DATAERR, "%s:%lu: ID too long", name, line);
+ die (EX_DATAERR, _("%s:%lu: ID too long"), name, line);
st.name[i++] = *p++;
}
st.name[i] = 0;
if (sscanf (p, " %lu %lu %lu\n", &t, &st.in, &st.out) != 3)
- die (EX_DATAERR, "%s:%lu: invalid input line", name, line);
+ die (EX_DATAERR, _("%s:%lu: invalid input line"), name, line);
report (&st, t);
}
fclose (fp);
close_db ();
- verbose (2, "Finished reading `%s'", name);
+ verbose (2, _("Finished reading `%s'"), name);
}
int
get_port (char *str)
{
int pn;
if (isdigit (str[0]))
pn = htons (atoi (str));
else
{
struct servent *s = getservbyname (str, "udp");
if (s)
pn = s->s_port;
else
{
- logmsg (L_ERR, "no such service: %s", str);
+ logmsg (L_ERR, _("no such service: %s"), str);
return 0;
}
}
return pn;
}
enum command
{
@@ -589,25 +592,25 @@ enum command
command_reconfig
};
enum command command;
RETSIGTYPE
sig_quit (int sig)
{
- logmsg (L_INFO, "exiting on signal %d", sig);
+ logmsg (L_INFO, _("exiting on signal %d"), sig);
unlink (pidfile);
exit (0);
}
RETSIGTYPE
sig_fatal (int sig)
{
- logmsg (L_ERR, "FATAL: exiting on signal %d", sig);
+ logmsg (L_ERR, _("FATAL: exiting on signal %d"), sig);
unlink (pidfile);
exit (EX_UNAVAILABLE);
}
RETSIGTYPE
sig_hup (int sig)
{
command = command_reconfig;
@@ -711,17 +714,17 @@ tagr_restart (char **argv)
exit (EX_UNAVAILABLE);
}
#define CHECK_USAGE(cond, opt, mode_opt) \
do \
if (cond) \
- die (EX_USAGE, "%s is meaningless with %s", opt, mode_opt); \
+ die (EX_USAGE, _("%s is meaningless with %s"), opt, mode_opt); \
while (0)
#define CHECK_OPTION(opt, optname) \
do \
{ \
if (opt != import_option) \
CHECK_USAGE (import_option, "--import", optname); \
if (opt != rebuild_option) \
@@ -768,17 +771,17 @@ main (int argc, char **argv)
if (html_template_option)
html_template = html_template_option;
argc -= index;
argv += index;
if (argc != 0 && !(list_option || import_option))
- die (EX_USAGE, "Too many arguments");
+ die (EX_USAGE, _("Too many arguments"));
if (readconfig ())
exit (EX_CONFIG);
if (lint_option)
{
CHECK_USAGE (import_option, "--import", "--lint");
CHECK_USAGE (rebuild_option, "--rebuild", "--lint");
@@ -890,26 +893,26 @@ main (int argc, char **argv)
signal (SIGPIPE, SIG_IGN);
signal (SIGALRM, sig_alrm);
if (!foreground)
{
FILE *fp;
if (daemon (0, 0))
- die (EX_OSERR, "cannot become daemon: %s", strerror (errno));
+ die (EX_OSERR, _("cannot become daemon: %s"), strerror (errno));
if ((fp = fopen (pidfile, "w")) != NULL)
{
fprintf (fp, "%lu\n", (unsigned long) getpid ());
fclose (fp);
}
else
{
- logmsg (L_ERR, "can't write pid file %s: %s",
+ logmsg (L_ERR, _("cannot write pid file %s: %s"),
pidfile, strerror (errno));
}
}
logmsg (L_INFO, _("%s started"), program_version);
command = command_none;
alarm (update_interval);

Return to:

Send suggestions and report system problems to the System administrator.