postgresql-8.4.0-pgbenchsetshell.patch
text/x-patch
Filename: postgresql-8.4.0-pgbenchsetshell.patch
Type: text/x-patch
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| contrib/pgbench/pgbench.c | 113 | 0 |
--- postgresql-8.4.0.orig/contrib/pgbench/pgbench.c 2009-09-22 10:09:44.000000000 +0900
+++ postgresql-8.4.0/contrib/pgbench/pgbench.c 2009-09-23 11:03:27.000000000 +0900
@@ -123,6 +123,7 @@ typedef struct
} Variable;
#define MAX_FILES 128 /* max number of SQL script files allowed */
+#define SHELL_COMMAND_SIZE 256 /* maximum size allowed for shell command */
/*
* structures used in custom query mode
@@ -987,7 +988,99 @@ top:
st->listen = 1;
}
+ else if (pg_strcasecmp(argv[0], "setshell") == 0)
+ {
+ int retval;
+ char res[64],
+ resfin[64];
+ FILE *respipe = NULL;
+ /* Data treatment */
+ /* prototype: /setshell aid skewerand */
+ respipe = popen(argv[2],"r");
+ if (respipe == NULL)
+ {
+ fprintf(stderr, "%s: error launching shell script", argv[0]);
+ st->ecnt++;
+ return;
+ }
+ if (fgets(res, 64, respipe) == NULL)
+ {
+ fprintf(stderr, "%s: error getting parameter", argv[0]);
+ st->ecnt++;
+ return;
+ }
+
+ retval = pclose(respipe);
+ if (retval == -1)
+ {
+ fprintf(stderr, "%s: error closing shell script", argv[0]);
+ st->ecnt++;
+ return;
+ }
+ /* Transform the parameter into an integer */
+ retval = atoi(res);
+ if (retval == 0)
+ {
+ fprintf(stderr, "%s: error input integer", argv[0]);
+ st->ecnt++;
+ return;
+ }
+ /* ready to put the variable */
+ snprintf(resfin, sizeof(resfin), "%d", retval);
+
+ if (putVariable(st, argv[1], resfin) == false)
+ {
+ fprintf(stderr, "%s: out of memory\n", argv[0]);
+ st->ecnt++;
+ return;
+ }
+#ifdef DEBUG
+ printf("shell parameter name: %s, value: %s", argv[1], resfin);
+#endif
+ st->listen = 1;
+ }
+ else if (pg_strcasecmp(argv[0], "shell") == 0)
+ {
+ int j,
+ retval,
+ retvalglob;
+ char commandLoc[SHELL_COMMAND_SIZE];
+
+ retval = snprintf(commandLoc,SHELL_COMMAND_SIZE-1,"%s",argv[1]);
+ if (retval < 0
+ || retval > SHELL_COMMAND_SIZE-1)
+ {
+ fprintf(stderr, "Error launching shell command: too many characters\n");
+ st->ecnt++;
+ return;
+ }
+ retvalglob = retval;
+
+ for (j = 2; j < argc; j++)
+ {
+ char *commandLoc2 = strdup(commandLoc);
+ retval = snprintf(commandLoc,SHELL_COMMAND_SIZE-1,"%s %s", commandLoc2, argv[j]);
+ retvalglob += retval;
+ if (retval < 0
+ || retvalglob > SHELL_COMMAND_SIZE-1)
+ {
+ fprintf(stderr, "Error launching shell command: too many characters\n");
+ free(commandLoc2);
+ st->ecnt++;
+ return;
+ }
+ free(commandLoc2);
+ }
+ retval = system(commandLoc);
+ if (retval < 0)
+ {
+ fprintf(stderr, "Error launching shell command: command not launched");
+ st->ecnt++;
+ return;
+ }
+ st->listen = 1;
+ }
goto top;
}
}
@@ -1283,6 +1376,26 @@ process_commands(char *buf)
fprintf(stderr, "%s: extra argument \"%s\" ignored\n",
my_commands->argv[0], my_commands->argv[j]);
}
+ else if (pg_strcasecmp(my_commands->argv[0], "setshell") == 0)
+ {
+ if (my_commands->argc < 3)
+ {
+ fprintf(stderr, "%s: missing argument\n", my_commands->argv[0]);
+ return NULL;
+ }
+
+ for (j = 3; j < my_commands->argc; j++)
+ fprintf(stderr, "%s: extra argument \"%s\" ignored\n",
+ my_commands->argv[0], my_commands->argv[j]);
+ }
+ else if (pg_strcasecmp(my_commands->argv[0], "shell") == 0)
+ {
+ if (my_commands->argc < 1)
+ {
+ fprintf(stderr, "%s: missing command\n", my_commands->argv[0]);
+ return NULL;
+ }
+ }
else
{
fprintf(stderr, "Invalid command %s\n", my_commands->argv[0]);