Re: [fossil-users] TH1 exec
For those interested in a TH1 exec command, I took the ideas from Stephan and Ron, and mixed a few of my own. Here I present my latest version for the exec command I'm using. Now I directly call the functions already included in src/popen.c This time, it can take up to 3 parameters: *exec ?NOWAIT? ?stdin? cmd* *stdin:* will be sent to the child process (and then the pipe will be closed). *NOWAIT: *will create the process and continue (I/O pipes are closed immediately, but not until stdin is passed to the child). *cmd:* well... you know what it means. As usual, comments, ideas and criticism are welcomed! http://abiliojr.homenet.org:20001/public/execcmd.diff On Thu, Feb 5, 2015 at 12:11 PM, Ron W wrote: > On Thu, Feb 5, 2015 at 11:09 AM, Abilio Marques > wrote: > >> Here the current code (missing the capture of the stdout). I send it as a >> patch to the current trunk version (0d1d7f6481). >> >> >> Ideas? >> > > I suggest altering the parameter processing to be: > > if ( argc == 3 ){ > if (fossil_strcmp(argv[1], "NOWAIT") == 0){ > wait = 0; cmd = argv[2]; > } else { > return /* insert value for "unknown option" */; > } } else { cmd = argv[1]; } > > > ___ > fossil-users mailing list > fossil-users@lists.fossil-scm.org > http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users > > ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
Re: [fossil-users] TH1 exec
On Thu, Feb 5, 2015 at 11:09 AM, Abilio Marques wrote: > Here the current code (missing the capture of the stdout). I send it as a > patch to the current trunk version (0d1d7f6481). > > > Ideas? > I suggest altering the parameter processing to be: if ( argc == 3 ){ if (fossil_strcmp(argv[1], "NOWAIT") == 0){ wait = 0; cmd = argv[2]; } else { return /* insert value for "unknown option" */; } } else { cmd = argv[1]; } ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
Re: [fossil-users] TH1 exec
On Thu, Feb 5, 2015 at 5:12 PM, Abilio Marques wrote: > Yeah, missed the attach... > src/popen.c does a lot of the same stuff except... it fails fatally on error instead of returning TH_ERROR. Pedantically speaking, i prefer using error codes (like your patch), but fossil has a long history of fatally failing on errors, so my instinct would be to re-use popen.c's APIs, rather than duplicating functionally equivalent code (assuming popen.c meets all your needs - maybe it doesn't). Just my €0.02 - do not consider it to be "official"! -- - stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
Re: [fossil-users] TH1 exec
Yeah, missed the attach... On Thu, Feb 5, 2015 at 11:39 AM, Abilio Marques wrote: > Here the current code (missing the capture of the stdout). I send it as a > patch to the current trunk version (0d1d7f6481). > > > Ideas? > > On Sat, Jan 31, 2015 at 9:56 AM, Stephan Beal > wrote: > >> On Sat, Jan 31, 2015 at 3:09 PM, Abilio Marques >> wrote: >> >>> I think that adding the ability to capture the app stdout (and stderr) >>> would be a great thing. That way it could be even more powerful than git >>> hooks. >>> >> >> There is some code in fossil for capturing piped i/o, but i have no idea >> if it works on non-*nix: see src/popen.c. >> >> >>> But actually, I've never used TH1 before, so I don't even know if it's >>> possible to return values out of a function, nor if there is a limit on >>> strings length. >>> >> >> (A) you can return a string (because everything is a string in TH1) and >> (B) there is no inherent size limit other than the system's allocator. >> However, you might want to look into the full-fledged (optional) TCL >> support, as TH1 apps get tedious to debug once they're longer than 5 or 10 >> lines. (If you're just spawning a process and returning its output, though, >> you don't need much code.) That said, i cannot comment on the TCL bits - >> hopefully someone familiar with them can enlighten us on how best to go >> about it. >> >> >>> I want to share my working proof of concept with you guys, so you can >>> test it and give feedback on it. What is the best way to do it? >>> >>> >> >> Post it here and someone will certainly start playing with it. (i'm >> ruling myself out for the time being - i have nerve damage in my left arm >> from too much typing and am reduced to right-hand-only typing for the >> foreseeable future.) >> >> >>> How do I get allowed to push to a branch in the main repo? >>> >> >> http://www.fossil-scm.org/index.html/doc/trunk/www/copyright-release.html >> >> fill that out and send it (snail mail) to Richard (a.k.a. "drh") at the >> address on that form. >> >> Once he's got that on file, you'll be set up with commit access. >> >> :) >> >> -- >> - stephan beal >> http://wanderinghorse.net/home/stephan/ >> http://gplus.to/sgbeal >> "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of >> those who insist on a perfect world, freedom will have to do." -- Bigby Wolf >> >> ___ >> fossil-users mailing list >> fossil-users@lists.fossil-scm.org >> http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users >> >> > Index: src/th_main.c == --- src/th_main.c +++ src/th_main.c @@ -1335,10 +1335,100 @@ "synchronous requests are not yet implemented", 0, 0); blob_reset(&payload); return TH_ERROR; } } + +/* +** TH1 command: exec ?NOWAIT? cmd +** +** Runs a command +*/ +static int execCmd( + Th_Interp *interp, + void *p, + int argc, + const char **argv, + int *argl +){ + +#if defined(_WIN32) || defined(_WIN64) + STARTUPINFO si = {0}; + PROCESS_INFORMATION pi = {0}; +#else + pid_t pid; +#endif + + int wait = 1; + const char *cmd; + + /* check if parameters are there */ + if ( argc != 2 && argc != 3){ +return Th_WrongNumArgs(interp, "exec ?NOWAIT? CMD"); + } + + if ( argc == 3 && fossil_strcmp(argv[1], "NOWAIT") == 0 ){ +wait = 0; +cmd = argv[2]; + } else { +cmd = argv[1]; + } + +#if defined(_WIN32) || defined(_WIN64) + si.cb = sizeof(si); + + /* Start the child process. */ + if( !CreateProcess( NULL, /* No module name (use command line) */ +cmd,/* Command line */ +NULL, /* Process handle not inheritable */ +NULL, /* Thread handle not inheritable */ +FALSE, /* Set handle inheritance to FALSE */ +CREATE_NEW_PROCESS_GROUP, /* CREATE_NO_WINDOW = run with no window, see + no use in it if fossil is been used inside + a command line window anyway */ +NULL, /* Use parent's environment block */ +NULL, /* Use parent's starting directory */ +&si,/* Pointer to STARTUPINFO structure */ +&pi ) /* Pointer to PROCESS_INFORMATION structure */ + ) { + return TH_ERROR; + } + + if ( wait ){ +/* Wait until child process exits */ +WaitForSingleObject(pi.hProcess, INFINITE); + } + + /* Close process and thread handles */ + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + +#else + + pid = fork(); + + /* check if we're the child */ + if ( pid == 0 ){ +/* then run the command */ +execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); + }else if( pid < 0 ){ +/* The fork failed */ +return TH_ERROR; + } + + /* we're still in the parent */ + if ( wait ){ +/* wait for the child */ +
Re: [fossil-users] TH1 exec
On Thu, Feb 5, 2015 at 5:09 PM, Abilio Marques wrote: > Here the current code (missing the capture of the stdout). I send it as a > patch to the current trunk version (0d1d7f6481). > The list strips (IIRC) attachments - try pasting it into your mail or posting a link to it. -- - stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
Re: [fossil-users] TH1 exec
Ohhh, I missed the attach in the first mail anyway, here it is: http://abiliojr.homenet.org:20001/public/exec.diff On Thu, Feb 5, 2015 at 11:41 AM, Stephan Beal wrote: > On Thu, Feb 5, 2015 at 5:09 PM, Abilio Marques wrote: > >> Here the current code (missing the capture of the stdout). I send it as a >> patch to the current trunk version (0d1d7f6481). >> > > The list strips (IIRC) attachments - try pasting it into your mail or > posting a link to it. > > > -- > - stephan beal > http://wanderinghorse.net/home/stephan/ > http://gplus.to/sgbeal > "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of > those who insist on a perfect world, freedom will have to do." -- Bigby Wolf > > ___ > fossil-users mailing list > fossil-users@lists.fossil-scm.org > http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users > > ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
Re: [fossil-users] TH1 exec
Here the current code (missing the capture of the stdout). I send it as a patch to the current trunk version (0d1d7f6481). Ideas? On Sat, Jan 31, 2015 at 9:56 AM, Stephan Beal wrote: > On Sat, Jan 31, 2015 at 3:09 PM, Abilio Marques > wrote: > >> I think that adding the ability to capture the app stdout (and stderr) >> would be a great thing. That way it could be even more powerful than git >> hooks. >> > > There is some code in fossil for capturing piped i/o, but i have no idea > if it works on non-*nix: see src/popen.c. > > >> But actually, I've never used TH1 before, so I don't even know if it's >> possible to return values out of a function, nor if there is a limit on >> strings length. >> > > (A) you can return a string (because everything is a string in TH1) and > (B) there is no inherent size limit other than the system's allocator. > However, you might want to look into the full-fledged (optional) TCL > support, as TH1 apps get tedious to debug once they're longer than 5 or 10 > lines. (If you're just spawning a process and returning its output, though, > you don't need much code.) That said, i cannot comment on the TCL bits - > hopefully someone familiar with them can enlighten us on how best to go > about it. > > >> I want to share my working proof of concept with you guys, so you can >> test it and give feedback on it. What is the best way to do it? >> >> > > Post it here and someone will certainly start playing with it. (i'm ruling > myself out for the time being - i have nerve damage in my left arm from too > much typing and am reduced to right-hand-only typing for the foreseeable > future.) > > >> How do I get allowed to push to a branch in the main repo? >> > > http://www.fossil-scm.org/index.html/doc/trunk/www/copyright-release.html > > fill that out and send it (snail mail) to Richard (a.k.a. "drh") at the > address on that form. > > Once he's got that on file, you'll be set up with commit access. > > :) > > -- > - stephan beal > http://wanderinghorse.net/home/stephan/ > http://gplus.to/sgbeal > "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of > those who insist on a perfect world, freedom will have to do." -- Bigby Wolf > > ___ > fossil-users mailing list > fossil-users@lists.fossil-scm.org > http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users > > ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
Re: [fossil-users] TH1 exec
On Sat, Jan 31, 2015 at 3:09 PM, Abilio Marques wrote: > I think that adding the ability to capture the app stdout (and stderr) > would be a great thing. That way it could be even more powerful than git > hooks. > There is some code in fossil for capturing piped i/o, but i have no idea if it works on non-*nix: see src/popen.c. > But actually, I've never used TH1 before, so I don't even know if it's > possible to return values out of a function, nor if there is a limit on > strings length. > (A) you can return a string (because everything is a string in TH1) and (B) there is no inherent size limit other than the system's allocator. However, you might want to look into the full-fledged (optional) TCL support, as TH1 apps get tedious to debug once they're longer than 5 or 10 lines. (If you're just spawning a process and returning its output, though, you don't need much code.) That said, i cannot comment on the TCL bits - hopefully someone familiar with them can enlighten us on how best to go about it. > I want to share my working proof of concept with you guys, so you can test > it and give feedback on it. What is the best way to do it? > > Post it here and someone will certainly start playing with it. (i'm ruling myself out for the time being - i have nerve damage in my left arm from too much typing and am reduced to right-hand-only typing for the foreseeable future.) > How do I get allowed to push to a branch in the main repo? > http://www.fossil-scm.org/index.html/doc/trunk/www/copyright-release.html fill that out and send it (snail mail) to Richard (a.k.a. "drh") at the address on that form. Once he's got that on file, you'll be set up with commit access. :) -- - stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf ___ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users