From 0daf60b6dbb47d363a611f1585ca62a2825f4bdf Mon Sep 17 00:00:00 2001 From: oetiker Date: Fri, 14 Jul 2006 08:56:28 +0000 Subject: [PATCH] added pwd command for remote server reset errno to zero before each loop -- Damien.Stuart usi.net git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@853 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/doc/rrdtool.pod | 2 +- program/src/rrd_tool.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/program/doc/rrdtool.pod b/program/doc/rrdtool.pod index 0f41607a..cd3c7852 100644 --- a/program/doc/rrdtool.pod +++ b/program/doc/rrdtool.pod @@ -260,7 +260,7 @@ accepts the same arguments as on the command line and some special commands like B and B. For detailed help on the server commands type: - rrdtool help cd|mkdir|ls|quit + rrdtool help cd|mkdir|pwd|ls|quit When a command is completed, RRDtool will print the string 'C', followed by timing information of the form BI diff --git a/program/src/rrd_tool.c b/program/src/rrd_tool.c index 5d49042a..e91464df 100644 --- a/program/src/rrd_tool.c +++ b/program/src/rrd_tool.c @@ -31,7 +31,7 @@ void PrintUsage(char *cmd) "\t\tlast, first, info, fetch, tune, resize, xport\n\n"; char help_listremote[] = - "Valid remote commands: quit, ls, cd, mkdir\n\n"; + "Valid remote commands: quit, ls, cd, mkdir, pwd\n\n"; char help_create[] = @@ -179,6 +179,10 @@ void PrintUsage(char *cmd) " * mkdir - creates a new directory\n\n" "\trrdtool mkdir newdirectoryname\n\n"; + char help_pwd[] = + " * pwd - returns the current working directory\n\n" + "\trrdtool pwd\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" @@ -187,7 +191,7 @@ void PrintUsage(char *cmd) enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST, C_FIRST, C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT, - C_QUIT, C_LS, C_CD, C_MKDIR, C_UPDATEV }; + C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD, C_UPDATEV }; int help_cmd = C_NONE; @@ -227,6 +231,8 @@ void PrintUsage(char *cmd) help_cmd = C_CD; else if (!strcmp(cmd,"mkdir")) help_cmd = C_MKDIR; + else if (!strcmp(cmd,"pwd")) + help_cmd = C_PWD; } fputs(help_main, stdout); switch (help_cmd) @@ -291,6 +297,9 @@ void PrintUsage(char *cmd) case C_MKDIR: fputs(help_mkdir, stdout); break; + case C_PWD: + fputs(help_pwd, stdout); + break; } fputs(help_lic, stdout); } @@ -450,6 +459,11 @@ int HandleInputLine(int argc, char **argv, FILE* out) #if defined(HAVE_SYS_STAT_H) struct stat st; #endif + char* cwd; /* To hold current working dir on call to pwd */ + + /* Reset errno to 0 before we start. + */ + errno = 0; if (RemoteMode){ if (argc>1 && strcmp("quit", argv[1]) == 0){ @@ -479,6 +493,20 @@ int HandleInputLine(int argc, char **argv, FILE* out) } return(0); } + if (argc>1 && strcmp("pwd", argv[1]) == 0){ + if (argc>2){ + printf("ERROR: invalid parameter count for pwd\n"); + return(1); + } + cwd = getcwd(NULL, MAXPATH); + if(cwd == NULL) { + printf("ERROR: %s\n",rrd_strerror(errno)); + return(1); + } + printf("%s\n", cwd); + free(cwd); + return(0); + } if (argc>1 && strcmp("mkdir", argv[1]) == 0){ if (argc>3){ printf("ERROR: invalid parameter count for mkdir\n"); -- 2.30.2