summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 23be368)
raw | patch | inline | side by side (parent: 23be368)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 8 May 2002 20:34:56 +0000 (20:34 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 8 May 2002 20:34:56 +0000 (20:34 +0000) |
-- Hartmut.Vogler@epost.de
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@136 a5681a0c-68f1-0310-ab6d-d61299d08faa
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@136 a5681a0c-68f1-0310-ab6d-d61299d08faa
doc/rrdtool.pod | patch | blob | history | |
src/rrd_tool.c | patch | blob | history | |
src/rrd_tool.h | patch | blob | history |
diff --git a/doc/rrdtool.pod b/doc/rrdtool.pod
index 723359224069937182c13929121286c4fc47f2aa..cd4757f6f827c7399486efac90a804f6211b87b9 100644 (file)
--- a/doc/rrdtool.pod
+++ b/doc/rrdtool.pod
=head1 SYNOPSIS
-B<rrdtool> B<-> | I<function>
+B<rrdtool> B<-> [workdir]| I<function>
=head1 DESCRIPTION
for input via standard in. With this feature you can improve
performance by attaching B<rrdtool> to another process (mrtg is one
example) through a set of pipes. Over the pipes B<rrdtool> accepts the
-same arguments as on the command line. When a command is completed,
-rrdtool will print the string 'C<OK>', followed by timing information of
-the form B<u:>I<usertime> B<s:>I<systemtime> both values are running
-totals of seconds since rrdtool was started. If an error occurs, a line
-of the form 'C<ERROR:> I<Description of error>' will be printed. B<rrdtool>
+same arguments as on the command line and some spezial commands like
+B<quit, cd, mkdir> and B<ls>. For detail helps about the server commands
+type :
+
+ rrdtool help cd|mkdir|ls|quit
+
+When a command is completed, rrdtool will print the string 'C<OK>',
+followed by timing information of the form B<u:>I<usertime>
+B<s:>I<systemtime> both values are running totals of seconds
+since rrdtool was started. If an error occurs, a line of the
+form 'C<ERROR:> I<Description of error>' will be printed. B<rrdtool>
will not abort if possible, but follow the ERROR line with an OK line.
+If a B<workdir> is spezified and the UID is 0, rrdtool will do a
+chroot to the workdir. If the UID is not 0, rrdtool only changes the
+current directory to B<workdir>.
+
+=head2 RRD Server
+
+If you want to create a RRD-Server, you must choose a TCP/IP Service
+number and add them to I</etc/services> like this:
+
+ rrdsrv 13900/tcp # rrd server
+
+Attention: the tcp port 13900 isn't official registered for rrdsrv. You
+can use any unused port in your services, but the server an the client
+system must use the same port of curse.
+After this you can add the rrdtool as meta-server to I</etc/inetd.conf>
+for example:
+
+ rrdsrv stream tcp nowait root /opt/rrd/bin/rrdtool rrdtool - /var/rrd
+
+Don't forget to create the database directory /var/rrd and reinitialize
+your inetd.
+If all was correct, you can access the server with perl sockets, tools
+like netcat or a quickhack test 'telnet localhost rrdsrv'.
+
=head1 SEE ALSO
diff --git a/src/rrd_tool.c b/src/rrd_tool.c
index 9a1f795dd08753bc36d6f7a9f3eeaf4ce94f90a1..41cf3cde0376f763e0f596eb714f018fbc762788 100644 (file)
--- a/src/rrd_tool.c
+++ b/src/rrd_tool.c
int CountArgs(char *aLine);
int CreateArgs(char *, char *, int, char **);
int HandleInputLine(int, char **, FILE*);
+int RemoteMode=0;
+int ChangeRoot=0;
#define TRUE 1
#define FALSE 0
#define MAX_LENGTH 10000
"Valid commands: create, update, graph, dump, restore,\n"
"\t\tlast, info, fetch, tune, resize, xport\n\n";
+ char help_listremote[] =
+ "Valid remote commands: quit, ls, cd, mkdir\n\n";
+
+
char help_create[] =
"* create - create a new RRD\n\n"
"\trrdtool create filename [--start|-b start time]\n"
"\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[XPORT:vname:legend]\n\n";
+ char help_quit[] =
+ " * quit - closeing a session in remote mode\n\n"
+ "\trrdtool quit\n\n";
+
+ char help_ls[] =
+ " * ls - lists all *.rrd files in current directory\n\n"
+ "\trrdtool ls\n\n";
+
+ char help_cd[] =
+ " * cd - changes the current directory\n\n"
+ "\trrdtool cd new direcotry\n\n";
+
+ char help_mkdir[] =
+ " * mkdir - creates a new direcotry\n\n"
+ "\trrdtool mkdir newdirecotryname\n\n";
+
char help_lic[] =
"RRDtool is distributed under the Terms of the GNU General\n"
"Public License Version 2. (www.gnu.org/copyleft/gpl.html)\n\n"
"For more information read the RRD manpages\n\n";
enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST,
- C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT };
+ C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT,
+ C_QUIT, C_LS, C_CD, C_MKDIR };
int help_cmd = C_NONE;
help_cmd = C_RESIZE;
else if (!strcmp(cmd,"xport"))
help_cmd = C_XPORT;
+ else if (!strcmp(cmd,"quit"))
+ help_cmd = C_QUIT;
+ else if (!strcmp(cmd,"ls"))
+ help_cmd = C_LS;
+ else if (!strcmp(cmd,"cd"))
+ help_cmd = C_CD;
+ else if (!strcmp(cmd,"mkdir"))
+ help_cmd = C_MKDIR;
}
fputs(help_main, stdout);
switch (help_cmd)
{
case C_NONE:
fputs(help_list, stdout);
+ if (RemoteMode){
+ fputs(help_listremote, stdout);
+ }
break;
case C_CREATE:
fputs(help_create, stdout);
case C_XPORT:
fputs(help_xport, stdout);
break;
+ case C_QUIT:
+ fputs(help_quit, stdout);
+ break;
+ case C_LS:
+ fputs(help_ls, stdout);
+ break;
+ case C_CD:
+ fputs(help_cd, stdout);
+ break;
+ case C_MKDIR:
+ fputs(help_mkdir, stdout);
+ break;
}
fputs(help_lic, stdout);
}
{
char **myargv;
char aLine[MAX_LENGTH];
+ char *firstdir="";
#ifdef MUST_DISABLE_SIGFPE
signal(SIGFPE,SIG_IGN);
#endif
return 0;
}
- if ((argc == 2) && !strcmp("-",argv[1]))
+ if (((argc == 2)||(argc == 3)) && !strcmp("-",argv[1]))
{
#if HAVE_GETRUSAGE
struct rusage myusage;
tz.tz_dsttime=0;
gettimeofday(&starttime,&tz);
#endif
+ RemoteMode=1;
+#ifndef WIN32
+ if ((argc == 3) && strcmp("",argv[2])){
+ if (getuid()==0){
+ chroot(argv[2]);
+ if (errno!=0){
+ fprintf(stderr,"ERROR: can't change root to '%s' errno=%d\n",
+ argv[2],errno);
+ exit(errno);
+ }
+ ChangeRoot=1;
+ firstdir="/";
+ }
+ else{
+ firstdir=argv[2];
+ }
+ }
+ if (strcmp(firstdir,"")){
+ chdir(firstdir);
+ if (errno!=0){
+ fprintf(stderr,"ERROR: %s\n",strerror(errno));
+ exit(errno);
+ }
+ }
+#else
+ fprintf(stderr,"ERROR: change root only in unix "
+ "enviroment posible\n");
+ exit(1);
+#endif
while (fgets(aLine, sizeof(aLine)-1, stdin)){
if ((argc = CountArgs(aLine)) == 0) {
PrintUsage(argv[1]);
exit(0);
}
+ else if (argc == 3 && !strcmp(argv[1],"help"))
+ {
+ PrintUsage(argv[2]);
+ exit(0);
+ }
else
HandleInputLine(argc, argv, stderr);
return 0;
int HandleInputLine(int argc, char **argv, FILE* out)
{
+ DIR *curdir; /* to read current dir with ls */
+ struct dirent *dent;
+ struct stat st;
optind=0; /* reset gnu getopt */
opterr=0; /* no error messages */
+ if (RemoteMode){
+ if (argc>1 && strcmp("quit", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for quit\n");
+ return(0);
+ }
+ exit(0);
+ }
+ if (argc>1 && strcmp("cd", argv[1]) == 0){
+ if (argc>3){
+ printf("ERROR: invalid parameter count for cd\n");
+ return(0);
+ }
+#ifndef WIN32
+ if (getuid()==0 && ! ChangeRoot){
+ printf("ERROR: chdir security problem - rrdtool is runnig as "
+ "root an no chroot!\n");
+ return(0);
+ }
+#endif
+ chdir(argv[2]);
+ if (errno!=0){
+ printf("ERROR: %s\n",strerror(errno));
+ }
+ return(0);
+ }
+ if (argc>1 && strcmp("mkdir", argv[1]) == 0){
+ if (argc>3){
+ printf("ERROR: invalid parameter count for mkdir\n");
+ return(0);
+ }
+#ifndef WIN32
+ if (getuid()==0 && ! ChangeRoot){
+ printf("ERROR: mkdir security problem - rrdtool is runnig as "
+ "root an no chroot!\n");
+ return(0);
+ }
+#endif
+ mkdir(argv[2],0777);
+ if (errno!=0){
+ printf("ERROR: %s\n",strerror(errno));
+ }
+ return(0);
+ }
+ if (argc>1 && strcmp("ls", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for ls\n");
+ return(0);
+ }
+ if ((curdir=opendir("."))!=NULL){
+ while((dent=readdir(curdir))!=NULL){
+ if (!stat(dent->d_name,&st)){
+ if (S_ISDIR(st.st_mode)){
+ printf("d %s\n",dent->d_name);
+ }
+ if (strlen(dent->d_name)>4 && S_ISREG(st.st_mode)){
+ if (!strcmp(dent->d_name+strlen(dent->d_name)-4,".rrd") ||
+ !strcmp(dent->d_name+strlen(dent->d_name)-4,".RRD")){
+ printf("- %s\n",dent->d_name);
+ }
+ }
+ }
+ }
+ }
+ else{
+ printf("ERROR: %s\n",strerror(errno));
+ return(errno);
+ }
+ return(0);
+ }
+ }
if (argc < 3
|| strcmp("help", argv[1]) == 0
|| strcmp("--help", argv[1]) == 0
diff --git a/src/rrd_tool.h b/src/rrd_tool.h
index 5ba481bd1d7c6ea2508382192eb6b0a173c53ad7..780cd05ea9054403167084e1c686496342347fcb 100644 (file)
--- a/src/rrd_tool.h
+++ b/src/rrd_tool.h
#if HAVE_MATH_H
# include <math.h>
#endif
+/* Sorry: don't know autoconf as well how to check the exist of
+ dirent.h ans sys/stat.h
+*/
+#include <sys/stat.h>
+#include <dirent.h>
+#include <sys/types.h>
+/*
+#endif
+*/
#if HAVE_UNISTD_H
# include <unistd.h>
#endif