On 9/24/2014 7:39 AM, Eliot Moss wrote:
On 9/24/2014 5:31 AM, Skarakis, Konstantinos wrote:
Ok -- I decided to just give it a try in a copy of valgrind
updated to svn head. The issue is that I was temporarily
sticking a null character into the format string, yet the
format string was declared somewhere else as const. That
declaration was righteous, and my temporary insertion of
a null I admit was a hack. I was already copying the
relevant part of the format string out into a temporary
buffer, so the actual adjustments needed were small. Once
I made those changes, it compiles and passes check tests
for me (on a linux amd64 system). I attach the updated
patch. I'll see about submitting this, though there also
needs to be an update to a section of the manual for a
complete patch to make sense for the distro.
Regards -- Eliot Moss
Index: coregrind/m_options.c
===================================================================
--- coregrind/m_options.c (revision 14564)
+++ coregrind/m_options.c (working copy)
@@ -234,6 +234,120 @@
goto bad;
}
}
+ else if ('s' == format[i]) {
+ i++;
+ if ('{' == format[i]) {
+ // Get the script name, get organized to invoke it
+ Char* scriptname;
+ Char* result;
+ i++;
+ int start = i;
+ while (True) {
+ if (0 == format[i]) {
+ VG_(fmsg)("%s: malformed %%s specifier\n", option_name);
+ goto bad;
+ } else if ('}' == format[i]) {
+ int nameLen = i - start;
+ Char *tempBuf = VG_(malloc)( "options.efn.3", nameLen + 1 );
+ VG_(strncpy)( tempBuf, &format[start], nameLen );
+ tempBuf[nameLen] = 0;
+ scriptname = tempBuf;
+
+ Int fd[2];
+ Int err;
+ if ( (err = VG_(pipe)(fd)) < 0) {
+ VG_(fmsg)("%s: could not create pipe for script; err=%d\n", option_name, err);
+ goto bad;
+ }
+
+ Int pid = VG_(fork)();
+ if (pid < 0) {
+ // could not fork to execute script -- die!
+ VG_(fmsg)("%s: could not fork to run script; err=%d\n", option_name, pid);
+ VG_(close)(fd[0]);
+ VG_(close)(fd[1]);
+ goto bad;
+ }
+
+ if (pid == 0) { // child
+ VG_(close)(fd[0]); // don't need the input side of the pipe
+ VG_(close)(1); // want to replace standard output
+ VG_(dup2)(fd[1], 1); // now have pipe for output
+ VG_(close)(fd[1]); // close old fd
+ Char* argv[4] = { "/bin/sh", "-c", scriptname, 0 };
+ VG_(execv)(argv[0], argv);
+ VG_(exit)(1); // should not get here!
+ }
+
+ VG_(close)(fd[1]);
+ Int incr = 100;
+ Int max = incr;
+ Int hardmax = 5 * incr;
+ Char* buf = VG_(malloc)( "options.efn.4", max+1 );
+ Int idx = 0;
+ Int amt;
+ while ( (amt = VG_(read)( fd[0], buf+idx, max-idx )) > 0 ) {
+ Int lim = idx + amt;
+ while ( idx < lim ) {
+ if (buf[idx] == '\n' || buf[idx] == 0) {
+ break;
+ }
+ idx++;
+ }
+ if (idx < lim) {
+ break;
+ }
+ if ( idx == max ) {
+ if ( max >= hardmax ) {
+ VG_(fmsg)("%s script output too large; truncating\n", scriptname);
+ amt = 0;
+ break;
+ }
+ max += incr;
+ buf = VG_(realloc)( "options.efn.5", buf, max+1 );
+ }
+ }
+ if ( amt < 0 ) {
+ VG_(fmsg)("%s script: error reading output; err=%d\n", scriptname, amt);
+ goto bad;
+ }
+ buf[idx] = 0;
+ VG_(close)(fd[0]);
+ i++; // over the }
+ result = buf;
+
+ { // code cribbed from m_libcproc.c: system
+ // wait for child to finish
+ Int ir, zzz;
+ vki_sigaction_toK_t sa, sa2;
+ vki_sigaction_fromK_t saved_sa;
+ VG_(memset)( &sa, 0, sizeof(sa) );
+ VG_(sigemptyset)(&sa.sa_mask);
+ sa.ksa_handler = VKI_SIG_DFL;
+ sa.sa_flags = 0;
+ ir = VG_(sigaction)(VKI_SIGCHLD, &sa, &saved_sa);
+ vg_assert(ir == 0);
+
+ zzz = VG_(waitpid)(pid, NULL, 0);
+
+ VG_(convert_sigaction_fromK_to_toK)( &saved_sa, &sa2 );
+ ir = VG_(sigaction)(VKI_SIGCHLD, &sa2, NULL);
+ vg_assert(ir == 0);
+ if (zzz < 0) {
+ VG_(fmsg)("%s: script returned code %d\n", scriptname, zzz);
+ }
+ }
+ break;
+ }
+ i++;
+ }
+ ENSURE_THIS_MUCH_SPACE(VG_(strlen)(result));
+ j += VG_(sprintf)(&out[j], "%s", result);
+ } else {
+ VG_(fmsg)("%s: expected '{' after '%%s'\n", option_name);
+ goto bad;
+ }
+ }
else {
// Something else, abort.
VG_(fmsg)("%s: expected 'p' or 'q' or '%%' after '%%'\n",
@@ -261,7 +375,7 @@
bad: {
HChar* opt = // 2: 1 for the '=', 1 for the NUL.
- VG_(malloc)( "options.efn.3",
+ VG_(malloc)( "options.efn.6",
VG_(strlen)(option_name) + VG_(strlen)(format) + 2 );
VG_(strcpy)(opt, option_name);
VG_(strcat)(opt, "=");
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users