void IRC_Client_GUI_MessageHandler::members (const string_list_t& list_in) { RPG_TRACE (ACE_TEXT ("IRC_Client_GUI_MessageHandler::members")); // sanity check(s) ACE_ASSERT (CBData_.GTKState); ACE_Guard<ACE_Thread_Mutex> aGuard (CBData_.GTKState->lock); Common_UI_GTKBuildersIterator_t iterator = CBData_.GTKState->builders.find (builderLabel_); // sanity check(s) ACE_ASSERT (iterator != CBData_.GTKState->builders.end ()); if (isFirstMemberListMsg_) { clearMembers (); isFirstMemberListMsg_ = false; } // end IF // retrieve channel liststore handle GtkListStore* list_store_p = GTK_LIST_STORE (gtk_builder_get_object ((*iterator).second.second, ACE_TEXT_ALWAYS_CHAR ("channel_liststore"))); ACE_ASSERT (list_store_p); GtkTreeIter iter; gchar* converted_nick_string = NULL; for (string_list_const_iterator_t iterator = list_in.begin (); iterator != list_in.end (); iterator++) { // step1: convert text converted_nick_string = Common_UI_Tools::Locale2UTF8 (*iterator); if (!converted_nick_string) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("failed to convert nickname: \"%s\", returning\n"))); return; } // end IF // step2: append new (text) entry gtk_list_store_append (list_store_p, &iter); gtk_list_store_set (list_store_p, &iter, 0, converted_nick_string, // column 0 -1); // clean up g_free (converted_nick_string); } // end FOR }
int ShellServer::caller(ServerContext& s, const char *cmd, string_list_t& args, string_map_t& env, process_io_t& io) { int result = 0; int status = 0; int pid = 0; int fdin[2]; /* child stdin - parent output */ int fdout[2]; /* Child stdout - parent block input */ int fderr[2]; /* Child stderr - parent result input */ int nargs = (int) args.size(); int nvars = (int) env.size(); string command = m_binpath + SEPSTR + cmd; args.push_front(command); (void) result; if (::access(command.c_str(), X_OK) < 0) { return -ENOSYS; } /* Make pipes */ if (pipe(fdin) < 0) { perror("Can't make pipe"); return -errno; } if (pipe(fdout) < 0) { perror("Can't make pipe"); return -errno; } if (pipe(fderr) < 0) { perror("Can't make pipe"); return -errno; } unsigned int i = 0; const char *envp[nvars + 3]; const char *argvs[nargs + 1]; char envbuf[2048]; char *envptr = envbuf; argvs[nargs + 1] = NULL; envp[nvars + 2] = NULL; string c = command; i = 0; for (string_list_t::iterator it = args.begin(); it != args.end(); it++) { argvs[i++] = (*it).c_str(); c += string(" ") + *it; } argvs[i] = 0; _DEBUG("-Running: %s", c.c_str()); i = 0; for (string_map_t::iterator it = env.begin(); it != env.end(); it++) { sprintf(envptr, "%s=%s", it->first.c_str(), it->second.c_str()); _DEBUG("-env: %s=%s", it->first.c_str(), it->second.c_str()); envp[i++] = envptr; envptr += strlen(envptr) + 1; } sprintf(envptr, "INETFS_CWD=%s", m_datapath.c_str()); envp[i++] = envptr; envptr += strlen(envptr) + 1; sprintf(envptr, "PWD=%s", m_datapath.c_str()); envp[i++] = envptr; envptr += strlen(envptr) + 1; envp[i] = NULL; switch ((pid = ::vfork())) { case -1: /* error */ //perror("Can't fork"); _DEBUG("-cfork failed with errno = %d", errno); return -errno; case 0: /* Child. */ { _DEBUG("+Child process"); ::close(2); if (2 != dup(fderr[1])) { ASSERT(0); } ::close(1); /* Close current stdout. */ if (1 != ::dup(fdout[1])) /* Make stdout go to write end of pipe. */ { ASSERT(0); } ::close(0); /* Close current stdin. */ if (0 != ::dup(fdin[0])) /* Make stdin come from read end of pipe. */ { ASSERT(0); } ::close(fderr[0]); ::close(fdout[0]); ::close(fdin[1]); ::chdir(m_datapath.c_str()); ::execvpe(command.c_str(), (char **) argvs, (char **) envp); status = -errno; perror("No exec"); //signal(getppid(), SIGQUIT); return status; } default: /* Parent. */ /* Close what we don't need. */ { ::close(fderr[1]); ::close(fdout[1]); ::close(fdin[0]); #if 0 struct sigaction sa; sa.sa_handler = &handle_sigchld; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; if (sigaction(SIGCHLD, &sa, 0) < 0) { perror("-Failed to set SIGCLD handler"); ::close(fderr[0]); ::close(fdout[0]); ::close(fdin[1]); return -errno; } #endif // write client stdin processing FILE* cfd_err = fdopen(fderr[0], "r"); FILE* cfd_in = NULL; if (io.input.length() > 0) { cfd_in = fdopen(fdin[1], "w"); fwrite(io.input.c_str(), io.input.length(), 1, cfd_in); fflush(cfd_in); } //read client sdtout //FILE* cfd_out = fdopen(fdout[1], "r"); if (fdout[0] > 0) { char buffer[4096]; int readlen = 0; do { readlen = (int) ::read(fdout[0], buffer, (int) sizeof(buffer)); if (readlen < 0) { result = -errno; break; } io.output.append(buffer, readlen); } while (readlen != 0); } if (!io.output.empty() && strncmp("@error ", io.output.c_str(), 7) == 0) { result = -atoi(io.output.c_str() + 7); } _DEBUG("-waiting for pid = %d", pid); if (waitpid(pid, &status, WNOHANG) < 0 && result == 0) { result = -errno; if (result == -ECHILD) // ignore ECHILD { result = 0; } } if (result == 0 && WIFEXITED(status)) { result = -WEXITSTATUS(status); } status = result; if (cfd_in) { fclose(cfd_in); } #if 0 if (cfd_out) { fclose(cfd_out); } #endif if (cfd_err) { fclose(cfd_err); } ::close(fderr[0]); ::close(fdout[0]); ::close(fdin[1]); } } return status; }