40 # if !defined(WIN32_LEAN_AND_MEAN) 41 # define WIN32_LEAN_AND_MEAN 45 # define C_MAXARGS 128 // the max number of command parameters. rational? 51 inline std::string lastError2String()
53 int error=GetLastError();
55 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, error, 0, buff, 1024,
nullptr);
57 return std::string(buff);
61 #define READ_FROM_PIPE 0 62 #define WRITE_TO_PIPE 1 63 #define REDIRECT_TO(from, to) yarp::run::impl::dup2(to, from) 73 std::string yarp::run::Run::mPortName;
75 int yarp::run::Run::mProcCNT=0;
76 bool yarp::run::Run::mStresstest=
false;
77 bool yarp::run::Run::mLogged=
false;
78 std::string yarp::run::Run::mLoggerPort(
"/yarplogger");
88 sprintf(msg,
"SIGNAL %d", sig);
91 if (pTerminator) pTerminator->
exit();
102 const char *at = txt.c_str();
105 for (
char ch : txt) {
107 result.
addString(std::string(at, len-slash_tweak));
113 slash_tweak = (ch==slash && len>0)?1:0;
117 result.
addString(std::string(at, len-slash_tweak));
124 fp = fopen(fname,
"r");
141 if (config.
check(
"server"))
143 mLogged=config.
check(
"log");
149 if (botPortLogger.
size()>1)
155 mPortName=std::string(config.
find(
"server").
asString());
160 if (config.
check(
"echo"))
163 fprintf(stderr,
"Program echo started.\n");
168 int ret=scanf(
"%s", line);
172 fprintf(stderr,
"%s\n", line);
188 fprintf(stderr,
"ERROR: no yarp network found.\n");
196 if (config.
check(
"readwrite"))
200 std::string fPortName;
201 std::string lPortName;
203 if (config.
check(
"forward"))
213 #elif defined(__APPLE__) 216 struct sigaction new_action;
218 sigfillset(&new_action.sa_mask);
219 new_action.sa_flags=0;
221 sigaction(SIGTERM, &new_action,
nullptr);
222 sigaction(SIGHUP, &new_action,
nullptr);
225 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
227 if (getppid()==1)
return 0;
229 yarp::os::impl::prctl(PR_SET_PDEATHSIG, SIGTERM);
231 struct sigaction new_action;
233 yarp::os::impl::sigfillset(&new_action.sa_mask);
234 new_action.sa_flags=0;
236 yarp::os::impl::sigaction(SIGTERM, &new_action,
nullptr);
237 yarp::os::impl::signal(SIGHUP, SIG_IGN);
239 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
254 if (config.
check(
"write"))
264 struct sigaction new_action;
266 yarp::os::impl::sigfillset(&new_action.sa_mask);
267 new_action.sa_flags=0;
268 yarp::os::impl::sigaction(SIGTERM, &new_action,
nullptr);
270 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
271 yarp::os::impl::signal(SIGHUP, SIG_IGN);
274 if (config.
check(
"log"))
295 if (config.
check(
"read"))
307 yarp::os::impl::signal(SIGHUP, SIG_IGN);
320 if (config.
check(
"stresstest"))
322 fprintf(stderr,
"Yarprun stress test started.\n");
325 int max_interval_ms=config.
find(
"stresstest").
asInt32();
330 config.
unput(
"stresstest");
334 bool isCommand=
false;
336 if (config.
check(
"cmd"))
343 unsigned int t=0, u=0;
347 char cmd_and_name[512];
351 std::random_device rd;
352 std::mt19937 mt(rd());
353 std::uniform_int_distribution<int> dist0maxint(0, max_interval_ms -1);
361 sprintf(tag,
"%s_%u", tag_zero.c_str(), t++);
362 stresser.
put(
"as", tag);
366 sprintf(cmd_and_name,
"%s --name /%s", cmd.c_str(), tag);
367 stresser.
put(
"cmd", cmd_and_name);
372 std::uniform_int_distribution<int> dist07(0, 7);
373 if (isCommand && ++term_cycle>=4)
377 int r = t - (dist07(mt));
379 for (
int i=u; i<r; ++i)
381 sprintf(tag,
"%s_%u", tag_zero.c_str(), i);
402 if (config.
check(
"help"))
410 if (config.
check(
"stdio")
411 || config.
check(
"cmd")
412 || config.
check(
"kill")
413 || config.
check(
"sigterm")
414 || config.
check(
"sigtermall")
415 || config.
check(
"exit")
416 || config.
check(
"isrunning")
417 || config.
check(
"ps")
418 || config.
check(
"env")
419 || config.
check(
"sysinfo")
420 || config.
check(
"which"))
436 for (
int r=0; r<RETRY; ++r)
440 if (!port.
open(
"..."))
453 RUNLOG(
"<<<port.write(msg, response)")
454 if (!port.
write(msg, response))
460 RUNLOG(
">>>port.write(msg, response)")
465 fprintf(stderr,
"RESPONSE:\n=========\n");
466 for (
size_t s=0; s<response.
size(); ++s)
468 fprintf(stderr,
"%s\n", response.
get(s).
toString().c_str());
476 response.
addString(
"Cannot connect to remote server, aborting...\n");
477 for (
size_t s=0; s<response.
size(); ++s)
479 fprintf(stderr,
"%s\n", response.
get(s).
toString().c_str());
487 yarp::run::Run::mStresstest=
false;
489 if (yarp::run::Run::pServerPort)
492 yarp::run::Run::pServerPort =
nullptr;
503 int yarp::run::Run::server()
509 if (!port.
open(mPortName.c_str()))
511 yError() <<
"Yarprun failed to open port: " << mPortName.c_str();
522 yInfo() <<
"Yarprun successfully started on port: " << mPortName.c_str();
536 RUNLOG(
"<<<port.read(msg, true)")
537 if (!port.
read(msg,
true))
break;
538 RUNLOG(
">>>port.read(msg, true)")
540 if (!pServerPort)
break;
548 if (msg.
check(
"stdio"))
553 if (strOnPort==mPortName)
561 if (mLogged || msg.
check(
"log"))
564 std::string portName=
"/log";
565 portName+=mPortName+
"/";
567 int space=command.find(
" ");
568 if (space!=std::string::npos) command=command.substr(0, space);
574 if (msg.
check(
"log"))
578 if (botLogger.
size()>1)
595 if (executeCmdAndStdio(msg, cmdResult)>0)
597 if (strStdioPort==mPortName)
600 userStdio(msg, stdioResult);
601 cmdResult.
append(stdioResult);
605 cmdResult.
append(sendMsg(msg, strStdioPort));
609 port.
reply(cmdResult);
614 userStdio(msg, stdioResult);
615 port.
reply(stdioResult);
622 if (msg.
check(
"cmd"))
626 if (msg.
check(
"log"))
630 if (botLogger.
size()>1)
632 std::string loggerName=botLogger.
get(1).
asString();
633 executeCmdStdout(msg, cmdResult, loggerName);
637 executeCmdStdout(msg, cmdResult, mLoggerPort);
642 executeCmdStdout(msg, cmdResult, mLoggerPort);
646 executeCmd(msg, cmdResult);
648 port.
reply(cmdResult);
652 if (msg.
check(
"kill"))
657 result.
addString(mProcessVector.Signal(alias, sig)?
"kill OK":
"kill FAILED");
662 if (msg.
check(
"sigterm"))
666 result.
addString(mProcessVector.Signal(alias, SIGTERM)?
"sigterm OK":
"sigterm FAILED");
671 if (msg.
check(
"sigtermall"))
673 mProcessVector.Killall(SIGTERM);
683 result.
append(mProcessVector.PS());
688 if (msg.
check(
"isrunning"))
692 result.
addString(mProcessVector.IsRunning(alias)?
"running":
"not running");
697 if (msg.
check(
"killstdio"))
700 mStdioVector.Signal(alias, SIGTERM);
709 if (msg.
check(
"sysinfo"))
716 if (msg.
check(
"which"))
722 for (
int i=0; i<possiblePaths.
size(); ++i)
725 const char* guess=guessString.c_str();
728 fileName=
"\"" + std::string(guess) +
"\"";
734 port.
reply(fileNameWriter);
738 if (msg.
check(
"exit"))
749 Run::mStdioVector.Killall(SIGTERM);
751 Run::mProcessVector.Killall(SIGTERM);
757 #else // LINUX SERVER 760 void yarp::run::Run::cleanBeforeExec()
772 mProcessVector =
nullptr;
778 mStdioVector =
nullptr;
781 if (mBraveZombieHunter)
784 mBraveZombieHunter =
nullptr;
792 void yarp::run::Run::writeToPipe(
int fd, std::string str)
794 int len=str.length()+1;
797 write(fd, str.c_str(), len);
800 int yarp::run::Run::readFromPipe(
int fd,
char* &data,
int& buffsize)
803 char* buff=(
char*)&len;
805 for (
int c=4, r=0; c>0; c-=r)
814 if (len<=0)
return 0;
819 data=
new char[buffsize=1024+(len/1024)*1024];
824 for (
int c=len, r=0; c>0; c-=r)
839 if (yarp::run::Run::mBraveZombieHunter)
845 int yarp::run::Run::server()
847 int pipe_server2manager[2];
848 int pipe_manager2server[2];
850 if (yarp::run::impl::pipe(pipe_server2manager))
852 fprintf(stderr,
"Can't open pipe because %s\n", strerror(errno));
858 if (yarp::run::impl::pipe(pipe_manager2server))
860 fprintf(stderr,
"Can't open pipe because %s\n", strerror(errno));
868 if (IS_INVALID(pid_process_manager))
874 CLOSE(pipe_manager2server[WRITE_TO_PIPE]);
875 CLOSE(pipe_manager2server[READ_FROM_PIPE]);
877 fprintf(stderr,
"Can't fork process manager because %s\n", strerror(error));
883 if (IS_PARENT_OF(pid_process_manager))
885 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
895 if (!port.
open(mPortName))
897 yError() <<
"Yarprun failed to open port: " << mPortName.c_str();
899 if (mPortName[0]!=
'/')
yError(
"Invalid port name '%s', it should start with '/'\n", mPortName.c_str());
910 yInfo() <<
"Yarprun successfully started on port: " << mPortName.c_str();
918 char *rsp_str=
new char[rsp_size];
924 RUNLOG(
"<<<port.read(msg, true)")
925 if (!port.
read(msg,
true))
break;
926 RUNLOG(
">>>port.read(msg, true)")
928 if (!pServerPort)
break;
930 if (msg.
check(
"sysinfo"))
937 if (msg.
check(
"which"))
943 for (
size_t i=0; i<possiblePaths.
size(); ++i)
946 const char* guess=guessString.c_str();
955 port.
reply(fileNameWriter);
959 if (msg.
check(
"exit"))
961 pServerPort =
nullptr;
970 writeToPipe(pipe_server2manager[WRITE_TO_PIPE], msg.
toString());
974 int nread=readFromPipe(pipe_manager2server[READ_FROM_PIPE], rsp_str, rsp_size);
979 fprintf(stderr,
"ERROR: broken pipe between server and manager\n");
987 port.
reply(response);
993 CLOSE(pipe_server2manager[WRITE_TO_PIPE]);
994 CLOSE(pipe_manager2server[READ_FROM_PIPE]);
1001 if (IS_NEW_PROCESS(pid_process_manager))
1003 yarp::os::impl::signal(SIGPIPE, SIG_IGN);
1014 mBraveZombieHunter->
start();
1021 char *msg_str=
new char[msg_size];
1028 RUNLOG(
"<<<readFromPipe")
1029 if (readFromPipe(pipe_server2manager[READ_FROM_PIPE], msg_str, msg_size)<=0)
break;
1030 RUNLOG(
">>>readFromPipe")
1038 if (msg.
check(
"stdio"))
1043 if (strOnPort==mPortName)
1051 if (mLogged || msg.
check(
"log"))
1054 std::string portName=
"/log";
1055 portName+=mPortName+
"/";
1057 size_t space=command.find(
' ');
1058 if (space!=std::string::npos) command=command.substr(0, space);
1064 if (msg.
check(
"log"))
1068 if (botLogger.
size()>1)
1089 if (executeCmdAndStdio(msg, cmdResult)>0)
1091 if (strStdioPort==mPortName)
1094 userStdio(msg, stdioResult);
1095 cmdResult.
append(stdioResult);
1099 cmdResult.
append(sendMsg(msg, strStdioPort));
1104 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], cmdResult.
toString());
1110 userStdio(msg, stdioResult);
1112 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], stdioResult.
toString());
1120 if (msg.
check(
"cmd"))
1124 if (msg.
check(
"log"))
1128 if (botLogger.
size()>1)
1130 std::string loggerName=botLogger.
get(1).
asString();
1131 executeCmdStdout(msg, cmdResult, loggerName);
1135 executeCmdStdout(msg, cmdResult, mLoggerPort);
1140 executeCmdStdout(msg, cmdResult, mLoggerPort);
1144 executeCmd(msg, cmdResult);
1148 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], cmdResult.
toString());
1153 if (msg.
check(
"kill"))
1158 result.
addString(mProcessVector->Signal(alias, sig)?
"kill OK":
"kill FAILED");
1160 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.
toString());
1165 if (msg.
check(
"sigterm"))
1169 result.
addString(mProcessVector->Signal(alias, SIGTERM)?
"sigterm OK":
"sigterm FAILED");
1171 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
1176 if (msg.
check(
"sigtermall"))
1178 mProcessVector->Killall(SIGTERM);
1183 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.
toString());
1188 if (msg.
check(
"ps"))
1191 result.
append(mProcessVector->PS());
1193 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.
toString());
1198 if (msg.
check(
"isrunning"))
1202 result.
addString(mProcessVector->IsRunning(alias)?
"running":
"not running");
1204 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.toString());
1209 if (msg.
check(
"killstdio"))
1212 mStdioVector->Signal(alias, SIGTERM);
1216 writeToPipe(pipe_manager2server[WRITE_TO_PIPE], result.
toString());
1222 mStdioVector->Killall(SIGTERM);
1224 mProcessVector->Killall(SIGTERM);
1226 if (mBraveZombieHunter)
1228 mBraveZombieHunter->stop();
1229 delete mBraveZombieHunter;
1230 mBraveZombieHunter =
nullptr;
1233 delete mProcessVector;
1235 delete mStdioVector;
1239 CLOSE(pipe_server2manager[READ_FROM_PIPE]);
1240 CLOSE(pipe_manager2server[WRITE_TO_PIPE]);
1257 if (config.
check(
"cmd") && config.
check(
"stdio"))
1263 Help(
"SYNTAX ERROR: missing remote stdio server\n");
1268 Help(
"SYNTAX ERROR: missing command\n");
1273 Help(
"SYNTAX ERROR: missing tag\n");
1278 Help(
"SYNTAX ERROR: missing remote server\n");
1284 printf(
"*********** %s ************\n", config.
toString().c_str());
1319 if (config.
check(
"cmd"))
1325 Help(
"SYNTAX ERROR: missing command\n");
1330 Help(
"SYNTAX ERROR: missing tag\n");
1335 Help(
"SYNTAX ERROR: missing remote server\n");
1371 if (config.
check(
"kill"))
1375 Help(
"SYNTAX ERROR: missing remote server\n");
1380 Help(
"SYNTAX ERROR: missing tag\n");
1385 Help(
"SYNTAX ERROR: missing signum\n");
1394 if (!response.
size())
1403 if (config.
check(
"sigterm"))
1407 Help(
"SYNTAX ERROR: missing tag");
1412 Help(
"SYNTAX ERROR: missing remote server\n");
1421 if (!response.
size())
1426 return response.
get(0).
asString()==
"sigterm OK"?0:2;
1430 if (config.
check(
"sigtermall"))
1434 Help(
"SYNTAX ERROR: missing remote server\n");
1443 if (!response.
size())
1451 if (config.
check(
"ps"))
1455 Help(
"SYNTAX ERROR: missing remote server\n");
1464 if (!response.
size())
1472 if (config.
check(
"isrunning"))
1476 Help(
"SYNTAX ERROR: missing remote server\n");
1482 Help(
"SYNTAX ERROR: missing tag\n");
1491 if (!response.
size())
1499 if (config.
check(
"sysinfo"))
1503 Help(
"SYNTAX ERROR: missing remote server\n");
1512 if (!port.
open(
"..."))
1514 fprintf(stderr,
"RESPONSE:\n=========\n");
1515 fprintf(stderr,
"Cannot open port, aborting...\n");
1524 fprintf(stderr,
"RESPONSE:\n=========\n");
1525 fprintf(stderr,
"Cannot connect to remote server, aborting...\n");
1533 RUNLOG(
"<<<port.write(msg, info)")
1535 RUNLOG(
">>>port.write(msg, info)")
1539 fprintf(stdout,
"RESPONSE:\n=========\n\n");
1543 fprintf(stdout,
"No response. (timeout)\n");
1548 fprintf(stdout,
"Platform name : %s\n", info.
platform.
name.c_str());
1550 fprintf(stdout,
"Platform release : %s\n", info.
platform.
release.c_str());
1552 fprintf(stdout,
"Platform kernel : %s\n\n", info.
platform.
kernel.c_str());
1554 fprintf(stdout,
"User Id : %d\n", info.
user.
userID);
1555 fprintf(stdout,
"User name : %s\n", info.
user.
userName.c_str());
1556 fprintf(stdout,
"User real name : %s\n", info.
user.
realName.c_str());
1557 fprintf(stdout,
"User home dir : %s\n\n", info.
user.
homeDir.c_str());
1560 fprintf(stdout,
"Cpu load 1 : %.2lf\n", info.
load.
cpuLoad1);
1561 fprintf(stdout,
"Cpu load 5 : %.2lf\n", info.
load.
cpuLoad5);
1562 fprintf(stdout,
"Cpu load 15 : %.2lf\n\n", info.
load.
cpuLoad15);
1570 fprintf(stdout,
"Processor model : %s\n", info.
processor.
model.c_str());
1573 fprintf(stdout,
"Processor vendor : %s\n", info.
processor.
vendor.c_str());
1587 if (config.
check(
"which"))
1591 Help(
"SYNTAX ERROR: missing remote server\n");
1601 if (!response.
size())
1608 if (config.
check(
"exit"))
1612 Help(
"SYNTAX ERROR: missing remote server\n");
1622 if (!response.
size())
1633 void yarp::run::Run::Help(
const char *msg)
1635 fprintf(stderr,
"%s", msg);
1636 fprintf(stderr,
"\nUSAGE:\n\n");
1637 fprintf(stderr,
"yarp run --server SERVERPORT\nrun a server on the local machine\n\n");
1638 fprintf(stderr,
"yarp run --on SERVERPORT --as TAG --cmd COMMAND [ARGLIST] [--workdir WORKDIR] [--env ENVIRONMENT]\nrun a command on SERVERPORT server\n\n");
1639 fprintf(stderr,
"yarp run --on SERVERPORT --as TAG --stdio STDIOSERVERPORT [--hold] [--geometry WxH+X+Y] --cmd COMMAND [ARGLIST] [--workdir WORKDIR] [--env ENVIRONMENT]\n");
1640 fprintf(stderr,
"run a command on SERVERPORT server sending I/O to STDIOSERVERPORT server\n\n");
1641 fprintf(stderr,
"yarp run --on SERVERPORT --kill TAG SIGNUM\nsend SIGNUM signal to TAG command\n\n");
1642 fprintf(stderr,
"yarp run --on SERVERPORT --sigterm TAG\nterminate TAG command\n\n");
1643 fprintf(stderr,
"yarp run --on SERVERPORT --sigtermall\nterminate all commands\n\n");
1644 fprintf(stderr,
"yarp run --on SERVERPORT --ps\nreport commands running on SERVERPORT\n\n");
1645 fprintf(stderr,
"yarp run --on SERVERPORT --isrunning TAG\nTAG command is running?\n\n");
1646 fprintf(stderr,
"yarp run --on SERVERPORT --sysinfo\nreport system information of SERVERPORT\n\n");
1647 fprintf(stderr,
"yarp run --on SERVERPORT --exit\nstop SERVERPORT server\n\n");
1663 std::string strStdioUUID=msg.
find(
"stdiouuid").
asString();
1667 SECURITY_ATTRIBUTES pipe_sec_attr;
1668 pipe_sec_attr.nLength=
sizeof(SECURITY_ATTRIBUTES);
1669 pipe_sec_attr.bInheritHandle=TRUE;
1670 pipe_sec_attr.lpSecurityDescriptor =
nullptr;
1671 HANDLE read_from_pipe_stdin_to_cmd, write_to_pipe_stdin_to_cmd;
1672 CreatePipe(&read_from_pipe_stdin_to_cmd, &write_to_pipe_stdin_to_cmd, &pipe_sec_attr, 0);
1673 HANDLE read_from_pipe_cmd_to_stdout, write_to_pipe_cmd_to_stdout;
1674 CreatePipe(&read_from_pipe_cmd_to_stdout, &write_to_pipe_cmd_to_stdout, &pipe_sec_attr, 0);
1677 PROCESS_INFORMATION stdout_process_info;
1678 ZeroMemory(&stdout_process_info,
sizeof(PROCESS_INFORMATION));
1679 STARTUPINFO stdout_startup_info;
1680 ZeroMemory(&stdout_startup_info,
sizeof(STARTUPINFO));
1682 stdout_startup_info.cb=
sizeof(STARTUPINFO);
1683 stdout_startup_info.hStdError=GetStdHandle(STD_ERROR_HANDLE);
1684 stdout_startup_info.hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
1685 stdout_startup_info.hStdInput=read_from_pipe_cmd_to_stdout;
1686 stdout_startup_info.dwFlags|=STARTF_USESTDHANDLES;
1688 BOOL bSuccess=CreateProcess(
nullptr,
1689 (
char*)(std::string(
"yarprun --write ")+strStdioUUID).c_str(),
1693 CREATE_NEW_PROCESS_GROUP,
1696 &stdout_startup_info,
1697 &stdout_process_info);
1701 std::string strError=std::string(
"ABORTED: server=")+mPortName
1702 +std::string(
" alias=")+strAlias
1703 +std::string(
" cmd=stdout\n")
1704 +std::string(
"Can't execute stdout because ")+lastError2String()
1709 fprintf(stderr,
"%s", strError.c_str());
1712 CloseHandle(write_to_pipe_stdin_to_cmd);
1713 CloseHandle(read_from_pipe_stdin_to_cmd);
1714 CloseHandle(write_to_pipe_cmd_to_stdout);
1715 CloseHandle(read_from_pipe_cmd_to_stdout);
1722 PROCESS_INFORMATION stdin_process_info;
1723 ZeroMemory(&stdin_process_info,
sizeof(PROCESS_INFORMATION));
1724 STARTUPINFO stdin_startup_info;
1725 ZeroMemory(&stdin_startup_info,
sizeof(STARTUPINFO));
1727 stdin_startup_info.cb=
sizeof(STARTUPINFO);
1728 stdin_startup_info.hStdError=write_to_pipe_stdin_to_cmd;
1729 stdin_startup_info.hStdOutput=write_to_pipe_stdin_to_cmd;
1730 stdin_startup_info.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
1731 stdin_startup_info.dwFlags|=STARTF_USESTDHANDLES;
1733 bSuccess=CreateProcess(
nullptr,
1734 (
char*)(std::string(
"yarprun --read ")+strStdioUUID).c_str(),
1738 CREATE_NEW_PROCESS_GROUP,
1741 &stdin_startup_info,
1742 &stdin_process_info);
1746 std::string strError=std::string(
"ABORTED: server=")+mPortName
1747 +std::string(
" alias=")+strAlias
1748 +std::string(
" cmd=stdin\n")
1749 +std::string(
"Can't execute stdin because ")+lastError2String()
1754 fprintf(stderr,
"%s", strError.c_str());
1756 TerminateProcess(stdout_process_info.hProcess,
YARPRUN_ERROR);
1758 CloseHandle(stdout_process_info.hProcess);
1760 CloseHandle(write_to_pipe_stdin_to_cmd);
1761 CloseHandle(read_from_pipe_stdin_to_cmd);
1762 CloseHandle(write_to_pipe_cmd_to_stdout);
1763 CloseHandle(read_from_pipe_cmd_to_stdout);
1770 PROCESS_INFORMATION cmd_process_info;
1771 ZeroMemory(&cmd_process_info,
sizeof(PROCESS_INFORMATION));
1772 STARTUPINFO cmd_startup_info;
1773 ZeroMemory(&cmd_startup_info,
sizeof(STARTUPINFO));
1775 cmd_startup_info.cb=
sizeof(STARTUPINFO);
1776 cmd_startup_info.hStdError=write_to_pipe_cmd_to_stdout;
1777 cmd_startup_info.hStdOutput=write_to_pipe_cmd_to_stdout;
1778 cmd_startup_info.hStdInput=read_from_pipe_stdin_to_cmd;
1779 cmd_startup_info.dwFlags|=STARTF_USESTDHANDLES;
1784 for (
int s=0; s<botCmd.
size(); ++s)
1786 strCmd+=botCmd.
get(s).
toString()+std::string(
" ");
1792 TCHAR chNewEnv[32767];
1795 LPTCH chOldEnv = GetEnvironmentStrings();
1798 LPTSTR lpOld = (LPTSTR) chOldEnv;
1799 LPTSTR lpNew = (LPTSTR) chNewEnv;
1802 lstrcpy(lpNew, lpOld);
1803 lpOld += lstrlen(lpOld) + 1;
1804 lpNew += lstrlen(lpNew) + 1;
1808 std::string cstrEnvName;
1809 if (msg.
check(
"env"))
1812 for(
int i=0; i<ss.size(); i++) {
1813 lstrcpy(lpNew, (LPTCH) ss.get(i));
1814 lpNew += lstrlen(lpNew) + 1;
1821 bool bWorkdir=msg.
check(
"workdir");
1822 std::string strWorkdir=bWorkdir?msg.
find(
"workdir").
asString()+
"\\":
"";
1824 bSuccess=CreateProcess(
nullptr,
1825 (
char*)(strWorkdir+strCmd).c_str(),
1829 CREATE_NEW_PROCESS_GROUP,
1831 bWorkdir ? strWorkdir.c_str() :
nullptr,
1835 if (!bSuccess && bWorkdir)
1837 bSuccess=CreateProcess(
nullptr,
1838 (
char*)(strCmd.c_str()),
1842 CREATE_NEW_PROCESS_GROUP,
1850 FreeEnvironmentStrings(chOldEnv);
1857 std::string line1=std::string(
"ABORTED: server=")+mPortName
1858 +std::string(
" alias=")+strAlias
1859 +std::string(
" cmd=")+strCmd
1860 +std::string(
"pid=")+
int2String(cmd_process_info.dwProcessId)
1863 WriteFile(write_to_pipe_cmd_to_stdout, line1.c_str(), line1.length(), &nBytes, 0);
1865 std::string line2=std::string(
"Can't execute command because ")+lastError2String()+std::string(
"\n");
1866 WriteFile(write_to_pipe_cmd_to_stdout, line1.c_str(), line2.length(), &nBytes, 0);
1867 FlushFileBuffers(write_to_pipe_cmd_to_stdout);
1869 std::string out=line1+line2;
1871 fprintf(stderr,
"%s", out.c_str());
1874 CloseHandle(write_to_pipe_stdin_to_cmd);
1875 CloseHandle(read_from_pipe_stdin_to_cmd);
1876 CloseHandle(write_to_pipe_cmd_to_stdout);
1877 CloseHandle(read_from_pipe_cmd_to_stdout);
1879 TerminateProcess(stdout_process_info.hProcess,
YARPRUN_ERROR);
1881 CloseHandle(stdout_process_info.hProcess);
1883 TerminateProcess(stdin_process_info.hProcess,
YARPRUN_ERROR);
1885 CloseHandle(stdin_process_info.hProcess);
1890 FlushFileBuffers(write_to_pipe_cmd_to_stdout);
1896 cmd_process_info.dwProcessId,
1899 stdin_process_info.dwProcessId,
1900 stdout_process_info.dwProcessId,
1901 read_from_pipe_stdin_to_cmd,
1902 write_to_pipe_stdin_to_cmd,
1903 read_from_pipe_cmd_to_stdout,
1904 write_to_pipe_cmd_to_stdout,
1905 cmd_process_info.hProcess,
1909 if (msg.
check(
"env"))
1913 mProcessVector.Add(pInf);
1915 result.
addInt32(cmd_process_info.dwProcessId);
1916 std::string out=std::string(
"STARTED: server=")+mPortName
1917 +std::string(
" alias=")+strAlias
1918 +std::string(
" cmd=")+strCmd
1919 +std::string(
"pid=")+
int2String(cmd_process_info.dwProcessId)
1924 fprintf(stderr,
"%s", out.c_str());
1926 return cmd_process_info.dwProcessId;
1932 std::string portName=
"/log";
1933 portName+=mPortName+
"/";
1935 int space=command.find(
" ");
1936 if (space!=std::string::npos) command=command.substr(0, space);
1940 SECURITY_ATTRIBUTES pipe_sec_attr;
1941 pipe_sec_attr.nLength=
sizeof(SECURITY_ATTRIBUTES);
1942 pipe_sec_attr.bInheritHandle=TRUE;
1943 pipe_sec_attr.lpSecurityDescriptor =
nullptr;
1944 HANDLE read_from_pipe_cmd_to_stdout, write_to_pipe_cmd_to_stdout;
1945 CreatePipe(&read_from_pipe_cmd_to_stdout, &write_to_pipe_cmd_to_stdout, &pipe_sec_attr, 0);
1948 PROCESS_INFORMATION stdout_process_info;
1949 ZeroMemory(&stdout_process_info,
sizeof(PROCESS_INFORMATION));
1950 STARTUPINFO stdout_startup_info;
1951 ZeroMemory(&stdout_startup_info,
sizeof(STARTUPINFO));
1953 stdout_startup_info.cb=
sizeof(STARTUPINFO);
1954 stdout_startup_info.hStdError=GetStdHandle(STD_ERROR_HANDLE);
1955 stdout_startup_info.hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
1956 stdout_startup_info.hStdInput=read_from_pipe_cmd_to_stdout;
1957 stdout_startup_info.dwFlags|=STARTF_USESTDHANDLES;
1959 BOOL bSuccess=CreateProcess(
nullptr,
1960 (
char*)(std::string(
"yarprun --log ")+loggerName+std::string(
" --write ")+portName).c_str(),
1964 CREATE_NEW_PROCESS_GROUP,
1967 &stdout_startup_info,
1968 &stdout_process_info);
1972 std::string strError=std::string(
"ABORTED: server=")+mPortName
1973 +std::string(
" alias=")+strAlias
1974 +std::string(
" cmd=stdout\n")
1975 +std::string(
"Can't execute stdout because ")+lastError2String()
1980 fprintf(stderr,
"%s", strError.c_str());
1983 CloseHandle(write_to_pipe_cmd_to_stdout);
1984 CloseHandle(read_from_pipe_cmd_to_stdout);
1991 PROCESS_INFORMATION cmd_process_info;
1992 ZeroMemory(&cmd_process_info,
sizeof(PROCESS_INFORMATION));
1993 STARTUPINFO cmd_startup_info;
1994 ZeroMemory(&cmd_startup_info,
sizeof(STARTUPINFO));
1996 cmd_startup_info.cb=
sizeof(STARTUPINFO);
1997 cmd_startup_info.hStdError=write_to_pipe_cmd_to_stdout;
1998 cmd_startup_info.hStdOutput=write_to_pipe_cmd_to_stdout;
1999 cmd_startup_info.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
2000 cmd_startup_info.dwFlags|=STARTF_USESTDHANDLES;
2005 for (
int s=0; s<botCmd.
size(); ++s)
2007 strCmd+=botCmd.
get(s).
toString()+std::string(
" ");
2013 TCHAR chNewEnv[32767];
2016 LPTCH chOldEnv = GetEnvironmentStrings();
2019 LPTSTR lpOld = (LPTSTR) chOldEnv;
2020 LPTSTR lpNew = (LPTSTR) chNewEnv;
2023 lstrcpy(lpNew, lpOld);
2024 lpOld += lstrlen(lpOld) + 1;
2025 lpNew += lstrlen(lpNew) + 1;
2029 std::string cstrEnvName;
2030 if (msg.
check(
"env"))
2032 lstrcpy(lpNew, (LPTCH) msg.
find(
"env").
asString().c_str());
2033 lpNew += lstrlen(lpNew) + 1;
2039 bool bWorkdir=msg.
check(
"workdir");
2040 std::string strWorkdir=bWorkdir?msg.
find(
"workdir").
asString()+
"\\":
"";
2042 bSuccess=CreateProcess(
nullptr,
2043 (
char*)(strWorkdir+strCmd).c_str(),
2047 CREATE_NEW_PROCESS_GROUP,
2049 bWorkdir?strWorkdir.c_str():
nullptr,
2053 if (!bSuccess && bWorkdir)
2055 bSuccess=CreateProcess(
nullptr,
2056 (
char*)(strCmd.c_str()),
2060 CREATE_NEW_PROCESS_GROUP,
2068 FreeEnvironmentStrings(chOldEnv);
2075 std::string line1=std::string(
"ABORTED: server=")+mPortName
2076 +std::string(
" alias=")+strAlias
2077 +std::string(
" cmd=")+strCmd
2078 +std::string(
"pid=")+
int2String(cmd_process_info.dwProcessId)
2081 WriteFile(write_to_pipe_cmd_to_stdout, line1.c_str(), line1.length(), &nBytes, 0);
2083 std::string line2=std::string(
"Can't execute command because ")+lastError2String()+std::string(
"\n");
2084 WriteFile(write_to_pipe_cmd_to_stdout, line1.c_str(), line2.length(), &nBytes, 0);
2085 FlushFileBuffers(write_to_pipe_cmd_to_stdout);
2087 std::string out=line1+line2;
2089 fprintf(stderr,
"%s", out.c_str());
2092 CloseHandle(write_to_pipe_cmd_to_stdout);
2093 CloseHandle(read_from_pipe_cmd_to_stdout);
2095 TerminateProcess(stdout_process_info.hProcess,
YARPRUN_ERROR);
2097 CloseHandle(stdout_process_info.hProcess);
2102 FlushFileBuffers(write_to_pipe_cmd_to_stdout);
2108 cmd_process_info.dwProcessId,
2109 stdout_process_info.dwProcessId,
2110 read_from_pipe_cmd_to_stdout,
2111 write_to_pipe_cmd_to_stdout,
2112 cmd_process_info.hProcess,
2119 if (msg.
check(
"env"))
2123 mProcessVector.Add(pInf);
2125 result.
addInt32(cmd_process_info.dwProcessId);
2126 std::string out=std::string(
"STARTED: server=")+mPortName
2127 +std::string(
" alias=")+strAlias
2128 +std::string(
" cmd=")+strCmd
2129 +std::string(
"pid=")+
int2String(cmd_process_info.dwProcessId)
2134 fprintf(stderr,
"%s", out.c_str());
2136 return cmd_process_info.dwProcessId;
2142 std::string strAlias=msg.
find(
"as").
asString().c_str();
2145 PROCESS_INFORMATION cmd_process_info;
2146 ZeroMemory(&cmd_process_info,
sizeof(PROCESS_INFORMATION));
2147 STARTUPINFO cmd_startup_info;
2148 ZeroMemory(&cmd_startup_info,
sizeof(STARTUPINFO));
2150 cmd_startup_info.cb=
sizeof(STARTUPINFO);
2155 for (
int s=0; s<botCmd.
size(); ++s)
2157 strCmd+=botCmd.
get(s).
toString()+std::string(
" ");
2179 TCHAR chNewEnv[32767];
2182 LPTCH chOldEnv = GetEnvironmentStrings();
2185 LPTSTR lpOld = (LPTSTR) chOldEnv;
2186 LPTSTR lpNew = (LPTSTR) chNewEnv;
2189 lstrcpy(lpNew, lpOld);
2190 lpOld += lstrlen(lpOld) + 1;
2191 lpNew += lstrlen(lpNew) + 1;
2195 std::string cstrEnvName;
2196 if (msg.
check(
"env"))
2198 lstrcpy(lpNew, (LPTCH) msg.
find(
"env").
asString().c_str());
2199 lpNew += lstrlen(lpNew) + 1;
2205 bool bWorkdir=msg.
check(
"workdir");
2206 std::string strWorkdir=bWorkdir?msg.
find(
"workdir").
asString()+
"\\":
"";
2208 BOOL bSuccess=CreateProcess(
nullptr,
2209 (
char*)(strWorkdir+strCmd).c_str(),
2213 CREATE_NEW_PROCESS_GROUP,
2215 bWorkdir ? strWorkdir.c_str() :
nullptr,
2219 if (!bSuccess && bWorkdir)
2221 bSuccess=CreateProcess(
nullptr,
2222 (
char*)(strCmd.c_str()),
2226 CREATE_NEW_PROCESS_GROUP,
2234 FreeEnvironmentStrings(chOldEnv);
2240 std::string out=std::string(
"ABORTED: server=")+mPortName
2241 +std::string(
" alias=")+strAlias
2242 +std::string(
" cmd=")+strCmd
2243 +std::string(
" pid=")+
int2String(cmd_process_info.dwProcessId)
2244 +std::string(
"\nCan't execute command because ")+lastError2String()
2248 fprintf(stderr,
"%s", out.c_str());
2257 cmd_process_info.dwProcessId,
2258 cmd_process_info.hProcess,
2261 if (msg.
check(
"env"))
2264 mProcessVector.Add(pInf);
2266 result.
addInt32(cmd_process_info.dwProcessId);
2267 std::string out=std::string(
"STARTED: server=")+mPortName
2268 +std::string(
" alias=")+strAlias
2269 +std::string(
" cmd=")+strCmd
2270 +std::string(
"pid=")+
int2String(cmd_process_info.dwProcessId)
2273 fprintf(stderr,
"%s", out.c_str());
2275 return cmd_process_info.dwProcessId;
2281 PROCESS_INFORMATION stdio_process_info;
2282 ZeroMemory(&stdio_process_info,
sizeof(PROCESS_INFORMATION));
2284 STARTUPINFO stdio_startup_info;
2285 ZeroMemory(&stdio_startup_info,
sizeof(STARTUPINFO));
2286 stdio_startup_info.cb=
sizeof(STARTUPINFO);
2287 stdio_startup_info.wShowWindow=SW_SHOWNOACTIVATE;
2288 stdio_startup_info.dwFlags=STARTF_USESHOWWINDOW;
2292 std::string strCmd=std::string(
"yarprun --readwrite ")+strUUID;
2295 BOOL bSuccess=CreateProcess(
nullptr,
2296 (
char*)strCmd.c_str(),
2303 &stdio_startup_info,
2304 &stdio_process_info);
2312 stdio_process_info.dwProcessId,
2313 stdio_process_info.hProcess,
2316 out=std::string(
"STARTED: server=")+mPortName
2317 +std::string(
" alias=")+strAlias
2318 +std::string(
" cmd=stdio pid=")+
int2String(stdio_process_info.dwProcessId)
2325 out=std::string(
"ABORTED: server=")+mPortName
2326 +std::string(
" alias=")+strAlias
2327 +std::string(
" cmd=stdio\n")
2328 +std::string(
"Can't open stdio window because ")+lastError2String()
2333 result.
addInt32(stdio_process_info.dwProcessId);
2335 fprintf(stderr,
"%s", out.c_str());
2338 return stdio_process_info.dwProcessId;
2395 char *pTmp = strchr(pLine,
' ');
2400 while ((*pTmp) && (*pTmp ==
' ')) {
2403 if (*pTmp ==
'\0') {
2417 char *pNext = io_pLine;
2421 size_t len = strlen(io_pLine);
2424 for(i = 0; i < len; i++) {
2425 if ((!quoted) && (
'"' == io_pLine[i])) {
2428 }
else if ((quoted) && (
'"' == io_pLine[i])) {
2431 }
else if ((quoted) && (
' ' == io_pLine[i])) {
2437 memset(o_pArgv, 0x00,
sizeof(
char*) *
C_MAXARGS);
2439 o_pArgv[0] = io_pLine;
2441 while ((
nullptr != pNext) && (*o_pArgc < C_MAXARGS)) {
2443 pNext = o_pArgv[*o_pArgc];
2445 if (
nullptr != o_pArgv[*o_pArgc]) {
2450 for(j = 0; j < *o_pArgc; j++) {
2451 len = strlen(o_pArgv[j]);
2452 for(i = 0; i < len; i++) {
2453 if (
'\1' == o_pArgv[j][i]) {
2454 o_pArgv[j][i] =
' ';
2460 void yarp::run::Run::CleanZombie(
int pid)
2462 bool bFound=mProcessVector && mProcessVector->CleanZombie(pid);
2464 if (!bFound)
if (mStdioVector) mStdioVector->CleanZombie(pid);
2474 std::string strStdioUUID=msg.
find(
"stdiouuid").
asString();
2476 int pipe_stdin_to_cmd[2];
2477 int ret_stdin_to_cmd=yarp::run::impl::pipe(pipe_stdin_to_cmd);
2479 int pipe_cmd_to_stdout[2];
2480 int ret_cmd_to_stdout=yarp::run::impl::pipe(pipe_cmd_to_stdout);
2482 int pipe_child_to_parent[2];
2483 int ret_child_to_parent=yarp::run::impl::pipe(pipe_child_to_parent);
2485 if (ret_child_to_parent!=0 || ret_cmd_to_stdout!=0 || ret_stdin_to_cmd!=0)
2489 std::string out=std::string(
"ABORTED: server=")+mPortName
2490 +std::string(
" alias=")+strAlias
2491 +std::string(
" cmd=stdout\n")
2492 +std::string(
"Can't create pipes ")+strerror(error)
2497 fprintf(stderr,
"%s", out.c_str());
2504 if (IS_INVALID(pid_stdout))
2510 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2511 CLOSE(pipe_cmd_to_stdout[READ_FROM_PIPE]);
2512 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2513 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2515 std::string out=std::string(
"ABORTED: server=")+mPortName
2516 +std::string(
" alias=")+strAlias
2517 +std::string(
" cmd=stdout\n")
2518 +std::string(
"Can't fork stdout process because ")+strerror(error)
2523 fprintf(stderr,
"%s", out.c_str());
2528 if (IS_NEW_PROCESS(pid_stdout))
2533 CLOSE(pipe_stdin_to_cmd[READ_FROM_PIPE]);
2534 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2535 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2544 int ret = yarp::run::impl::execlp(
"yarprun",
"yarprun",
"--write", strStdioUUID.c_str(),
static_cast<char*
>(
nullptr));
2546 CLOSE(pipe_cmd_to_stdout[READ_FROM_PIPE]);
2552 std::string out=std::string(
"ABORTED: server=")+mPortName
2553 +std::string(
" alias=")+strAlias
2554 +std::string(
" cmd=stdout\n")
2555 +std::string(
"Can't execute stdout because ")+strerror(error)
2558 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
2559 fprintf(out_to_parent,
"%s", out.c_str());
2560 fflush(out_to_parent);
2561 fclose(out_to_parent);
2563 fprintf(stderr,
"%s", out.c_str());
2566 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2571 if (IS_PARENT_OF(pid_stdout))
2575 fprintf(stderr,
"STARTED: server=%s alias=%s cmd=stdout pid=%d\n", mPortName.c_str(), strAlias.c_str(), pid_stdout);
2579 if (IS_INVALID(pid_stdin))
2584 CLOSE(pipe_stdin_to_cmd[READ_FROM_PIPE]);
2585 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2586 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2587 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2589 std::string out=std::string(
"ABORTED: server=")+mPortName
2590 +std::string(
" alias=")+strAlias
2591 +std::string(
" cmd=stdin\n")
2592 +std::string(
"Can't fork stdin process because ")+strerror(error)
2597 fprintf(stderr,
"%s", out.c_str());
2599 SIGNAL(pid_stdout, SIGTERM);
2600 fprintf(stderr,
"TERMINATING stdout (%d)\n", pid_stdout);
2605 if (IS_NEW_PROCESS(pid_stdin))
2608 REDIRECT_TO(STDERR_FILENO, pipe_stdin_to_cmd[WRITE_TO_PIPE]);
2610 CLOSE(pipe_stdin_to_cmd[READ_FROM_PIPE]);
2611 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2612 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2621 int ret = yarp::run::impl::execlp(
"yarprun",
"yarprun",
"--read", strStdioUUID.c_str(),
static_cast<char*
>(
nullptr));
2623 CLOSE(pipe_stdin_to_cmd[WRITE_TO_PIPE]);
2629 std::string out=std::string(
"ABORTED: server=")+mPortName
2630 +std::string(
" alias=")+strAlias
2631 +std::string(
" cmd=stdin\n")
2632 +std::string(
"Can't execute stdin because ")+strerror(error)
2636 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
2637 fprintf(out_to_parent,
"%s", out.c_str());
2638 fflush(out_to_parent);
2639 fclose(out_to_parent);
2640 fprintf(stderr,
"%s", out.c_str());
2643 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2648 if (IS_PARENT_OF(pid_stdin))
2653 fprintf(stderr,
"STARTED: server=%s alias=%s cmd=stdin pid=%d\n", mPortName.c_str(), strAlias.c_str(), pid_stdin);
2657 if (IS_INVALID(pid_cmd))
2661 CLOSE(pipe_stdin_to_cmd[READ_FROM_PIPE]);
2662 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2663 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2665 std::string out=std::string(
"ABORTED: server=")+mPortName
2666 +std::string(
" alias=")+strAlias
2667 +std::string(
" cmd=")+strCmd
2668 +std::string(
"\nCan't fork command process because ")+strerror(error)
2673 fprintf(stderr,
"%s", out.c_str());
2675 FILE* to_yarp_stdout=fdopen(pipe_cmd_to_stdout[WRITE_TO_PIPE],
"w");
2676 fprintf(to_yarp_stdout,
"%s", out.c_str());
2677 fflush(to_yarp_stdout);
2678 fclose(to_yarp_stdout);
2680 SIGNAL(pid_stdout, SIGTERM);
2681 fprintf(stderr,
"TERMINATING stdout (%d)\n", pid_stdout);
2682 SIGNAL(pid_stdin, SIGTERM);
2683 fprintf(stderr,
"TERMINATING stdin (%d)\n", pid_stdin);
2685 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2690 if (IS_NEW_PROCESS(pid_cmd))
2692 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2694 char *cmd_str=
new char[strCmd.length()+1];
2695 strcpy(cmd_str, strCmd.c_str());
2703 char **arg_str =
new char*[
C_MAXARGS + 1];
2705 arg_str[nargs]=
nullptr;
2707 setvbuf(stdout,
nullptr, _IONBF, 0);
2709 REDIRECT_TO(STDIN_FILENO, pipe_stdin_to_cmd[READ_FROM_PIPE]);
2710 REDIRECT_TO(STDOUT_FILENO, pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2711 REDIRECT_TO(STDERR_FILENO, pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2713 if (msg.
check(
"env"))
2716 for(
int i=0; i<ss.size(); i++) {
2717 char* szenv =
new char[strlen(ss.get(i))+1];
2718 strcpy(szenv, ss.get(i));
2719 yarp::os::impl::putenv(szenv);
2724 if (msg.
check(
"workdir"))
2726 int ret = yarp::os::impl::chdir(msg.
find(
"workdir").
asString().c_str());
2732 std::string out=std::string(
"ABORTED: server=")+mPortName
2733 +std::string(
" alias=")+strAlias
2734 +std::string(
" cmd=")+strCmd
2735 +std::string(
"\nCan't execute command, cannot set working directory ")+strerror(error)
2738 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
2739 fprintf(out_to_parent,
"%s", out.c_str());
2740 fflush(out_to_parent);
2741 fclose(out_to_parent);
2742 fprintf(stderr,
"%s", out.c_str());
2750 char currWorkDirBuff[1024];
2755 char **cwd_arg_str=
new char*[nargs+1];
2756 for (
int i=1; i<nargs; ++i) cwd_arg_str[i]=arg_str[i];
2757 cwd_arg_str[nargs]=
nullptr;
2758 cwd_arg_str[0]=
new char[strlen(currWorkDir)+strlen(arg_str[0])+16];
2760 strcpy(cwd_arg_str[0], currWorkDir);
2761 strcat(cwd_arg_str[0],
"/");
2762 strcat(cwd_arg_str[0], arg_str[0]);
2769 ret = yarp::run::impl::execvp(cwd_arg_str[0], cwd_arg_str);
2771 delete [] cwd_arg_str[0];
2772 delete [] cwd_arg_str;
2782 ret = yarp::run::impl::execvp(arg_str[0], arg_str);
2787 CLOSE(pipe_stdin_to_cmd[READ_FROM_PIPE]);
2788 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2794 std::string out=std::string(
"ABORTED: server=")+mPortName
2795 +std::string(
" alias=")+strAlias
2796 +std::string(
" cmd=")+strCmd
2797 +std::string(
"\nCan't execute command because ")+strerror(error)
2800 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
2801 fprintf(out_to_parent,
"%s", out.c_str());
2802 fflush(out_to_parent);
2803 fclose(out_to_parent);
2804 fprintf(stderr,
"%s", out.c_str());
2810 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2816 if (IS_PARENT_OF(pid_cmd))
2818 CLOSE(pipe_stdin_to_cmd[READ_FROM_PIPE]);
2819 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
2820 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2831 pipe_stdin_to_cmd[READ_FROM_PIPE],
2832 pipe_stdin_to_cmd[WRITE_TO_PIPE],
2833 pipe_cmd_to_stdout[READ_FROM_PIPE],
2834 pipe_cmd_to_stdout[WRITE_TO_PIPE],
2839 pInf->setCmd(strCmd);
2841 if (msg.
check(
"env"))
2846 mProcessVector->Add(pInf);
2850 FILE* in_from_child=fdopen(pipe_child_to_parent[READ_FROM_PIPE],
"r");
2851 int flags=fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_GETFL, 0);
2852 fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_SETFL, flags|O_NONBLOCK);
2862 if (!fgets(buff, 1024, in_from_child) || ferror(in_from_child) || feof(in_from_child))
break;
2864 out+=std::string(buff);
2867 fclose(in_from_child);
2876 out=std::string(
"STARTED: server=")+mPortName
2877 +std::string(
" alias=")+strAlias
2878 +std::string(
" cmd=")+strCmd
2887 fprintf(stderr,
"%s", out.c_str());
2889 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2897 result.
addString(
"I should never reach this point!!!\n");
2907 std::string portName=
"/log";
2908 portName+=mPortName+
"/";
2910 std::string command=strCmd;
2911 size_t space=command.find(
' ');
2912 if (space != std::string::npos) {
2913 command=command.substr(0, space);
2919 int pipe_cmd_to_stdout[2];
2920 int ret_cmd_to_stdout=yarp::run::impl::pipe(pipe_cmd_to_stdout);
2922 int pipe_child_to_parent[2];
2923 int ret_child_to_parent=yarp::run::impl::pipe(pipe_child_to_parent);
2925 if (ret_child_to_parent!=0 || ret_cmd_to_stdout!=0)
2929 std::string out=std::string(
"ABORTED: server=")+mPortName
2930 +std::string(
" alias=")+strAlias
2931 +std::string(
" cmd=stdout\n")
2932 +std::string(
"Can't create pipes ")+strerror(error)
2937 fprintf(stderr,
"%s", out.c_str());
2944 if (IS_INVALID(pid_stdout))
2950 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
2951 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2953 std::string out=std::string(
"ABORTED: server=")+mPortName
2954 +std::string(
" alias=")+strAlias
2955 +std::string(
" cmd=stdout\n")
2956 +std::string(
"Can't fork stdout process because ")+strerror(error)
2961 fprintf(stderr,
"%s", out.c_str());
2966 if (IS_NEW_PROCESS(pid_stdout))
2971 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
2980 int ret = yarp::run::impl::execlp(
"yarprun",
"yarprun",
"--write", portName.c_str(),
"--log", loggerName.c_str(),
static_cast<char*
>(
nullptr));
2982 CLOSE(pipe_cmd_to_stdout[READ_FROM_PIPE]);
2988 std::string out=std::string(
"ABORTED: server=")+mPortName
2989 +std::string(
" alias=")+strAlias
2990 +std::string(
" cmd=stdout\n")
2991 +std::string(
"Can't execute stdout because ")+strerror(error)
2994 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
2995 fprintf(out_to_parent,
"%s", out.c_str());
2996 fflush(out_to_parent);
2997 fclose(out_to_parent);
2999 fprintf(stderr,
"%s", out.c_str());
3002 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
3007 if (IS_PARENT_OF(pid_stdout))
3011 fprintf(stderr,
"STARTED: server=%s alias=%s cmd=stdout pid=%d\n", mPortName.c_str(), strAlias.c_str(), pid_stdout);
3019 if (IS_INVALID(pid_cmd))
3024 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
3026 std::string out=std::string(
"ABORTED: server=")+mPortName
3027 +std::string(
" alias=")+strAlias
3028 +std::string(
" cmd=")+strCmd
3029 +std::string(
"\nCan't fork command process because ")+strerror(error)
3034 fprintf(stderr,
"%s", out.c_str());
3036 FILE* to_yarp_stdout=fdopen(pipe_cmd_to_stdout[WRITE_TO_PIPE],
"w");
3037 fprintf(to_yarp_stdout,
"%s", out.c_str());
3038 fflush(to_yarp_stdout);
3039 fclose(to_yarp_stdout);
3041 SIGNAL(pid_stdout, SIGTERM);
3042 fprintf(stderr,
"TERMINATING stdout (%d)\n", pid_stdout);
3043 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
3048 if (IS_NEW_PROCESS(pid_cmd))
3050 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
3052 char *cmd_str=
new char[strCmd.length()+1];
3053 strcpy(cmd_str, strCmd.c_str());
3061 char **arg_str =
new char*[
C_MAXARGS + 1];
3063 arg_str[nargs]=
nullptr;
3065 setvbuf(stdout,
nullptr, _IONBF, 0);
3068 REDIRECT_TO(STDERR_FILENO, pipe_cmd_to_stdout[WRITE_TO_PIPE]);
3070 if (msg.
check(
"env"))
3073 for(
int i=0; i<ss.size(); i++) {
3074 char* szenv =
new char[strlen(ss.get(i))+1];
3075 strcpy(szenv, ss.get(i));
3076 yarp::os::impl::putenv(szenv);
3081 if (msg.
check(
"workdir"))
3083 int ret = yarp::os::impl::chdir(msg.
find(
"workdir").
asString().c_str());
3089 std::string out=std::string(
"ABORTED: server=")+mPortName
3090 +std::string(
" alias=")+strAlias
3091 +std::string(
" cmd=")+strCmd
3092 +std::string(
"\nCan't execute command, cannot set working directory ")+strerror(error)
3095 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
3096 fprintf(out_to_parent,
"%s", out.c_str());
3097 fflush(out_to_parent);
3098 fclose(out_to_parent);
3099 fprintf(stderr,
"%s", out.c_str());
3107 char currWorkDirBuff[1024];
3108 char *currWorkDir=
getcwd(currWorkDirBuff, 1024);
3112 char **cwd_arg_str=
new char*[nargs+1];
3113 for (
int i=1; i<nargs; ++i) cwd_arg_str[i]=arg_str[i];
3114 cwd_arg_str[nargs]=
nullptr;
3115 cwd_arg_str[0]=
new char[strlen(currWorkDir)+strlen(arg_str[0])+16];
3117 strcpy(cwd_arg_str[0], currWorkDir);
3118 strcat(cwd_arg_str[0],
"/");
3119 strcat(cwd_arg_str[0], arg_str[0]);
3126 ret = yarp::run::impl::execvp(cwd_arg_str[0], cwd_arg_str);
3128 delete [] cwd_arg_str[0];
3129 delete [] cwd_arg_str;
3139 ret = yarp::run::impl::execvp(arg_str[0], arg_str);
3144 CLOSE(pipe_cmd_to_stdout[WRITE_TO_PIPE]);
3150 std::string out=std::string(
"ABORTED: server=")+mPortName
3151 +std::string(
" alias=")+strAlias
3152 +std::string(
" cmd=")+strCmd
3153 +std::string(
"\nCan't execute command because ")+strerror(error)
3156 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
3157 fprintf(out_to_parent,
"%s", out.c_str());
3158 fflush(out_to_parent);
3159 fclose(out_to_parent);
3160 fprintf(stderr,
"%s", out.c_str());
3166 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
3172 if (IS_PARENT_OF(pid_cmd))
3175 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
3183 pipe_cmd_to_stdout[READ_FROM_PIPE],
3184 pipe_cmd_to_stdout[WRITE_TO_PIPE],
3189 pInf->setCmd(strCmd);
3191 if (msg.
check(
"env"))
3196 mProcessVector->Add(pInf);
3200 FILE* in_from_child=fdopen(pipe_child_to_parent[READ_FROM_PIPE],
"r");
3201 int flags=fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_GETFL, 0);
3202 fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_SETFL, flags|O_NONBLOCK);
3212 if (!fgets(buff, 1024, in_from_child) || ferror(in_from_child) || feof(in_from_child))
break;
3214 out+=std::string(buff);
3217 fclose(in_from_child);
3226 out=std::string(
"STARTED: server=")+mPortName
3227 +std::string(
" alias=")+strAlias
3228 +std::string(
" cmd=")+strCmd
3236 fprintf(stderr,
"%s", out.c_str());
3238 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
3246 result.
addString(
"I should never reach this point!!!\n");
3258 if (msg.
check(
"forward"))
3260 strCmd=std::string(
"/bin/bash -l -c \"yarprun --readwrite ")+strUUID
3265 strCmd=std::string(
"/bin/bash -l -c \"yarprun --readwrite ")+strUUID+
"\"";
3268 int pipe_child_to_parent[2];
3270 if (yarp::run::impl::pipe(pipe_child_to_parent))
3274 std::string out=std::string(
"ABORTED: server=")+mPortName
3275 +std::string(
" alias=")+strAlias
3276 +std::string(
" cmd=stdio\nCan't create pipe ")+strerror(error)
3282 fprintf(stderr,
"%s", out.c_str());
3289 for (
auto & i : command) {
3293 cmdcpy(command[c++],
"xterm");
3294 cmdcpy(command[c++], msg.
check(
"hold")?
"-hold":
"+hold");
3296 if (msg.
check(
"geometry"))
3298 cmdcpy(command[c++],
"-geometry");
3299 cmdcpy(command[c++], msg.
find(
"geometry").
asString().c_str());
3302 cmdcpy(command[c++],
"-title");
3303 cmdcpy(command[c++], strAlias.c_str());
3305 cmdcpy(command[c++],
"-e");
3306 cmdcpy(command[c++], strCmd.c_str());
3310 if (IS_INVALID(pid_cmd))
3314 std::string out=std::string(
"ABORTED: server=")+mPortName
3315 +std::string(
" alias=")+strAlias
3316 +std::string(
" cmd=stdio\nCan't fork stdout process because ")+strerror(error)
3322 fprintf(stderr,
"%s", out.c_str());
3332 if (IS_NEW_PROCESS(pid_cmd))
3347 int ret = yarp::run::impl::execvp(
"xterm", command);
3355 std::string out=std::string(
"ABORTED: server=")+mPortName
3356 +std::string(
" alias=")+strAlias
3357 +std::string(
" cmd=xterm\nCan't execute command because ")+strerror(error)
3360 FILE* out_to_parent=fdopen(pipe_child_to_parent[WRITE_TO_PIPE],
"w");
3362 fprintf(out_to_parent,
"%s", out.c_str());
3363 fflush(out_to_parent);
3364 fclose(out_to_parent);
3366 fprintf(stderr,
"%s", out.c_str());
3369 CLOSE(pipe_child_to_parent[WRITE_TO_PIPE]);
3374 if (IS_PARENT_OF(pid_cmd))
3378 mStdioVector->Add(
new YarpRunProcInfo(strAlias, mPortName, pid_cmd,
nullptr, msg.
check(
"hold")));
3386 FILE* in_from_child=fdopen(pipe_child_to_parent[
READ_FROM_PIPE],
"r");
3387 int flags=fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_GETFL, 0);
3388 fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_SETFL, flags|O_NONBLOCK);
3397 if (!fgets(buff, 1024, in_from_child) || ferror(in_from_child) || feof(in_from_child))
break;
3399 out+=std::string(buff);
3402 fclose(in_from_child);
3408 if (out.substr(0, 14)==
"xterm Xt error" || out.substr(0, 7)==
"ABORTED")
3414 out=std::string(
"STARTED: server=")+mPortName
3415 +std::string(
" alias=")+strAlias
3416 +std::string(
" cmd=xterm pid=")+
int2String(pid_cmd)
3421 fprintf(stderr,
"%s", out.c_str());
3426 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
3442 int pipe_child_to_parent[2];
3443 int ret_pipe_child_to_parent=yarp::run::impl::pipe(pipe_child_to_parent);
3445 if (ret_pipe_child_to_parent!=0)
3449 std::string out=std::string(
"ABORTED: server=")+mPortName
3450 +std::string(
" alias=")+strAlias
3451 +std::string(
" cmd=stdio\nCan't create pipe ")+strerror(error)
3457 fprintf(stderr,
"%s", out.c_str());
3464 if (IS_INVALID(pid_cmd))
3468 std::string out=std::string(
"ABORTED: server=")+mPortName
3469 +std::string(
" alias=")+strAlias
3470 +std::string(
" cmd=")+strCmd
3471 +std::string(
"\nCan't fork command process because ")+strerror(error)
3476 fprintf(stderr,
"%s", out.c_str());
3481 if (IS_NEW_PROCESS(pid_cmd))
3483 int saved_stderr = yarp::run::impl::dup(STDERR_FILENO);
3484 int null_file=open(
"/dev/null", O_WRONLY);
3491 char *cmd_str=
new char[strCmd.length()+1];
3492 strcpy(cmd_str, strCmd.c_str());
3500 char **arg_str =
new char*[
C_MAXARGS + 1];
3502 arg_str[nargs]=
nullptr;
3504 if (msg.
check(
"env"))
3507 for(
int i=0; i<ss.size(); i++) {
3508 char* szenv =
new char[strlen(ss.get(i))+1];
3509 strcpy(szenv, ss.get(i));
3510 yarp::os::impl::putenv(szenv);
3514 if (msg.
check(
"workdir"))
3516 int ret = yarp::os::impl::chdir(msg.
find(
"workdir").
asString().c_str());
3522 std::string out=std::string(
"ABORTED: server=")+mPortName
3523 +std::string(
" alias=")+strAlias
3524 +std::string(
" cmd=")+strCmd
3525 +std::string(
"\nCan't execute command, cannot set working directory ")+strerror(error)
3528 FILE* out_to_parent=fdopen(pipe_child_to_parent[
WRITE_TO_PIPE],
"w");
3529 fprintf(out_to_parent,
"%s", out.c_str());
3530 fflush(out_to_parent);
3531 fclose(out_to_parent);
3534 fprintf(stderr,
"%s", out.c_str());
3540 char currWorkDirBuff[1024];
3541 char *currWorkDir=
getcwd(currWorkDirBuff, 1024);
3545 char **cwd_arg_str=
new char*[nargs+1];
3546 for (
int i=1; i<nargs; ++i) cwd_arg_str[i]=arg_str[i];
3547 cwd_arg_str[nargs]=
nullptr;
3548 cwd_arg_str[0]=
new char[strlen(currWorkDir)+strlen(arg_str[0])+16];
3551 strcpy(cwd_arg_str[0], currWorkDir);
3552 strcat(cwd_arg_str[0],
"/");
3553 strcat(cwd_arg_str[0], arg_str[0]);
3560 ret = yarp::run::impl::execvp(cwd_arg_str[0], cwd_arg_str);
3562 delete [] cwd_arg_str[0];
3563 delete [] cwd_arg_str;
3572 ret = yarp::run::impl::execvp(arg_str[0], arg_str);
3579 std::string out=std::string(
"ABORTED: server=")+mPortName
3580 +std::string(
" alias=")+strAlias
3581 +std::string(
" cmd=")+strCmd
3582 +std::string(
"\nCan't execute command because ")+strerror(error)
3585 FILE* out_to_parent=fdopen(pipe_child_to_parent[
WRITE_TO_PIPE],
"w");
3586 fprintf(out_to_parent,
"%s", out.c_str());
3587 fflush(out_to_parent);
3588 fclose(out_to_parent);
3590 if (saved_stderr >= 0)
3594 fprintf(stderr,
"%s", out.c_str());
3603 if (IS_PARENT_OF(pid_cmd))
3605 auto* pInf =
new YarpRunProcInfo(strAlias, mPortName, pid_cmd,
nullptr,
false);
3606 pInf->setCmd(strCmd);
3608 mProcessVector->Add(pInf);
3610 sprintf(pidstr,
"%d", pid_cmd);
3614 FILE* in_from_child=fdopen(pipe_child_to_parent[
READ_FROM_PIPE],
"r");
3615 int flags=fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_GETFL, 0);
3616 fcntl(pipe_child_to_parent[READ_FROM_PIPE], F_SETFL, flags|O_NONBLOCK);
3626 if (!fgets(buff, 1024, in_from_child) || ferror(in_from_child) || feof(in_from_child))
break;
3628 out+=std::string(buff);
3631 fclose(in_from_child);
3640 out=std::string(
"STARTED: server=")+mPortName
3641 +std::string(
" alias=")+strAlias
3642 +std::string(
" cmd=")+strCmd
3647 fprintf(stderr,
"%s", out.c_str());
3652 CLOSE(pipe_child_to_parent[READ_FROM_PIPE]);
3678 std::string dest_srv=node;
3680 if (command.
check(
"stdio"))
3682 dest_srv=std::string(command.
find(
"stdio").
asString());
3689 if (command.
check(
"geometry"))
3697 if (command.
check(
"hold"))
3716 printf(
":: %s\n", msg.
toString().c_str());
3718 response=sendMsg(msg, dest_srv);
3721 sprintf(buff,
"%d", response.get(0).asInt32());
3722 keyv=std::string(buff);
3741 printf(
":: %s\n", msg.
toString().c_str());
3743 response=sendMsg(msg, node);
3745 return response.get(0).asString()==
"sigterm OK"?0:
YARPRUN_ERROR;
3761 printf(
":: %s\n", msg.
toString().c_str());
3763 response=sendMsg(msg, node);
3765 return response.get(0).asString()==
"sigtermall OK"?0:
YARPRUN_ERROR;
3783 printf(
":: %s\n", msg.
toString().c_str());
3785 response=sendMsg(msg, node);
3787 return response.get(0).asString()==
"kill OK"?0:
YARPRUN_ERROR;
3804 printf(
":: %s\n", msg.
toString().c_str());
3806 response=sendMsg(msg, node);
3808 if (!response.size())
return false;
3810 return response.get(0).asString()==
"running";
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
static RunTerminator * pTerminator
void fromString(const std::string &text)
Initializes bottle from a string.
static yarp::os::Bottle parsePaths(const std::string &txt)
A port that is specialized as an RPC server.
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
static int client(yarp::os::Property &config)
Send a property object to a run server, bundling up all the settings usually specified on the command...
yarp::os::SystemInfo::MemoryInfo memory
system memory information
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
std::string toString() const override
Return a standard text representation of the content of the object.
static NameClient & getNameClient()
Get an instance of the name client.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
yarp::os::SystemInfo::PlatformInfo platform
operating system information
void setEnv(const std::string &env)
char * getcwd(char *buf, size_t size)
Portable wrapper for the getcwd() function.
A class for storing options and configuration information.
bool start()
Start the new thread running.
static bool fileExists(const char *fname)
int main(int argc, char *argv[])
void addString(const char *str)
Places a string in the bottle, at the end of the list.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
void parseArguments(char *io_pLine, int *o_pArgc, char **o_pArgv)
Breaks up a line into multiple arguments.
bool stop()
Stop the thread.
void useSystemClock()
Configure YARP to use system time (this is the default).
A port that is specialized as an RPC client.
void sigstdio_handler(int sig)
static int sigterm(const std::string &node, const std::string &keyv)
Terminate an application running on a yarprun server.
std::string toString() const override
Return a standard text representation of the content of the object.
static int start(const std::string &node, yarp::os::Property &command, std::string &keyv)
Launch a yarprun server.
yarp::os::SystemInfo::LoadInfo load
current cpu load information
static bool getLocalMode()
Get current value of flag "localMode", see setLocalMode function.
virtual std::string asString() const
Get string value.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void clear()
Empties the bottle of any objects it contains.
A helper class to pass the SystemInfo object around the YARP network.
void setCmd(const std::string &cmd)
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void splitLine(char *pLine, char **pArgs)
Split a line into separate words.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Split a string into pieces.
int SIGNAL(int pid, int signum)
static std::string getDirectorySeparator()
Get an OS-appropriate directory separator (e.g.
static std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
A simple collection of objects that can be described and transmitted in a portable way...
yarp::os::SystemInfo::ProcessorInfo processor
system processor type information
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A class for thread synchronization and mutual exclusion.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
static bool isRunning(const std::string &node, std::string &keyv)
Get a report of all applications running on a yarprun server.
static bool checkNetwork()
Check if the YARP Network is up and running.
static std::string getPathSeparator()
Get an OS-appropriate path separator (e.g.
Bottle tail() const
Get all but the first element of a bottle.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
#define REDIRECT_TO(from, to)
static bool disconnect(const std::string &src, const std::string &dest, bool quiet=true)
Request that an output port disconnect from an input port.
yarp::os::SystemInfo::UserInfo user
current user information
static void delaySystem(double seconds)
int getpid()
Portable wrapper for the getppid() function.
yarp::os::SystemInfo::StorageInfo storage
system storage information
void sigint_handler(int sig)
int fork(void)
Portable wrapper for the fork() function.
std::string send(const std::string &cmd, bool multi=true, const ContactStyle &style=ContactStyle())
Send a text message to the nameserver, and return the result.
static int kill(const std::string &node, const std::string &keyv, int s)
Send a SIGNAL to an application running on a yarprun server (Linux only).
std::string toString() const override
Gives a human-readable textual representation of the bottle.
A single value (typically within a Bottle).
void setVerbosity(int verbose=0)
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
bool read(PortReader &reader, bool willReply=true) override
Read an object from the port.
static void sigchld_handler(int sig)
std::string int2String(int x)
size_t size() const
Gets the number of elements in the bottle.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
Value & get(size_t index) const
Reads a Value v from a certain part of the list.