On Sat, 10 Aug 2013 17:53:41 -0400 "L. D. James" <lja...@apollo3.com> wrote: [snip] > Chris, thanks again for your interest in my question. I apologize > for the delayed response, as I was on a support call for most of the > day. When I got back I trimmed down 500 lines of code to the example > below. > > This is 48 lines of my vpn connection routine. It's 48 out of the 500 > line application. In those 48 lines I have 4 lines outputting to the > console. I would like for those lines to output to a gui window. > > Those 4 lines are just some of the actually 25 lines of status that > will be output in the course of running the application. While it's > running and checking the connection it outputs either starts "*" or > dots "." at 10 second interval while it checks some of the file and > connection status. > > > // code begin > // ------------------------------------------------- > #include <iostream> > #include <fstream> > #include <unistd.h> > #include <string> > using namespace std; > int main(int argc, char* argv[]) { > string ret; > string server; > string command; > string runit(string c); > setuid(0); > server = argv[1]; > string peerentry = "/etc/ppp/peers/" + server; > command = "ls " + peerentry; > ret = runit(command); > if (ret != peerentry) { > cout << "Problems locating server: " << server << endl; // > console out > return 1; > } > string filetest = "/var/run/ppp-" + server + ".pid"; > ifstream myfile(filetest.c_str()); > > if (myfile.is_open()){ > cout << "Connection is in effect" << endl; // console out > myfile.close(); > } > else { > cout << "Connecting to..." << server << endl; // console out > command = "pppd call " + server; > ret = runit(command); > cout << "Results: [" << ret << "]" << endl; // console out > } > return 0; > } > string runit(std::string c){ > string lret = ""; > c += " 2>&1"; > FILE *in; > char buff[512]; > if (!(in = popen(c.c_str(), "r"))) { > return lret; > } > while (fgets(buff, sizeof(buff), in) != NULL) { > lret += buff; > } > pclose(in); > return lret; > } > // ------------------------------------------------- > // code end
This appears to be just a batch job calling popen() which brings up a ppp connection. There is no program loop anywhere and the while loop for fgets() in runit() will block until EOF is reached, which equates to the call to pppd ending and the process in which it is running closing its stdout. Presumably you run this as a cron job, or something like that? Or, since you say, "while it's running and checking the connection it outputs either starts '*' or dots '.' at 10 second interval while it checks some of the file and connection status", possibly you have excised the loop logic, which is the interesting part for present purposes. (As it happens, it will not compile because the prototype for runit() is not in namespace scope, but that is no doubt just a matter of transcription.) To call up an executable (in this case pppd) in this kind of usage using glib you would normally use Glib::spawn_async_with_pipes() and connect to the standard_output and standard_error file descriptors with Glib::signal_io().connect(). The problem you have got here though is that you call setuid(0) on a binary which presumably has its suid bit set in order to launch pppd. You should definitely not do that directly with a GTK+ program. You would need to have a small wrapper with suid set which calls up pppd, which is launched by your GTK+ program using Glib::spawn_async_with_pipes(). (Yuck.) As it happens, if you want a short cut for a batch job like this which provides a GTK+ user interface, I would consider a shell script and zenity, which is what zenity was intended for. A google search will tell you more. However you would still need to circumvent your setuid problem. Chris _______________________________________________ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list