aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac18
-rw-r--r--src/graph.c1
-rw-r--r--src/html.gram.y34
-rw-r--r--src/html.lex.l10
-rw-r--r--src/log.c16
-rw-r--r--src/main.c77
-rw-r--r--src/readconfig.c32
-rw-r--r--src/report.c40
-rw-r--r--src/stat.c65
-rw-r--r--src/tagr.h5
10 files changed, 167 insertions, 131 deletions
diff --git a/configure.ac b/configure.ac
index a622998..70e0c79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,33 +53,51 @@ AC_FUNC_STRFTIME
AC_FUNC_STRTOD
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([memset pow select socket strchr strdup strerror strtoul])
# GNUlib
gl_INIT
GRECS_SETUP
# Check for gd headers and libraries
AC_CHECK_HEADERS([gd.h gdfonts.h],:,
[AC_MSG_ERROR([Libgd headers gd.h and/or gdfonts.h are not found])])
AC_CHECK_LIB([gd],[gdImageCreate],
,
[AC_MSG_ERROR([libgd not found])])
AC_CHECK_HEADERS(gdbm.h,
,
[AC_MSG_ERROR([gdbm.h not found])])
AC_CHECK_LIB([gdbm], [gdbm_open],
,
[AC_MSG_ERROR([libgdbm not found])])
+
+## Default syslog facility
+LOG_FACILITY="LOG_DAEMON"
+
+AC_ARG_VAR([LOG_FACILITY],
+ [Default syslog facility])
+if test -n "$LOG_FACILITY"; then
+ logfacility=`echo $LOG_FACILITY | tr a-z A-Z`
+ case $logfacility in
+ USER|DAEMON|AUTH|AUTHPRIV|MAIL|CRON|LOCAL[[0-7]])
+ LOG_FACILITY=LOG_$logfacility;;
+ LOG_USER|LOG_DAEMON|LOG_AUTH|LOG_AUTHPRIV|LOG_MAIL|LOG_CRON|LOG_LOCAL[[0-7]])
+ LOG_FACILITY=$logfacility;;
+ *) AC_MSG_ERROR([Invalid value of LOG_FACILITY]);;
+ esac
+fi
+AC_DEFINE_UNQUOTED([LOG_FACILITY],$LOG_FACILITY,
+ [Default syslog facility.])
AC_CONFIG_FILES([Makefile
gnu/Makefile
grecs/Makefile
grecs/src/Makefile
src/Makefile
etc/Makefile])
AC_OUTPUT
diff --git a/src/graph.c b/src/graph.c
index bfd00cb..1464e8b 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -33,48 +33,49 @@
#include <tagr.h>
int fill_incoming_option = 1; /* Fill incoming graph */
int percent_option = 0;
int transparent_option = 1;
int zero_unknown_option = 1;
int color_background[3] = { 245,245,245 };
int color_light[3] = { 194,194,194 };
int color_dark[3] = { 100,100,100 };
int color_major[3] = { 255,0,0 };
int color_in[3] = { 0,235,12 };
int color_out[3] = { 0,94,255 };
int color_grid[3] = { 0,0,0 };
int color_in_max[3] = { 0,166,33 };
int color_out_max[3] = { 255,0,255 };
int color_percent[3] = { 239,159,79 };
int graph_xsize = 460;
int graph_ysize = 100;
int graph_h_margin[2] = { 100, 14 };
int graph_v_margin[2] = { 14, 35 };
+/* FIXME: I18N?? */
char *rate_unit = "Bytes per Second";
#define make_color_index(g, ar) \
gdImageColorAllocate (g, (ar)[0], (ar)[1], (ar)[2])
static void
draw_vtext (gdImagePtr graph, int color, const char *text)
{
gdImageStringUp (graph, gdFontSmall,
8,
graph_ysize + graph_v_margin[0] -
(graph_ysize - gdFontSmall->w * strlen (text))/2,
(unsigned char *) text, color);
}
int
draw_graph (FILE *fp,
struct monitor *mon,
queue_t *dataq, const struct avg_acc *avg, time_t now,
int xstep, unsigned long xmax,
int growright,
struct grid_class *xgrid, struct grid_class *ygrid)
{
int x, y;
diff --git a/src/html.gram.y b/src/html.gram.y
index fae64ff..e488494 100644
--- a/src/html.gram.y
+++ b/src/html.gram.y
@@ -92,229 +92,229 @@ eval : IDENT
obrace: OBRACE
{
begin_eval ();
}
;
cbrace: CBRACE
{
end_eval ();
}
;
expr : value
| '(' expr ')'
{
$$ = $2;
}
| expr '+' expr
{
if ($1.type == unspecified_value
|| $3.type == unspecified_value)
init_value (&$$, unspecified_value, NULL);
else if ($1.type != $3.type)
{
- yyerror ("type mismatch in addition");
+ yyerror (_("type mismatch in addition"));
init_value (&$$, unspecified_value, NULL);
}
else
{
$$.type = $1.type;
deduce_format (&$$, &$1, &$3);
switch ($1.type)
{
case numeric_value:
$$.v.number = $1.v.number + $3.v.number;
break;
case string_value:
$$.v.string = xmalloc (strlen ($1.v.string)
+ strlen ($3.v.string) + 1);
strcpy ($$.v.string, $1.v.string);
strcat ($$.v.string, $3.v.string);
break;
default:
abort (); /* Should not happen */
}
}
}
| expr '-' expr
{
if ($1.type == unspecified_value
|| $3.type == unspecified_value)
init_value (&$$, unspecified_value, NULL);
else if ($1.type != $3.type)
{
- yyerror ("type mismatch in subtraction");
+ yyerror (_("type mismatch in subtraction"));
init_value (&$$, unspecified_value, NULL);
}
else if ($1.type == string_value)
{
- yyerror ("subtraction not defined for strings");
+ yyerror (_("subtraction not defined for strings"));
init_value (&$$, unspecified_value, NULL);
}
else
{
$$.type = $1.type;
deduce_format (&$$, &$1, &$3);
$$.v.number = $1.v.number - $3.v.number;
}
}
| expr '*' expr
{
if ($1.type == unspecified_value
|| $3.type == unspecified_value)
init_value (&$$, unspecified_value, NULL);
else if ($1.type != $3.type)
{
- yyerror ("type mismatch in multiplication");
+ yyerror (_("type mismatch in multiplication"));
init_value (&$$, unspecified_value, NULL);
}
else if ($1.type == string_value)
{
- yyerror ("multiplication not defined for strings");
+ yyerror (_("multiplication not defined for strings"));
init_value (&$$, unspecified_value, NULL);
}
else
{
$$.type = $1.type;
deduce_format (&$$, &$1, &$3);
$$.v.number = $1.v.number * $3.v.number;
}
}
| expr '/' expr
{
if ($1.type == unspecified_value
|| $3.type == unspecified_value)
init_value (&$$, unspecified_value, NULL);
else if ($1.type != $3.type)
{
- yyerror ("type mismatch in division");
+ yyerror (_("type mismatch in division"));
init_value (&$$, unspecified_value, NULL);
}
else if ($1.type == string_value)
{
- yyerror ("division not defined for strings");
+ yyerror (_("division not defined for strings"));
init_value (&$$, unspecified_value, NULL);
}
else if (fabs ($3.v.number) < 1.0e-5)
{
- yyerror ("division by zero");
+ yyerror (_("division by zero"));
init_value (&$$, unspecified_value, NULL);
}
else
{
$$.type = $1.type;
deduce_format (&$$, &$1, &$3);
$$.v.number = $1.v.number / $3.v.number;
}
}
| '-' expr %prec UMINUS
{
if ($2.type == unspecified_value)
init_value (&$$, unspecified_value, NULL);
else if ($2.type == string_value)
{
- yyerror ("unary minus not defined for strings");
+ yyerror (_("unary minus not defined for strings"));
init_value (&$$, unspecified_value, NULL);
}
else
{
$$ = $2;
$$.v.number = - $2.v.number;
}
}
| '+' expr %prec UMINUS
{
if ($2.type == unspecified_value)
init_value (&$$, unspecified_value, NULL);
else if ($2.type == string_value)
{
- yyerror ("unary plus not defined for strings");
+ yyerror (_("unary plus not defined for strings"));
init_value (&$$, unspecified_value, NULL);
}
else
{
$$ = $2;
}
}
;
value : IDENT
| NUMBER
{
union value v;
v.number = $1;
init_value (&$$, numeric_value, &v);
}
;
%%
int
yyerror (char *s)
{
logmsg (L_ERR, "%s:%d: %s", html_input_file, html_input_line, s);
return 0;
}
int
create_html (pp_tab_t *tab, char *file, char *dest)
{
int rc;
if (html_open (file))
return 1;
tmp_file_name = mkfilename (NULL, dest, ".tmp");
tmp_file = fopen (tmp_file_name, "w");
if (!tmp_file)
{
- logmsg (L_ERR, "cannot open output file `%s': %s",
+ logmsg (L_ERR, _("cannot open output file `%s': %s"),
file, strerror (errno));
html_close ();
return 1;
}
ident_tab = tab;
rc = yyparse ();
fclose (tmp_file);
if (rc == 0)
{
if (unlink (dest) && errno != ENOENT)
{
- logmsg (L_ERR, "cannot unlink file `%s': %s",
+ logmsg (L_ERR, _("cannot unlink file `%s': %s"),
dest, strerror (errno));
rc = 1;
}
if (rename (tmp_file_name, dest))
{
- logmsg (L_ERR, "cannot rename `%s' to `%s': %s",
+ logmsg (L_ERR, _("cannot rename `%s' to `%s': %s"),
tmp_file_name, dest,
strerror (errno));
rc = 1;
}
}
free (tmp_file_name);
return rc;
}
static void
out_char (int c)
{
fputc (c, tmp_file);
}
static void
deduce_format (pp_value_t *res, const pp_value_t *a, const pp_value_t *b)
{
res->prec = maxprec (a->prec, b->prec);
if (!a->format && b->format)
{
res->fmt = b->fmt;
res->format = b->format;
}
@@ -473,88 +473,88 @@ read_symtab (pp_tab_t **tab, const char *name)
unsigned line = 0;
int status = 0;
fp = fopen (name, "r");
if (!fp)
return -1;
while (getline (&buf, &size, fp) > 0)
{
char *p, *var, *value;
int cmd;
size_t len = strlen (buf);
line++;
if (buf[len-1] == '\n')
buf[len-1] = 0;
if (buf[0] == '#' || buf[0] == 0)
continue;
p = buf;
cmd = *p++;
if (*p != ' ' || !(isascii (*++p) && isalpha (*p)))
{
- logmsg (L_ERR, "%s:%u: invalid input: %s",
+ logmsg (L_ERR, _("%s:%u: invalid input: %s"),
name, line, buf);
status = 1;
break;
}
var = p;
p = strchr (var, ' ');
if (!p)
{
- logmsg (L_ERR, "%s:%u: invalid input: %s",
+ logmsg (L_ERR, _("%s:%u: invalid input: %s"),
name, line, buf);
status = 1;
break;
}
*p++ = 0;
value = p;
switch (cmd)
{
case 's':
add_string_value (tab, var, value);
break;
case 'n':
{
char *p;
double num = strtod (value, &p);
if (*p)
{
- logmsg (L_ERR, "%s:%u: invalid numeric value: %s",
+ logmsg (L_ERR, _("%s:%u: invalid numeric value: %s"),
name, line, value);
status = 1;
}
else
add_numeric_value (tab, var, num);
}
break;
default:
- logmsg (L_NOTICE, "%s:%u: ignoring unknown command %#03o",
+ logmsg (L_NOTICE, _("%s:%u: ignoring unknown command %#03o"),
name, line, cmd);
}
}
free (buf);
fclose (fp);
return status;
}
int
write_symtab (pp_tab_t *tab, const char *name)
{
FILE *fp;
fp = fopen (name, "w");
if (!fp)
return -1;
for (; tab; tab = tab->next)
{
switch (tab->value.type)
{
case numeric_value:
fprintf (fp, "n %s %g\n", tab->name, tab->value.v.number);
break;
diff --git a/src/html.lex.l b/src/html.lex.l
index 931bfc1..0e0d423 100644
--- a/src/html.lex.l
+++ b/src/html.lex.l
@@ -22,83 +22,83 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <tagr.h>
#include <html.gram.h>
char *html_input_file;
int html_input_line;
%}
%s EVAL
NAME [A-Za-z_][A-Za-z0-9_]*
N [0-9]+
%%
\$\$ {
yylval.character = '$';
return CHAR;
}
\${NAME} {
if (find_value (yytext+1, &yylval.value))
{
- yyerror ("unknown identifier");
+ yyerror (_("unknown identifier"));
init_value (&yylval.value, unspecified_value, NULL);
}
return IDENT;
}
\$\({NAME}\) {
yytext[yyleng-1] = 0;
if (find_value (yytext+2, &yylval.value))
{
- yyerror ("unknown identifier");
+ yyerror (_("unknown identifier"));
init_value (&yylval.value, unspecified_value, NULL);
}
return IDENT;
}
\$\({NAME}:{N}\) {
char *p = strchr (yytext, ':');
*p = 0;
if (find_value (yytext+2, &yylval.value))
{
- yyerror ("unknown identifier");
+ yyerror (_("unknown identifier"));
init_value (&yylval.value, unspecified_value, NULL);
}
else
{
yylval.value.prec = strtoul (p+1, NULL, 10);
}
return IDENT;
}
\$\({NAME}:[^)]+\) {
pp_value_t val;
char *p = strchr (yytext, ':');
*p++ = 0;
if (find_value (yytext+2, &val))
{
- yyerror ("unknown identifier");
+ yyerror (_("unknown identifier"));
init_value (&yylval.value, unspecified_value, NULL);
}
else
{
size_t len = strlen (p) - 1;
init_value (&yylval.value, val.type, &val.v);
yylval.value.prec = val.prec;
yylval.value.format = val.format;
yylval.value.fmt = xmalloc (len + 1);
memcpy (yylval.value.fmt, p, len);
yylval.value.fmt[len] = 0;
}
return IDENT;
}
\$\{ return OBRACE;
\$\} return CBRACE;
<EVAL>[ \t]+ ;
<EVAL>"("|")"|"+"|"-"|"*"|"/" return yytext[0];
<EVAL>{N}\.?([eE][-+]?{N}+)? {
yylval.number = strtod (yytext, NULL);
return NUMBER;
}
\n {
html_input_line++;
@@ -109,49 +109,49 @@ N [0-9]+
yylval.character = yytext[0];
return CHAR;
}
%%
void
begin_eval ()
{
BEGIN (EVAL);
}
void
end_eval ()
{
BEGIN (INITIAL);
}
int
html_open (char *file)
{
yyin = fopen (file, "r");
if (!yyin)
{
- logmsg (L_ERR, "cannot open input file `%s': %s",
+ logmsg (L_ERR, _("cannot open input file `%s': %s"),
file, strerror (errno));
return 1;
}
html_input_file = file;
html_input_line = 1;
return 0;
}
void
html_close ()
{
if (yyin)
{
fclose (yyin);
yyin = NULL;
}
}
int
yywrap ()
{
html_close ();
return 1;
}
diff --git a/src/log.c b/src/log.c
index de847c9..e5ae4e1 100644
--- a/src/log.c
+++ b/src/log.c
@@ -8,85 +8,85 @@
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <syslog.h>
#include <argp.h>
#include <tagr.h>
-int log_facility = LOGFACILITY;
+int log_facility = LOG_FACILITY;
char *log_tag;
int log_print_severity; /* FIXME: not used */
void
init_syslog (char *progname)
{
if (!log_tag)
log_tag = progname;
openlog (log_tag, LOG_PID, log_facility);
}
int syslog_level[] = {
LOG_DEBUG,
LOG_INFO,
LOG_NOTICE,
LOG_WARNING,
LOG_ERR,
LOG_CRIT,
};
char *level_str[] = {
- "debug",
- "info",
- "notice",
- "warning",
- "error",
- "CRITICAL",
+ N_("debug"),
+ N_("info"),
+ N_("notice"),
+ N_("warning"),
+ N_("error"),
+ N_("CRITICAL"),
};
void
vlogmsg (int level, const char *fmt, va_list ap)
{
if (grecs_log_to_stderr)
{
- fprintf (stderr, "%s: %s: ", log_tag, level_str[level]);
+ fprintf (stderr, "%s: %s: ", log_tag, gettext (level_str[level]));
vfprintf (stderr, fmt, ap);
fprintf (stderr, "\n");
}
else
vsyslog (syslog_level[level], fmt, ap);
}
void
logmsg (int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vlogmsg (level, fmt, ap);
va_end (ap);
}
void
die (int code, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vlogmsg (LOG_CRIT, fmt, ap);
diff --git a/src/main.c b/src/main.c
index 2a20ba9..9b98ec5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,81 +59,81 @@ char *pidfile = TAGR_PIDFILE;
unsigned update_interval = 5*60;
char i_recv_buffer[reply_size (MAXADDR)];
char *recv_buffer = i_recv_buffer;
char *configfile = TAGR_CONFIGFILE;
char *html_template = TAGR_TEMPLATE;
char *user;
char *basedir;
int port;
int sockfd;
int foreground = 0;
int single_process_option = 0;
int verbose_level;
static int rebuild_option;
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,
OPT_NO_PREPROCESSOR,
OPT_DUMP_GRAMMAR_TRACE,
OPT_DUMP_LEX_TRACE,
OPT_CONFIG_HELP,
OPT_READ,
};
static struct argp_option options[] = {
#define GRID 10
{NULL, 0, NULL, 0,
N_("Main operation mode"), GRID },
{"lint", 't', NULL, 0,
N_("parse configuration file and exit"), GRID+1},
{NULL, 'E', NULL, 0,
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
{NULL, 0, NULL, 0,
N_("Operation mode modifiers"), GRID },
{"foreground", 'f', NULL, 0, N_("run in foreground mode"), GRID+1},
{"config-file", 'c', "FILE", 0, N_("read specified configuration FILE"), GRID+1},
{"single-process", 's', NULL, 0, N_("run in single-process mode"), GRID+1},
#undef GRID
#define GRID 30
{NULL, 0, NULL, 0,
N_("Logging"), GRID },
{"syslog", OPT_SYSLOG, NULL, 0, N_("log to syslog"), GRID+1},
{"stderr", OPT_STDERR, NULL, 0, N_("log to stderr"), GRID+1},
#undef GRID
@@ -166,54 +166,54 @@ static struct argp_option options[] = {
#define GRID 60
{NULL, 0, NULL, 0,
N_("Other settings"), GRID },
{"html-template", 'T', N_("FILE"), 0,
N_("use given HTML template file"), GRID+1},
{"user", 'u', N_("USER-NAME"), 0,
N_("run with this user privileges"), GRID+1},
#undef GRID
#define GRID 70
{NULL, 0, NULL, 0,
N_("Additional help"), GRID },
{"config-help", OPT_CONFIG_HELP, NULL, 0,
N_("show configuration file summary"), GRID+1},
#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;
if (!check_mode)
check_mode = xstrdup (s);
else
strcat (xrealloc (check_mode, strlen (check_mode) + 2), s);
}
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case 'f':
foreground++;
break;
case 'b':
@@ -314,316 +314,319 @@ static struct argp argp = {
options,
parse_opt,
args_doc,
doc,
NULL,
NULL,
NULL
};
/* Change to the given uid/gid. Clear the supplementary group list.
On success returns 0.
On failure returns 1 (or exits, depending on topt settings. See
anubis_error) */
static int
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)
{
uid_t euid;
if (setuid (uid)
|| geteuid () != uid
|| (getuid () != uid && (geteuid () == 0 || getuid () == 0)))
{
#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);
chdir (pwd->pw_dir);
}
}
void
decode_buffer ()
{
int i;
Stat_reply *reply;
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);
}
void
read_input (const char *name)
{
FILE *fp;
char *buf = NULL;
size_t bufsize = 0;
unsigned long line = 0;
unsigned long t;
if (!name || strcmp (name, "-") == 0)
{
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;
line++;
for (p = buf; *p && isascii (*p) && isspace (*p); p++)
;
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
{
command_none,
command_update,
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;
signal (sig, sig_hup);
}
RETSIGTYPE
sig_alrm (int sig)
{
command = command_update;
signal (sig, sig_alrm);
}
RETSIGTYPE
sig_child (int sig)
{
int status;
while (waitpid ((pid_t)-1, &status, WNOHANG) > 0)
@@ -695,49 +698,49 @@ tagr_restart (char **argv)
signal (SIGHUP, SIG_DFL);
signal (SIGUSR1, SIG_DFL);
signal (SIGUSR2, SIG_DFL);
signal (SIGQUIT, SIG_DFL);
signal (SIGTERM, SIG_DFL);
signal (SIGIOT, SIG_DFL);
signal (SIGCHLD, SIG_DFL);
signal (SIGPIPE, SIG_DFL);
signal (SIGALRM, SIG_DFL);
for (i = getdtablesize (); i > minfd; i--)
close (i);
execv (argv[0], argv);
logmsg (L_ERR, _("cannot restart: %s"), strerror (errno));
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) \
CHECK_USAGE (rebuild_option, "--rebuild", optname); \
if (opt != list_option) \
CHECK_USAGE (list_option, "--list", optname); \
if (opt != read_option) \
CHECK_USAGE