43static const int kOK = TCL_OK;
44static const int kERR = TCL_ERROR;
51 Tcl_CreateObjCommand(interp,
"rutil::isatty",
Isatty,
53 Tcl_CreateObjCommand(interp,
"rutil::sigaction",
SignalAction,
55 Tcl_CreateObjCommand(interp,
"rutil::waitpid",
WaitPid,
64 int objc, Tcl_Obj*
const objv[])
67 string file =
"stdin";
71 transform(file.begin(), file.end(), file.begin(), ::tolower);
73 if (file ==
"stdin") fileno = STDIN_FILENO;
74 if (file ==
"stdout") fileno = STDOUT_FILENO;
75 if (file ==
"stderr") fileno = STDERR_FILENO;
76 if (fileno == -1)
return args.
Quit(
"file must be stdin, stdout, or stderr");
88 transform(sn.begin(), sn.end(), sn.begin(), ::toupper);
89 if (sn ==
"SIGHUP")
return SIGHUP;
90 if (sn ==
"SIGINT")
return SIGINT;
91 if (sn ==
"SIGTERM")
return SIGTERM;
92 if (sn ==
"SIGUSR1")
return SIGUSR1;
93 if (sn ==
"SIGUSR2")
return SIGUSR2;
99 if (signum == SIGHUP)
return "SIGHUP";
100 if (signum == SIGINT)
return "SIGINT";
101 if (signum == SIGTERM)
return "SIGTERM";
102 if (signum == SIGUSR1)
return "SIGUSR1";
103 if (signum == SIGUSR2)
return "SIGUSR2";
111 int objc, Tcl_Obj*
const objv[])
123 if (objc == 1)
return kOK;
130 if (args.
NextOpt(opt, optset)) {
132 if (opt ==
"-init") {
136 }
else if (opt ==
"-info") {
137 RtclOPtr pres(Tcl_NewListObj(0,
nullptr));
138 int siglist[] = {SIGHUP,SIGINT,SIGTERM,SIGUSR1,SIGUSR2};
139 for (
auto& sig : siglist) {
143 Tcl_ListObjAppendElement(
nullptr, pele,
146 Tcl_ListObjAppendElement(
nullptr, pele, pobj);
148 Tcl_ListObjAppendElement(
nullptr, pele,
149 Tcl_NewStringObj(
"{}",-1));
151 Tcl_ListObjAppendElement(
nullptr, pres, pele);
166 if (!args.
GetArg(
"signam", signam))
return kERR;
168 if (signum < 0)
return args.
Quit(
"invalid signal name");
172 if (args.
NextOpt(opt, optset)) {
173 if (opt ==
"-action") {
175 if (!args.
GetArg(
"script", script))
return kERR;
177 RtclOPtr pobj(Tcl_NewStringObj(script.c_str(), -1));
178 if (!pact->
SetAction(signum, pobj, emsg))
179 return args.
Quit(emsg);
181 }
else if (opt ==
"-revert") {
184 return args.
Quit(emsg);
191 if (!pact->
GetAction(signum, pobj, emsg))
192 return args.
Quit(
"no handler defined");
193 if (pobj ==
nullptr) pobj = Tcl_NewStringObj(
"{}",-1);
204 int objc, Tcl_Obj*
const objv[])
212 int irc = ::waitpid(pid, &status, WNOHANG);
214 RerrMsg emsg(
"RtclSystem::WaitPid",
"waitpid() failed: ", errno);
215 return args.
Quit(emsg);
bool NextOpt(std::string &val)
FIXME_docs.
const char * PeekArgString(int rind) const
FIXME_docs.
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
bool OptValid() const
FIXME_docs.
int Quit(const std::string &str)
FIXME_docs.
void SetResult(const std::string &str)
FIXME_docs.
bool AllDone()
FIXME_docs.
Implemenation (inline) of RtclOPtr.
bool SetAction(int signum, Tcl_Obj *pobj, RerrMsg &emsg)
FIXME_docs.
static bool Init(Tcl_Interp *interp, RerrMsg &emsg)
FIXME_docs.
static RtclSignalAction * Obj()
FIXME_docs.
bool ClearAction(int signum, RerrMsg &emsg)
FIXME_docs.
bool GetAction(int signum, Tcl_Obj *&pobj, RerrMsg &emsg)
FIXME_docs.
static int Isatty(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
FIXME_docs.
static int WaitPid(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
FIXME_docs.
static void CreateCmds(Tcl_Interp *interp)
FIXME_docs.
static int SignalAction(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
FIXME_docs.
Declaration of class ReventLoop.
static int signam2num(const std::string &signam)
static const char * signum2nam(int signum)