naomik Posted September 29, 2009 Share Posted September 29, 2009 I'm trying to call a program (hbplus) from the command line. When I run the program directly from the command line, it executes successfully. When I run the program using the script below, I get a segmentation fault. The console output says GLIBC_2.7 is not found, but I only get this error when I call the program from php. -bash-4.0$ cat hboutput ./hbplus: /lib/libc.so.6: version `GLIBC_2.7' not found (required by ./hbplus) When I run my program from the command line as shown, it executes succesfully. -bash-4.0$ ./hbplus 1PEF.pdb <?php echo '<pre>'; $last_line = system('./hbplus 1PEF.pdb &>hboutput', $retval); // Printing additional info echo ' </pre> <hr />Last line of the output: ' . $last_line . ' <hr />Return value: ' . $retval; ?> Link to comment https://forums.phpfreaks.com/topic/175940-c-program-seg-faults-when-called-in-php-script/ Share on other sites More sharing options...
jon23d Posted September 29, 2009 Share Posted September 29, 2009 Just a guess, but perhaps some environmental variable is missing that points to that library for the php user. I'd try comparing a list of the two and seeing whats different, then setting the one needed. Link to comment https://forums.phpfreaks.com/topic/175940-c-program-seg-faults-when-called-in-php-script/#findComment-927170 Share on other sites More sharing options...
naomik Posted September 30, 2009 Author Share Posted September 30, 2009 How would I list the environmental variables for the apache user? Also, I ran the ldd command on my C executable and got this information: -bash-4.0$ ldd hbplus linux-gate.so.1 => (0x00f6d000) libm.so.6 => /lib/libm.so.6 (0x0055b000) libc.so.6 => /lib/libc.so.6 (0x003e8000) /lib/ld-linux.so.2 (0x003c4000) Link to comment https://forums.phpfreaks.com/topic/175940-c-program-seg-faults-when-called-in-php-script/#findComment-927442 Share on other sites More sharing options...
naomik Posted September 30, 2009 Author Share Posted September 30, 2009 That was a good guess Jon. The C code that was causing the seg fault was the following: char rcfn[256]; strcpy(rcfn,getenv("HOME")); Since apache does not have a HOME environmental variable defined, getenv returns NULL. Then strcpy seg faults when trying to copy NULL into the buffer. I just modified the C code so that it checks if getenv returns NULL, and now everything is working fine. I still don't understand where the glibc error ("/lib/libc.so.6: version `GLIBC_2.7' not found") came from. Link to comment https://forums.phpfreaks.com/topic/175940-c-program-seg-faults-when-called-in-php-script/#findComment-927708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.