ts-0.7.5/.hg_archival.txt0000644000000000000000000000017212476424652013401 0ustar 00000000000000repo: fe34481ad1b09bd0840091eeda9913039ebd39a5 node: 43079a99351e507032471644f5debf4dfdc9ffad branch: default tag: v0.7.5 ts-0.7.5/.hgignore0000644000000000000000000000003112476424652012110 0ustar 00000000000000^.*\.o$ core ^ts$ \.exrc ts-0.7.5/.hgtags0000644000000000000000000000515612476424652011600 0ustar 000000000000009acd8ae3190c49419503af0354f370423ce8a699 v0.0.1 96fcebb6851006199f06bbb0e5360a5675dbc992 v0.1 f093d0964cf590aff2521624bf3fe1503a43b95b v0.2 620319858e9a60ca7256f9de0b4426a52f805b6d v0.2.1 3c492266923e9ce54ad88ced74ef3dc5ecb1bb37 v0.2.3 bb1b20d79acf2ed6f1954cd7ade0814a724b9dee v0.3 4735cade8213a6e8e7c64673573498f8b11edb5d v0.3.1 94945f1c7326c3d4e60a59fa1e2235ce59e1be89 v0.3.1-2 36bec04b8afd320ece21ea3f28b03ec409ff4dc1 v0.3.1-3 94170d3b46d039da8191200b491d6ec429ae2385 v0.3.1-4 098526b06bfe9b9e533ea86ef1fef7a3d29c8b5a v0.3.2 27b0f0e44de8046cec342896a0c77a7ad3c0fd54 v0.3.2-1 98b6955472dd18ac171a6cb4a8e4a228f26cd8a5 v0.3.2-2 c0a1c1e98b6aba9027c73be34f5567d11901d8ca 0.3.2-3 9d23b6db61c96dc5502a1d4a5fc9b9c8013a409d v0.4 b60f173b1489f99beb11f04598e6f604b9c655e3 v0.4-1 c620eacd7630abb620af4984227c0108a0725777 v0.4-2 0b99d94818d164af629062b19044ef573741e2e8 v0.4.1 8b40ee19e765129e88628b5eebca5e70805ec4f1 v0.4.2 5ec722128e2721d2f46537f8ba4e64a657baf66a v0.5 35b77fb4deb1a8f3a9c8fad39db37de737cf565e v0.5.1 bca29e2a1a863473f6abbf3a8af6502d2f9f0276 v0.5.2 bf0250709d522492ef1c6bd03706f2accb5af8c7 v0.5.3 d18e1091fae9476a8b1db3ffa8e68dcd7645ad48 v0.5.4 b4476e12a7173e371b1787622012d31bb9598ab3 v0.5.4.1 b9643c784d8433e68b651807913fef4be5275b51 v0.6 42c9470aa4f9c7ae188a5ad8eb6981b9c0120437 v0.6.1 0000000000000000000000000000000000000000 v0.6.1 5b8a23e79ed635872031b3925619617cda3f3623 v0.6.1 18d5bf8fa969941689d4f51cc65a9697931ab9cd v0.6.2 dc8f1609bad8ac00cd4b07f57486aca5df86941f v0.6.3 0d831e6cf8ef700c2ac3eb233fa5db3d2dbfdd0e v0.6.3bis 11631dd11ff88751ef136bd4bbf5ec2e048cf07f v0.6.3-3rd 56061026d1683a7b46753a0cb41573affd84a353 v0.6.3-4th 62048132f95f0a7af72b137f05613b7793575fb9 v0.6.4 1698b327528de0e4bfe6b9837e1e7d91f8fe852c v0.6.5 d207fb7471440a44372b0ca914e510e20add7a55 v0.6.5 f049b802be641c6775d9882cbb36203ea8a3061b v0.6.6 d7d0074df110a8091ad729b50dcfb3f85f128ef6 v0.7.0 d7d0074df110a8091ad729b50dcfb3f85f128ef6 v0.7.0 73880166685f5094abfbb301e6f010ca7b95c5d3 v0.7.0 549211f9affa99c236b2e2f65b3f9e97bd2ead0e v0.7.1 549211f9affa99c236b2e2f65b3f9e97bd2ead0e 2edd42e77392 549211f9affa99c236b2e2f65b3f9e97bd2ead0e v0.7.1 0000000000000000000000000000000000000000 v0.7.1 549211f9affa99c236b2e2f65b3f9e97bd2ead0e 2edd42e77392 0000000000000000000000000000000000000000 2edd42e77392 0000000000000000000000000000000000000000 v0.7.1 2edd42e7739295e3212f239ef6dc8886335bdf3f v0.7.1 de0a7720dbc20960cf291478b2137e94d64f6416 v0.7.2 7e125eb9a06e223a37c2627a111c359a03c1ef24 v0.7.3 7e125eb9a06e223a37c2627a111c359a03c1ef24 v0.7.3 b01bb36b4290abe7475c66d3d594a6dabe56ed24 v0.7.3 b01bb36b4290abe7475c66d3d594a6dabe56ed24 v0.7.3 7e3b3663bb34ce8b5640f7e934f451cb042b6dd7 v0.7.3 ts-0.7.5/COPYING0000644000000000000000000004307612476424652011360 0ustar 00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ts-0.7.5/Changelog0000644000000000000000000001355512476424652012136 0ustar 00000000000000## Features to be implemented Doubtful tasks: - Allow the 'only-tail' output, without any storage. The number of lines or bytes should be choosable. - No program should give that big amount of output, so it cannot be stored. - What happens if the output disk is full? Should be decide a good behaviour in that situation? - It's up to the running program; ts gives the descsriptor to it. Future: - Use a better system than mkstemp() for finding output files, so we can add .gz to the gzipped outputs. v0.7.5: - Fixing a bug that made the sever crash in MacOSX: strdup() related. v0.7.4: - Fixing a bug about dangling processes, in case of using "ts -r". v0.7.3: - Add option '-N' to set the number of slots required for a job to run. Proposed by Sergey Litvinov. v0.7.2: - Add option '-E', to keep stderr apart. It goes to "`ts -o`.e". v0.7.1: - Implement check of ownership of the socket. Security bugfix. v0.7.0: - Implement blocking of enqueuing still allowing other queue operations. - Add the -B parameter, that will not block in case of queue full v0.6.6: - Fixed the feature TS_MAXCONN, which collided with the protocol version check. v0.6.5: - Fixed a problem that -c and -t, if their pipe was broken, they remained. - Fixed a problem (maybe some copypaste once?) on -l, that created always an error msg. - Adding the possibility of limiting the amount of ts connections. v0.6.4: - Fixed a bug breaking -c and -t. v0.6.3: - Fixed a bug on -c and -t. - Adding first support for -D (run depending on any job) - Adding version control on the protocol. - Making the ts server chdir to the socket directory, so it doesn't annoy on umounting. v0.6.2: - Fixed a bug on -w - Making -S return the number of slots - Fixed a bug on clients dying (making the queue not usable anymore) - Making an error file different for each socket ($TS_SOCKET.error) - Making ts not to log on the error log file constantly. - Adding information on the exit status in -i v0.6.1: - Adding support for the TS_SLOTS env variable, to set the number of slots of a starting server. - Removing references to /usr for nix. - Bugfixing (fixed error handling, -m) v0.6: - Adding multi-slot running capabilities. Big changes in the job management. - Bugfixing (-t, -c and -r, mostly) v0.5.4.1: - Moving out 'debian', so the Debian packagers can use their systems comfortably when packaging ts. v0.5.4: - Bug fixing (-t, actions to last job ids, -w, ...) - -c waits for the job end. Like -t, but it shows the whole output. v0.5.3: - Fixed: Only one waiting ts process ('-w' and '-t') could be used for each jobid. Now, many. v0.5.2: - Fixed the '-r' without jobid, which should remove the last added job. - Fixed some messages for '-t' without jobid (it said something about job -1). v0.5.1: - Fixed the new '-t', which had several problems v0.5: - Several bug fixes (related to -w, -r and -L) - ts creates sessions, so "kill -- -`ts -p`" can be used - New implementation for '-t', which exits when finished, similar to '-w' v0.4.2: - Added labels with -L, in order to distingish commands better on queue list. - Added per-job information, readable through -i, configurable through TS_ENV - Added dependant enqueuing (-d). Conditional run based on last job result. v0.4.1: -* Bugfix: removing a job now doesn't leave the job's ts client alive -* Bugfix: killing the running job's ts client now doesn't block the queue forever -* Bugfix: now using setsid() in order to unlink ts from the bash session. v0.4: -* Allow killing 'ts' in a nice way. - It's good, because a spawner of 'ts' may want to kill it. -* If the server is horribly killed (it may happen as this is software), store the task queue in a file, so it can be recovered. -* Store the 'times()' for the run tasks. v0.3.2: -* Fixed the $POSIXLY_CORRECT bug finally -* Slightly better makefile and man page -* The server should never run out of handles - simply block the client -* Added an error reporting system (in ts(1) - BUGS) -* SIGPIPE is ignored in the ts processes v0.3.1: -* Fixed a bug with $POSIXLY_CORRECT being passed to the jobs. This break the gentoo emerge jobs. -* Fixed a posix compatibility problem for BSD. -* Fixed - the fd 3 is no more opened for the task processes. -* Added a man page and fixed the makefile. v0.3: -* Allow sending the output by mail, or passing it to a program if an env var defines it. -* Allow gzipping the output -* Add a flag for swapping two jobs in the queue (-U id-id) -* Limit the jobs in 'finished' state according to $TS_MAXFINISHED -* Output the jobid in stdout. -* Status check with -s. Return the state in stdout. -* An env var may define the socket path. -* bash is no more used for running commands. Commands are run as is. v0.2.3: -* '-nf' doesn't leave the job in 'finished' state -* Fixed a bug in -r -* '-u' implemented. For altering the queue order. -* '-w' returns the waited errorlevel -* '-o' returns the output file of the last job v0.2.1: -* Fixed a bug in the wait-notifications. -* Improved the compilation, including almost all the proper files. v0.2: -* Add a '-h' for help -* Have a nice list output (correctly formatted) -* Allow killing the running job (Allowed with -p easily) -* Allow tailing any job -* Allow removing a job from the queue -* Allow waiting any job v0.1: -* The clients should _always_ go into background. * -* Allow to receive more parameters in the command line, and them be joined with spaces for the command passed to bash. -* There should be no limit on command line parameters. -* There should be no limit on lines outputed by "-l". -* Get the list of finished jobs, with its errorlevel. -* The list of finished jobs should be clenead on demmand "-c". -* Output to a file should be possible. Use mkstemp(). -* There should be no limit on output filename. v0.0.1: -* add tasks, and they run one after another. Input closed. Output in stdout. ts-0.7.5/Makefile0000644000000000000000000000204712476424652011756 0ustar 00000000000000PREFIX?=/usr/local GLIBCFLAGS=-D_XOPEN_SOURCE=500 -D__STRICT_ANSI__ CFLAGS=-pedantic -ansi -Wall -g -O0 OBJECTS=main.o \ server.o \ server_start.o \ client.o \ msgdump.o \ jobs.o \ execute.o \ msg.o \ mail.o \ error.o \ signals.o \ list.o \ print.o \ info.o \ env.o \ tail.o INSTALL=install -c all: ts tsretry: tsretry.c ts: $(OBJECTS) $(CC) $(LDFLAGS) -o ts $^ # Test our 'tail' implementation. ttail: tail.o ttail.o $(CC) $(LDFLAGS) -o ttail $^ .c.o: $(CC) $(CFLAGS) $(GLIBCFLAGS) -c $< # Dependencies main.o: main.c main.h server_start.o: server_start.c main.h server.o: server.c main.h client.o: client.c main.h msgdump.o: msgdump.c main.h jobs.o: jobs.c main.h execute.o: execute.c main.h msg.o: msg.c main.h mail.o: mail.c main.h error.o: error.c main.h signals.o: signals.c main.h list.o: list.c main.h tail.o: tail.c main.h ttail.o: ttail.c main.h clean: rm -f *.o ts install: ts $(INSTALL) -d $(PREFIX)/bin $(INSTALL) ts $(PREFIX)/bin $(INSTALL) -d $(PREFIX)/share/man/man1 $(INSTALL) -m 644 ts.1 $(PREFIX)/share/man/man1 ts-0.7.5/OBJECTIVES0000644000000000000000000000631412476424652011677 0ustar 00000000000000Introduction --------------------------- This file was written before even the first implementation of 'ts', and it's kept in the repository for historical reasons. Tool objectives --------------------------- - Be able to send commands to the computer, so that they run one after another, stored in a queue. - Control what to do with the input/output of those programs Limits --------------------------- - One queue system per user per system Interface --------------------------- The user should see a single command: ts The default action (maybe on "ts - ...") should be appending a job to the default queue. Job execution --------------------------- The jobs should receive the proper environment from the shell/parent they were queued on. The errorlevels, and maybe some statistical information (times, bytes in/out) should be stored in the queue. The user should be able to check the result of the jobs at any time. We should fork a '$SHELL' and run the job command, because a user may expect his shell parser. Queues --------------------------- There should be different queues, each with an id. The command will work by default with one quue. Each queue will have jobs in different states: - running - queued - blocked (wrong errorlevel on the previous job? optional) - finished (the user can see the errorlevel,etc.) Input/output --------------------------- The user, when adding a job to the queue, should be able to choose: - Where the output goes. As flags: - store: put it into a file in /tmp (or similar). - mail: put it into a file in /tmp, and send it by mail (maybe gzipped) - gzip: directly gzip the output - tail: store in a buffer the last 10 lines A user may choose "mail || gzip", and the file should be mailed gzipped. Or "gzip || tail", and the file should be stored directly gzipped, although with tailing available. - What to do with the input: opened/closed If opened, the user should be able to connect its current stdin to the process'. Job management --------------------------- - Shutdown: stop all the background processes related to the queues. - tail (id): 'tail' the last lines of a process' output. - list: list the queues, with relevant information - wait (id)*: block until some processes dies - remove (id)+: remove jobs from the queue - clear: remove the information about dead jobs (errorlevels, etc.) ---------------------------------- Implementation ------------------------------------ Client/Server ---------------------- A central server daemon will have the main list of jobs, will open a socket, and all the clients will tell what to do through it. This daemon will be started , if a client cannot find it. The client will go immediatly to background when the user adds a new job. A minimum version control should be done between client/server, to assure the dialog will be correct. Connections ----------------------- The connections could go through a Unix socket in /tmp, as X windows. An env variable could have a preference for a socket other than the default. Let's say, /tmp/ts-$USER-0.socket Protocol ----------------------- The clients should pass messages to the server, and vicerveza. Some messages should allow: - new job - list jobs - input data - tail data - get job info - wait job ts-0.7.5/PORTABILITY0000644000000000000000000000127212476424652012042 0ustar 00000000000000ANSI C and POSIX ------------------------- The code should compile without any warning in a system providing an ANSI C compiler and a Single Unix Specification rev 5 library. I tried only with glibc. If you find any inconsistency between the code and this statement, please let know the auther. Compilers ------------------------- (Lluís) I could compile easily with gcc. I could also compile with tcc 0.9.23 if I change the features to -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D__STRICT_ANSI__ . HP-UX 10.2 in PA-RISC ------------------------- (Lluís) I could compile ts 0.3 changing the #include for sys/select.h in server.c to sys/time.h. I also had to use gcc instead of the system's cc. ts-0.7.5/PROTOCOL0000644000000000000000000000104512476424652011477 0ustar 00000000000000[ Totally outdated document ] New job ------------------------- Client: Msg [ new job (commandsize,filenamesize)] Client: Command (+null) Server: Msg [ NewJob OK ] --- pause until the server allows running --- Server: Msg [ RunJOB ] Client: Msg [ RunJOB OK ] Client: (if needed) Filename (+null) --- pause until the client process finishes --- Client: Msg [ EndJOB ] Client: close. List ------------------------- Client: Msg [ LIST ] Server: Msg [ List_line ] Server: line (+null) Server: Msg [ List_line ] Server: line (+null) ... Server: close. ts-0.7.5/README0000644000000000000000000000061212476424652011172 0ustar 00000000000000Users ------------------------ If you are in a system which understands POSIX and has the GNU toolkit, you probably can run: make make install If you want to install to another path than /usr/local, you can run: make install PREFIX=/usr Developers ------------------------ Run ". setenv" before adding bugs to the database. Use 'bug' for the database. http://freshmeat.net/projects/bug/ ts-0.7.5/TRICKS0000644000000000000000000000345612476424652011245 0ustar 00000000000000System wide queue ------------------------- You can set the $TS_SOCKET variable to the same name path for all your 'ts' processes, and then they'll use the same socket for intercommunication. This means - single queue. You should be certain that any 'ts' can read/write to that socket, using chmod. A queue for each resource ------------------------- You can use $TS_SOCKET and aliases/scripts for having different queues for different resources. For instance, using bash: alias tsdisk='TS_SOCKET=/tmp/socket.disk ts' alias tsram='TS_SOCKET=/tmp/socket.ram ts' alias tsnet='TS_SOCKET=/tmp/socket.net ts' You can also create shell scripts like this: << FILE ts2 #!/bin/sh export TS_SOCKET=/tmp/socket-ts2.$USER ts "$@" >> END OF FILE ts2 Be notified of a task finished ------------------------- In X windows, inside bash, after submitting the task, I use: $ ( ts -w ; xmessage Finished! ) & Killing process groups ------------------------- ts creates a new session for the job, so the pid of the command run can be used as the process group id for the command and its childs. So, you can use something like: $ kill -- -`ts -p` in order to kill the job started and all its childs. I find it useful when killing 'make's. Limiting the number of ts processes ------------------------- Each queued job remains in the system as a waiting process. On environments where the number of processes is quite limited, the user can select the amount of the maximum number of ts server connections to ts clients. That will be read from the environment variable TS_MAXCONN at the server start, and cannot be set again once the server runs: $ ts -K # we assure we will start the server at the next ts call $ TS_MAXCONN=5 ts Internally there is a maximum of 1000 connexions that cannot be exceeded without modifying the source code (server.c). ts-0.7.5/buglist.bug0000644000000000000000000000651212476424652012467 0ustar 0000000000000029 0 1 sleep recv() may return ECONNRESET \nI don't know why. It happened sometimes, when the client didn't send any\nENDJOB message.\nIt should be investigated.\n\nHypothesis:\n- maybe recv() returns ECONNRESET if the other side process has died but not\n closed()?\n simple tests seem to show that it's not true. 20 1 open Log the output of TS_ONFINISH, for the case it gives an error I actually used this for debugging:\n\nexec >> $HOME/${0##*/}.out 2>&1\ndate; echo params: "$@"; echo\nset -xv\n\nand found that the script is run, but that the server worked\ndifferently from what I expected: My script checks the output\nof ts to be sure that it is run via ts and not via cmdline.\n\nAs the script gets some information as parameters, I checked\nwhether these are in the output of ts. What I expected was\nthat ts would show a line like\n\n0 finished /tmp/ts-out.l8jhbI 0 10.05/0.00/0.00 sleep 10\n\nNow I understand that the (just finished) job is shown as\n\n0 running /tmp/ts-out.l8jhbI sleep 10\n\nin this very moment. I adapted my script and now it works. :-)\n\nBTW: Why don't you just log stdout/stderr of $TS_ONFINISH? 22 1 open Add more information to TS_SAVELIST (from ts -i, for example) 23 -5 done "ts -S" could return the number of slots set. 19 -10 fixed Killing a child ts blocked the queue ts creates the job in a new Process Group. You can send signals\nto the whole Process Group using a negative number for kill, as\nin: "kill -- -`ts -p`" (the first double hyphen is for sending\nthe default TERM signal, and not mixing the ID with a signal\nnumber).\n\nI finally tried this and it works. Once I accidently killed the\ncorresponding ts process instead and this hung the whole queue:\n\nts(3427)---grandpa(3428)-+-father(3429)-+-son(3430)---sleep(3431)\n | `-son(3435)---sleep(3436)\n `-father(3432)-+-son(3433)---sleep(3434)\n `-son(3437)---sleep(3438)\n\n$ kill -- -3427 #should have been 3428\n$ ts\n\nID State Output E-Level Times(r/u/s) Command [run=1/1]\n1 queued (file) grandpa\n2 queued (file) grandpa\n\nKilling the correct pid 3428 didn't help ts to recover. A 'ts -C'\ndid exactly nothing. Finally 'ts -K' allowed to use ts again.\n\nJust as a note\nThomas 18 2 open Making a different TS_SAVELIST name on each socket/date 28 10 open Security thread on the unix socket \nFrom http://www.lst.de/~okir/blackhats/node55.html:\n\n\nUnix sockets and named pipes\n\nSimilar problems arise when you want to use Unix domain sockets or named pipes\nin /tmp or other hostile directories.4.4\n\nThe KDE desktop comes with an application called kdesu which is a GUI frontend\nto the su program. In an act of unparalleled user-friendliness it will try to\ncache the password for you. Rather than storing it in a file, the password is\nhanded to a separate daemon process that kdesu talks to via a Unix domain socket\nnamed /tmp/.kdesu_userid. The problem with this was that kdesu didn't care who\nor what had created the socket, and was willing to talk to anyone as long as the\nsocket was there. This made it very easy for an attacker to write a rogue\npassword caching daemon that, as a side effect, would ``cache'' the passwords in\na file owned by the attacker. ts-0.7.5/client.c0000644000000000000000000003626512476424652011751 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include "main.h" static void c_end_of_job(const struct Result *res); static void c_wait_job_send(); static void c_wait_running_job_send(); char *build_command_string() { int size; int i; int num; char **array; char *commandstring; size = 0; num = command_line.command.num; array = command_line.command.array; /* Count bytes needed */ for (i = 0; i < num; ++i) { /* The '1' is for spaces, and at the last i, * for the null character */ size = size + strlen(array[i]) + 1; } /* Alloc */ commandstring = (char *) malloc(size); if(commandstring == NULL) error("Error in malloc for commandstring"); /* Build the command */ strcpy(commandstring, array[0]); for (i = 1; i < num; ++i) { strcat(commandstring, " "); strcat(commandstring, array[i]); } return commandstring; } void c_new_job() { struct msg m; char *new_command; char *myenv; m.type = NEWJOB; new_command = build_command_string(); myenv = get_environment(); /* global */ m.u.newjob.command_size = strlen(new_command) + 1; /* add null */ if (myenv) m.u.newjob.env_size = strlen(myenv) + 1; /* add null */ else m.u.newjob.env_size = 0; if (command_line.label) m.u.newjob.label_size = strlen(command_line.label) + 1; /* add null */ else m.u.newjob.label_size = 0; m.u.newjob.store_output = command_line.store_output; m.u.newjob.do_depend = command_line.do_depend; m.u.newjob.depend_on = command_line.depend_on; m.u.newjob.should_keep_finished = command_line.should_keep_finished; m.u.newjob.command_size = strlen(new_command) + 1; /* add null */ m.u.newjob.wait_enqueuing = command_line.wait_enqueuing; m.u.newjob.num_slots = command_line.num_slots; /* Send the message */ send_msg(server_socket, &m); /* Send the command */ send_bytes(server_socket, new_command, m.u.newjob.command_size); /* Send the label */ send_bytes(server_socket, command_line.label, m.u.newjob.label_size); /* Send the environment */ send_bytes(server_socket, myenv, m.u.newjob.env_size); free(new_command); free(myenv); } int c_wait_newjob_ok() { struct msg m; int res; res = recv_msg(server_socket, &m); if(res == -1) error("Error in wait_newjob_ok"); if(m.type == NEWJOB_NOK) { fprintf(stderr, "Error, queue full\n"); exit(EXITCODE_QUEUE_FULL); } if(m.type != NEWJOB_OK) error("Error getting the newjob_ok"); return m.u.jobid; } int c_wait_server_commands() { struct msg m; int res; while (1) { res = recv_msg(server_socket, &m); if(res == -1) error("Error in wait_server_commands"); if (res == 0) break; if(res != sizeof(m)) error("Error in wait_server_commands"); if (m.type == RUNJOB) { struct Result res; res.skipped = 0; /* These will send RUNJOB_OK */ if (command_line.do_depend && m.u.last_errorlevel != 0) { res.errorlevel = -1; res.user_ms = 0.; res.system_ms = 0.; res.real_ms = 0.; res.skipped = 1; c_send_runjob_ok(0, -1); } else run_job(&res); c_end_of_job(&res); return res.errorlevel; } } return -1; } void c_wait_server_lines() { struct msg m; int res; while (1) { res = recv_msg(server_socket, &m); if(res == -1) error("Error in wait_server_lines"); if (res == 0) break; if(res != sizeof(m)) error("Error in wait_server_lines 2"); if (m.type == LIST_LINE) { char * buffer; buffer = (char *) malloc(m.u.size); recv_bytes(server_socket, buffer, m.u.size); printf("%s", buffer); free(buffer); } } } void c_list_jobs() { struct msg m; m.type = LIST; send_msg(server_socket, &m); } /* Exits if wrong */ void c_check_version() { struct msg m; int res; m.type = GET_VERSION; /* Double send, so an old ts will answer for sure at least once */ send_msg(server_socket, &m); send_msg(server_socket, &m); /* Set up a 2 second timeout to receive the version msg. */ res = recv_msg(server_socket, &m); if(res == -1) error("Error calling recv_msg in c_check_version"); if (m.type != VERSION || m.u.version != PROTOCOL_VERSION) { printf("Wrong server version. Received %i, expecting %i\n", m.u.version, PROTOCOL_VERSION); error("Wrong server version. Received %i, expecting %i", m.u.version, PROTOCOL_VERSION); } /* Receive also the 2nd send_msg if we got the right version */ res = recv_msg(server_socket, &m); if(res == -1) error("Error calling the 2nd recv_msg in c_check_version"); } void c_show_info() { struct msg m; int res; m.type = INFO; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); while (1) { res = recv_msg(server_socket, &m); if(res == -1) error("Error in wait_server_lines"); if (res == 0) break; if(res != sizeof(m)) error("Error in wait_server_lines 2"); if (m.type == INFO_DATA) { char * buffer; enum { DSIZE = 1000 }; /* We're going to output data using the stdout fd */ fflush(stdout); buffer = (char *) malloc(DSIZE); do { res = recv(server_socket, buffer, DSIZE, 0); if (res > 0) write(1, buffer, res); } while(res > 0); free(buffer); } } } void c_send_runjob_ok(const char *ofname, int pid) { struct msg m; /* Prepare the message */ m.type = RUNJOB_OK; if (ofname) /* ofname == 0, skipped execution */ m.u.output.store_output = command_line.store_output; else m.u.output.store_output = 0; m.u.output.pid = pid; if (m.u.output.store_output) m.u.output.ofilename_size = strlen(ofname) + 1; else m.u.output.ofilename_size = 0; send_msg(server_socket, &m); /* Send the filename */ if (command_line.store_output) send_bytes(server_socket, ofname, m.u.output.ofilename_size); } static void c_end_of_job(const struct Result *res) { struct msg m; m.type = ENDJOB; m.u.result = *res; /* struct copy */ send_msg(server_socket, &m); } void c_shutdown_server() { struct msg m; m.type = KILL_SERVER; send_msg(server_socket, &m); } void c_clear_finished() { struct msg m; m.type = CLEAR_FINISHED; send_msg(server_socket, &m); } static char * get_output_file(int *pid) { struct msg m; int res; char *string = 0; /* Send the request */ m.type = ASK_OUTPUT; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in get_output_file"); switch(m.type) { case ANSWER_OUTPUT: if (m.u.output.store_output) { /* Receive the output file name */ string = 0; if (m.u.output.ofilename_size > 0) { string = (char *) malloc(m.u.output.ofilename_size); recv_bytes(server_socket, string, m.u.output.ofilename_size); } *pid = m.u.output.pid; return string; } *pid = m.u.output.pid; return 0; /* WILL NOT GO FURTHER */ case LIST_LINE: /* Only ONE line accepted */ string = (char *) malloc(m.u.size); res = recv_bytes(server_socket, string, m.u.size); if(res != m.u.size) error("Error in get_output_file line size"); fprintf(stderr, "Error in the request: %s", string); exit(-1); /* WILL NOT GO FURTHER */ default: warning("Wrong internal message in get_output_file line size"); } /* This will never be reached */ return 0; } int c_tail() { char *str; int pid; str = get_output_file(&pid); if (str == 0) { fprintf(stderr, "The output is not stored. Cannot tail.\n"); exit(-1); } c_wait_running_job_send(); return tail_file(str, 10 /* Last lines to show */); } int c_cat() { char *str; int pid; str = get_output_file(&pid); if (str == 0) { fprintf(stderr, "The output is not stored. Cannot cat.\n"); exit(-1); } c_wait_running_job_send(); return tail_file(str, -1 /* All the lines */); } void c_show_output_file() { char *str; int pid; /* This will exit if there is any error */ str = get_output_file(&pid); if (str == 0) { fprintf(stderr, "The output is not stored.\n"); exit(-1); } printf("%s\n", str); free(str); } void c_show_pid() { int pid; /* This will exit if there is any error */ get_output_file(&pid); printf("%i\n", pid); } void c_remove_job() { struct msg m; int res; char *string = 0; /* Send the request */ m.type = REMOVEJOB; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in remove_job"); switch(m.type) { case REMOVEJOB_OK: return; /* WILL NOT GO FURTHER */ case LIST_LINE: /* Only ONE line accepted */ string = (char *) malloc(m.u.size); res = recv_bytes(server_socket, string, m.u.size); fprintf(stderr, "Error in the request: %s", string); exit(-1); /* WILL NOT GO FURTHER */ default: warning("Wrong internal message in remove_job"); } /* This will never be reached */ } int c_wait_job_recv() { struct msg m; int res; char *string = 0; /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in wait_job"); switch(m.type) { case WAITJOB_OK: return m.u.result.errorlevel; /* WILL NOT GO FURTHER */ case LIST_LINE: /* Only ONE line accepted */ string = (char *) malloc(m.u.size); res = recv_bytes(server_socket, string, m.u.size); if(res != m.u.size) error("Error in wait_job - line size"); fprintf(stderr, "Error in the request: %s", string); exit(-1); /* WILL NOT GO FURTHER */ default: warning("Wrong internal message in c_wait_job"); } /* This will never be reached */ return -1; } static void c_wait_job_send() { struct msg m; /* Send the request */ m.type = WAITJOB; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); } static void c_wait_running_job_send() { struct msg m; /* Send the request */ m.type = WAIT_RUNNING_JOB; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); } /* Returns the errorlevel */ int c_wait_job() { c_wait_job_send(); return c_wait_job_recv(); } /* Returns the errorlevel */ int c_wait_running_job() { c_wait_running_job_send(); return c_wait_job_recv(); } void c_send_max_slots(int max_slots) { struct msg m; /* Send the request */ m.type = SET_MAX_SLOTS; m.u.max_slots = command_line.max_slots; send_msg(server_socket, &m); } void c_get_max_slots() { struct msg m; int res; /* Send the request */ m.type = GET_MAX_SLOTS; m.u.max_slots = command_line.max_slots; send_msg(server_socket, &m); /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in move_urgent"); switch(m.type) { case GET_MAX_SLOTS_OK: printf("%i\n", m.u.max_slots); return; default: warning("Wrong internal message in get_max_slots"); } } void c_move_urgent() { struct msg m; int res; char *string = 0; /* Send the request */ m.type = URGENT; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in move_urgent"); switch(m.type) { case URGENT_OK: return; /* WILL NOT GO FURTHER */ case LIST_LINE: /* Only ONE line accepted */ string = (char *) malloc(m.u.size); res = recv_bytes(server_socket, string, m.u.size); if(res != m.u.size) error("Error in move_urgent - line size"); fprintf(stderr, "Error in the request: %s", string); exit(-1); /* WILL NOT GO FURTHER */ default: warning("Wrong internal message in move_urgent"); } /* This will never be reached */ return; } void c_get_state() { struct msg m; int res; char *string = 0; /* Send the request */ m.type = GET_STATE; m.u.jobid = command_line.jobid; send_msg(server_socket, &m); /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in get_state - line size"); switch(m.type) { case ANSWER_STATE: printf("%s\n", jstate2string(m.u.state)); return; /* WILL NOT GO FURTHER */ case LIST_LINE: /* Only ONE line accepted */ string = (char *) malloc(m.u.size); res = recv_bytes(server_socket, string, m.u.size); if(res != m.u.size) error("Error in get_state - line size"); fprintf(stderr, "Error in the request: %s", string); exit(-1); /* WILL NOT GO FURTHER */ default: warning("Wrong internal message in get_state"); } /* This will never be reached */ return; } void c_swap_jobs() { struct msg m; int res; char *string = 0; /* Send the request */ m.type = SWAP_JOBS; m.u.swap.jobid1 = command_line.jobid; m.u.swap.jobid2 = command_line.jobid2; send_msg(server_socket, &m); /* Receive the answer */ res = recv_msg(server_socket, &m); if(res != sizeof(m)) error("Error in swap_jobs"); switch(m.type) { case SWAP_JOBS_OK: return; /* WILL NOT GO FURTHER */ case LIST_LINE: /* Only ONE line accepted */ string = (char *) malloc(m.u.size); res = recv_bytes(server_socket, string, m.u.size); if(res != m.u.size) error("Error in swap_jobs - line size"); fprintf(stderr, "Error in the request: %s", string); exit(-1); /* WILL NOT GO FURTHER */ default: warning("Wrong internal message in swap_jobs"); } /* This will never be reached */ return; } ts-0.7.5/deb/pkg/DEBIAN/control0000644000000000000000000000124212476424652014152 0ustar 00000000000000Package: ts Version: 0.5.4 Section: base Priority: optional Architecture: i386 Essential: no Installed-Size: 100 Maintainer: Lluis Batlle Depends: coreutils Conflicts: moreutils Description: task spooler is a Unix batch system where the tasks spooled run one after the other. Each user in each system has his own job queue. The tasks are run in the correct context (that of enqueue) from any shell/process, and its output/results can be easily watched. It is very useful when you know that your commands depend on a lot of RAM, a lot of disk use, give a lot of output, or for whatever reason it's better not to run them at the same time. ts-0.7.5/debian-pkg/changelog0000644000000000000000000000023012476424652014161 0ustar 00000000000000task-spooler (0.5.3-1) unstable; urgency=low * Initial release. -- Alexander V. Inyukhin Wed, 13 Feb 2008 07:32:26 +0300 ts-0.7.5/debian-pkg/compat0000644000000000000000000000000212476424652013512 0ustar 000000000000005 ts-0.7.5/debian-pkg/control0000644000000000000000000000132712476424652013722 0ustar 00000000000000Source: task-spooler Section: base Priority: optional Maintainer: Lluis Batlle Build-Depends: cdbs, debhelper (>= 5) Standards-Version: 3.7.2 Package: task-spooler Architecture: any Depends: ${shlibs:Depends} Conflicts: moreutils Description: task spooler is a Unix batch system where the tasks spooled run one after the other. Each user in each system has his own job queue. The tasks are run in the correct context (that of enqueue) from any shell/process, and its output/results can be easily watched. It is very useful when you know that your commands depend on a lot of RAM, a lot of disk use, give a lot of output, or for whatever reason it's better not to run them at the same time. ts-0.7.5/debian-pkg/docs0000644000000000000000000000005612476424652013170 0ustar 00000000000000OBJECTIVES PORTABILITY PROTOCOL README TRICKS ts-0.7.5/debian-pkg/rules0000644000000000000000000000025212476424652013370 0ustar 00000000000000#!/usr/bin/make -f include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/makefile.mk DEB_MAKE_INSTALL_TARGET = install PREFIX=$(DEB_DESTDIR)/usr ts-0.7.5/env.c0000644000000000000000000000373012476424652011252 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include #include "main.h" static int fork_command(const char *command) { int pid; int p[2]; int fdnull; fdnull = open("/dev/null", O_RDONLY); if (fdnull == -1) error("Cannot open /dev/null"); pipe(p); pid = fork(); switch(pid) { case 0: restore_sigmask(); close(server_socket); dup2(fdnull, 0); if (fdnull != 0) close(fdnull); dup2(p[1], 1); dup2(p[1], 2); if (p[1] != 1 && p[1] != 2) close(p[1]); close(p[0]); execlp("/bin/sh", "/bin/sh", "-c", command, 0); error("/bin/sh exec error"); case -1: error("Fork error"); default: close(p[1]); } return p[0]; } char * get_environment() { char *ptr; char *command; int readfd; int bytes = 0; int alloc = 0; command = getenv("TS_ENV"); if (command == 0) return 0; readfd = fork_command(command); ptr = 0; do { int next; int res; next = bytes + 1000; if (next > alloc) { ptr = realloc(ptr, next); alloc = next; } res = read(readfd, ptr + bytes, 1000); if (res < 0) error("Cannot read from the TS_ENV command (%s)", command); else if (res == 0) break; else bytes += res; } while(1); /* We will always have 1000 bytes more to be written, on end. * We add a null for it to be an ASCIIZ string. */ ptr[bytes] = '\0'; close(readfd); wait(0); return ptr; } ts-0.7.5/error.c0000644000000000000000000000712512476424652011615 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include #include #include #include #include "main.h" enum Etype { WARNING, ERROR }; /* Declared in main.h as extern */ enum Process_type process_type; static int real_errno; /* Local protos */ static void dump_structs(FILE *out); static void print_date(FILE *out) { time_t t; const char *tstr; t = time(NULL); tstr = ctime(&t); fprintf(out, "date %s", tstr); } static void dump_proc_info(FILE *out) { print_date(out); fprintf(out, "pid %i\n", getpid()); if (process_type == SERVER) fprintf(out, "type SERVER\n"); else if (process_type == CLIENT) fprintf(out, "type CLIENT\n"); else fprintf(out, "type UNKNOWN\n"); } static FILE * open_error_file() { int fd; FILE* out; char *path; int new_size; char *new_path; create_socket_path(&path); new_size = strlen(path)+10; new_path = malloc(new_size); strncpy(new_path, path, new_size); strncat(new_path, ".error", (new_size - strlen(path)) - 1); free(path); fd = open(new_path, O_CREAT | O_APPEND | O_WRONLY, 0600); if (fd == -1) return 0; out = fdopen(fd, "a"); if (out == NULL) { close(fd); return 0; } free(new_path); return out; } static void print_error(FILE *out, enum Etype type, const char *str, va_list ap) { fprintf(out, "-------------------"); if (type == ERROR) fprintf(out, "Error\n"); else if (type == WARNING) fprintf(out, "Warning\n"); else fprintf(out, "Unknown kind of error\n"); fprintf(out, " Msg: "); vfprintf(out, str, ap); fprintf(out, "\n"); fprintf(out, " errno %i, \"%s\"\n", real_errno, strerror(real_errno)); } static void problem(enum Etype type, const char *str, va_list ap) { FILE *out; out = open_error_file(); if (out == 0) return; /* out is ready */ print_error(out, type, str, ap); dump_structs(out); /* this will close the fd also */ fclose(out); } static void problem_msg(enum Etype type, const struct msg *m, const char *str, va_list ap) { FILE *out; out = open_error_file(); if (out == 0) return; /* out is ready */ print_error(out, type, str, ap); msgdump(out, m); dump_structs(out); /* this will close the fd also */ fclose(out); } void error(const char *str, ...) { va_list ap; va_start(ap, str); real_errno = errno; if (process_type == CLIENT) { vfprintf(stderr, str, ap); fputc('\n', stderr); } problem(ERROR, str, ap); exit(-1); } void error_msg(const struct msg *m, const char *str, ...) { va_list ap; va_start(ap, str); real_errno = errno; problem_msg(ERROR, m, str, ap); exit(-1); } void warning(const char *str, ...) { va_list ap; va_start(ap, str); real_errno = errno; problem(WARNING, str, ap); } void warning_msg(const struct msg *m, const char *str, ...) { va_list ap; va_start(ap, str); real_errno = errno; problem_msg(WARNING, m, str, ap); } static void dump_structs(FILE *out) { dump_proc_info(out); if (process_type == SERVER) { dump_jobs_struct(out); dump_notifies_struct(out); dump_conns_struct(out); } } ts-0.7.5/execute.c0000644000000000000000000001673612476424652012136 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "main.h" /* from signals.c */ extern int signals_child_pid; /* 0, not set. otherwise, set. */ /* Returns errorlevel */ static void run_parent(int fd_read_filename, int pid, struct Result *result) { int status; char *ofname = 0; int namesize; int res; char *command; struct timeval starttv; struct timeval endtv; struct tms cpu_times; /* Read the filename */ /* This is linked with the write() in this same file, in run_child() */ if (command_line.store_output) { res = read(fd_read_filename, &namesize, sizeof(namesize)); if (res == -1) error("read the filename from %i", fd_read_filename); if (res != sizeof(namesize)) error("Reading the size of the name"); ofname = (char *) malloc(namesize); res = read(fd_read_filename, ofname, namesize); if (res != namesize) error("Reading the the out file name"); } res = read(fd_read_filename, &starttv, sizeof(starttv)); if (res != sizeof(starttv)) error("Reading the the struct timeval"); close(fd_read_filename); /* All went fine - prepare the SIGINT and send runjob_ok */ signals_child_pid = pid; unblock_sigint_and_install_handler(); c_send_runjob_ok(ofname, pid); wait(&status); /* Set the errorlevel */ if (WIFEXITED(status)) { /* We force the proper cast */ signed char tmp; tmp = WEXITSTATUS(status); result->errorlevel = tmp; result->died_by_signal = 0; } else if (WIFSIGNALED(status)) { signed char tmp; tmp = WTERMSIG(status); result->signal = tmp; result->errorlevel = -1; result->died_by_signal = 1; } else { result->died_by_signal = 0; result->errorlevel = -1; } command = build_command_string(); if (command_line.send_output_by_mail) { send_mail(command_line.jobid, result->errorlevel, ofname, command); } hook_on_finish(command_line.jobid, result->errorlevel, ofname, command); free(command); free(ofname); /* Calculate times */ gettimeofday(&endtv, NULL); result->real_ms = endtv.tv_sec - starttv.tv_sec + ((float) (endtv.tv_usec - starttv.tv_usec) / 1000000.); times(&cpu_times); /* The times are given in clock ticks. The number of clock ticks per second * is obtained in POSIX using sysconf(). */ result->user_ms = (float) cpu_times.tms_cutime / (float) sysconf(_SC_CLK_TCK); result->system_ms = (float) cpu_times.tms_cstime / (float) sysconf(_SC_CLK_TCK); } void create_closed_read_on(int dest) { int p[2]; /* Closing input */ pipe(p); close(p[1]); /* closing the write handle */ dup2(p[0], dest); /* the pipe reading goes to dest */ if(p[0] != dest) close(p[0]); } /* This will close fd_out and fd_in in the parent */ static void run_gzip(int fd_out, int fd_in) { int pid; pid = fork(); switch(pid) { case 0: /* child */ restore_sigmask(); dup2(fd_in,0); /* stdout */ dup2(fd_out,1); /* stdout */ close(fd_in); close(fd_out); /* Without stderr */ close(2); execlp("gzip", "gzip", NULL); exit(-1); /* Won't return */ case -1: exit(-1); /* Fork error */ default: close(fd_in); close(fd_out); } } static void run_child(int fd_send_filename) { char outfname[] = "/tmp/ts-out.XXXXXX"; char errfname[sizeof outfname + 2]; /* .e */ int namesize; int outfd; struct timeval starttv; if (command_line.store_output) { if (command_line.gzip) { int p[2]; /* We assume that all handles are closed*/ pipe(p); /* gzip output goes to the filename */ /* This will be the handle other than 0,1,2 */ outfd = mkstemp(outfname); /* stdout */ /* Program stdout and stderr */ /* which go to pipe write handle */ dup2(p[1], 1); if (command_line.stderr_apart) { int errfd; strncpy(errfname, outfname, sizeof errfname); strncat(errfname, ".e", 2); errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600); dup2(errfd, 2); close(errfd); } else dup2(p[1], 2); close(p[1]); /* run gzip. * This wants p[0] in 0, so gzip will read * from it */ run_gzip(outfd, p[0]); } else { /* Prepare the filename */ outfd = mkstemp(outfname); /* stdout */ dup2(outfd, 1); /* stdout */ if (command_line.stderr_apart) { int errfd; strncpy(errfname, outfname, sizeof errfname); strncat(errfname, ".e", 2); errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600); dup2(errfd, 2); close(errfd); } else dup2(outfd, 2); close(outfd); } /* Send the filename */ namesize = sizeof(outfname); write(fd_send_filename, (char *)&namesize, sizeof(namesize)); write(fd_send_filename, outfname, sizeof(outfname)); } /* Times */ gettimeofday(&starttv, NULL); write(fd_send_filename, &starttv, sizeof(starttv)); close(fd_send_filename); /* Closing input */ if (command_line.should_go_background) create_closed_read_on(0); /* We create a new session, so we can kill process groups as: kill -- -`ts -p` */ setsid(); execvp(command_line.command.array[0], command_line.command.array); } int run_job(struct Result *res) { int pid; int errorlevel; int p[2]; /* For the parent */ /*program_signal(); Still not needed*/ block_sigint(); /* Prepare the output filename sending */ pipe(p); pid = fork(); switch(pid) { case 0: restore_sigmask(); close(server_socket); close(p[0]); run_child(p[1]); /* Not reachable, if the 'exec' of the command * works. Thus, command exists, etc. */ fprintf(stderr, "ts could not run the command\n"); exit(-1); /* To avoid a compiler warning */ errorlevel = 0; break; case -1: /* To avoid a compiler warning */ errorlevel = 0; error("forking"); default: close(p[1]); run_parent(p[0], pid, res); break; } return errorlevel; } #if 0 Not needed static void sigchld_handler(int val) { } static void program_signal() { struct sigaction act; act.sa_handler = sigchld_handler; /* Reset the mask */ memset(&act.sa_mask,0,sizeof(act.sa_mask)); act.sa_flags = SA_NOCLDSTOP; sigaction(SIGCHLD, &act, NULL); } #endif ts-0.7.5/gentoo/ts-0.5.2.ebuild0000644000000000000000000000105312476424652014061 0ustar 00000000000000# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ inherit eutils DESCRIPTION="A comfortable way of running batch jobs" HOMEPAGE="http://vicerveza.homeunix.net/~viric/soft/ts/" SRC_URI="http://vicerveza.homeunix.net/~viric/soft/ts/${P}.tar.gz" LICENSE="GPL" SLOT="0" KEYWORDS="~x86" IUSE="" DEPEND="" RDEPEND="" src_compile() { emake || die "emake failed" } src_install() { exeinto /usr/bin doexe ts doman ts.1 dodoc Changelog OBJECTIVES PORTABILITY PROTOCOL README TRICKS } ts-0.7.5/info.c0000644000000000000000000000556212476424652011422 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include "main.h" void pinfo_init(struct Procinfo *p) { p->ptr = 0; p->nchars = 0; p->allocchars = 0; p->start_time.tv_sec = 0; p->start_time.tv_usec = 0; p->end_time.tv_sec = 0; p->end_time.tv_usec = 0; p->enqueue_time.tv_sec = 0; p->enqueue_time.tv_usec = 0; } void pinfo_free(struct Procinfo *p) { if (p->ptr) { free(p->ptr); } p->nchars = 0; p->allocchars = 0; } void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...) { va_list ap; int newchars = p->nchars + maxsize; void *newptr; int res; va_start(ap, line); /* Ask for more memory for the array, if needed */ if (newchars > p->allocchars) { int newmem; int newalloc; newalloc = newchars; newmem = newchars * sizeof(*p->ptr); newptr = realloc(p->ptr, newmem); if(newptr == 0) { warning("Cannot realloc more memory (%i) in pinfo_addline. " "Not adding the content.", newmem); return; } p->ptr = (char *) newptr; p->allocchars = newalloc; } res = vsnprintf(p->ptr + p->nchars, (p->allocchars - p->nchars), line, ap); p->nchars += res; /* We don't store the final 0 */ } void pinfo_dump(const struct Procinfo *p, int fd) { if (p->ptr) { int res; int rest = p->nchars; while (rest > 0) { res = write(fd, p->ptr, rest); if (res == -1) { warning("Cannot write more chars in pinfo_dump"); return; } rest -= res; } } } int pinfo_size(const struct Procinfo *p) { return p->nchars; } void pinfo_set_enqueue_time(struct Procinfo *p) { gettimeofday(&p->enqueue_time, 0); p->start_time.tv_sec = 0; p->start_time.tv_usec = 0; p->end_time.tv_sec = 0; p->end_time.tv_usec = 0; } void pinfo_set_start_time(struct Procinfo *p) { gettimeofday(&p->start_time, 0); p->end_time.tv_sec = 0; p->end_time.tv_usec = 0; } void pinfo_set_end_time(struct Procinfo *p) { gettimeofday(&p->end_time, 0); } float pinfo_time_until_now(const struct Procinfo *p) { float t; struct timeval now; gettimeofday(&now, 0); t = now.tv_sec - p->start_time.tv_sec; t += (float) (now.tv_usec - p->start_time.tv_usec) / 1000000.; return t; } float pinfo_time_run(const struct Procinfo *p) { float t; t = p->end_time.tv_sec - p->start_time.tv_sec; t += (float) (p->end_time.tv_usec - p->start_time.tv_usec) / 1000000.; return t; } ts-0.7.5/jobs.c0000644000000000000000000010567112476424652011426 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2013 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include "main.h" /* The list will access them */ int busy_slots = 0; int max_slots = 1; struct Notify { int socket; int jobid; struct Notify *next; }; /* Globals */ static struct Job *firstjob = 0; static struct Job *first_finished_job = 0; static int jobids = 0; /* This is used for dependencies from jobs * already out of the queue */ static int last_errorlevel = 0; /* Before the first job, let's consider a good previous result */ /* We need this to handle well "-d" after a "-nf" run */ static int last_finished_jobid; static struct Notify *first_notify = 0; int max_jobs; static struct Job * get_job(int jobid); void notify_errorlevel(struct Job *p); static void send_list_line(int s, const char * str) { struct msg m; /* Message */ m.type = LIST_LINE; m.u.size = strlen(str) + 1; send_msg(s, &m); /* Send the line */ send_bytes(s, str, m.u.size); } static void send_urgent_ok(int s) { struct msg m; /* Message */ m.type = URGENT_OK; send_msg(s, &m); } static void send_swap_jobs_ok(int s) { struct msg m; /* Message */ m.type = SWAP_JOBS_OK; send_msg(s, &m); } static struct Job * find_previous_job(const struct Job *final) { struct Job *p; /* Show Queued or Running jobs */ p = firstjob; while(p != 0) { if (p->next == final) return p; p = p->next; } return 0; } static struct Job * findjob(int jobid) { struct Job *p; /* Show Queued or Running jobs */ p = firstjob; while(p != 0) { if (p->jobid == jobid) return p; p = p->next; } return 0; } static struct Job * findjob_holding_client() { struct Job *p; /* Show Queued or Running jobs */ p = firstjob; while(p != 0) { if (p->state == HOLDING_CLIENT) return p; p = p->next; } return 0; } static struct Job * find_finished_job(int jobid) { struct Job *p; /* Show Queued or Running jobs */ p = first_finished_job; while(p != 0) { if (p->jobid == jobid) return p; p = p->next; } return 0; } static int count_not_finished_jobs() { int count=0; struct Job *p; /* Show Queued or Running jobs */ p = firstjob; while(p != 0) { ++count; p = p->next; } return count; } static void add_notify_errorlevel_to(struct Job *job, int jobid) { int *p; int newsize = (job->notify_errorlevel_to_size + 1) * sizeof(int); p = (int *) realloc(job->notify_errorlevel_to, newsize); if (p == 0) error("Cannot allocate more memory for notify_errorlist_to for jobid %i," " having already %i elements", job->jobid, job->notify_errorlevel_to_size); job->notify_errorlevel_to = p; job->notify_errorlevel_to_size += 1; job->notify_errorlevel_to[job->notify_errorlevel_to_size - 1] = jobid; } void s_mark_job_running(int jobid) { struct Job *p; p = findjob(jobid); if (!p) error("Cannot mark the jobid %i RUNNING.", jobid); p->state = RUNNING; } /* -1 means nothing awaken, otherwise returns the jobid awaken */ int wake_hold_client() { struct Job *p; p = findjob_holding_client(); if (p) { p->state = QUEUED; return p->jobid; } return -1; } const char * jstate2string(enum Jobstate s) { const char * jobstate; switch(s) { case QUEUED: jobstate = "queued"; break; case RUNNING: jobstate = "running"; break; case FINISHED: jobstate = "finished"; break; case SKIPPED: jobstate = "skipped"; break; case HOLDING_CLIENT: jobstate = "skipped"; break; } return jobstate; } void s_list(int s) { struct Job *p; char *buffer; /* Times: 0.00/0.00/0.00 - 4+4+4+2 = 14*/ buffer = joblist_headers(); send_list_line(s,buffer); free(buffer); /* Show Queued or Running jobs */ p = firstjob; while(p != 0) { if (p->state != HOLDING_CLIENT) { buffer = joblist_line(p); send_list_line(s,buffer); free(buffer); } p = p->next; } p = first_finished_job; /* Show Finished jobs */ while(p != 0) { buffer = joblist_line(p); send_list_line(s,buffer); free(buffer); p = p->next; } } static struct Job * newjobptr() { struct Job *p; if (firstjob == 0) { firstjob = (struct Job *) malloc(sizeof(*firstjob)); firstjob->next = 0; firstjob->output_filename = 0; firstjob->command = 0; return firstjob; } p = firstjob; while(p->next != 0) p = p->next; p->next = (struct Job *) malloc(sizeof(*p)); p->next->next = 0; p->next->output_filename = 0; p->next->command = 0; return p->next; } /* Returns -1 if no last job id found */ static int find_last_jobid_in_queue(int neglect_jobid) { struct Job *p; int last_jobid = -1; p = firstjob; while(p != 0) { if (p->jobid != neglect_jobid && p->jobid > last_jobid) last_jobid = p->jobid; p = p->next; } return last_jobid; } /* Returns -1 if no last job id found */ static int find_last_stored_jobid_finished() { struct Job *p; int last_jobid = -1; p = first_finished_job; while(p != 0) { if (p->jobid > last_jobid) last_jobid = p->jobid; p = p->next; } return last_jobid; } /* Returns job id or -1 on error */ int s_newjob(int s, struct msg *m) { struct Job *p; int res; p = newjobptr(); p->jobid = jobids++; if (count_not_finished_jobs() < max_jobs) p->state = QUEUED; else p->state = HOLDING_CLIENT; p->num_slots = m->u.newjob.num_slots; p->store_output = m->u.newjob.store_output; p->should_keep_finished = m->u.newjob.should_keep_finished; p->notify_errorlevel_to = 0; p->notify_errorlevel_to_size = 0; p->do_depend = m->u.newjob.do_depend; p->depend_on = -1; /* By default. May be overriden in the next conditions */ if (m->u.newjob.do_depend == 1) { /* Depend on the last queued job. */ /* As we already have 'p' in the queue, * neglect it during the find_last_jobid_in_queue() */ if (m->u.newjob.depend_on == -1) { p->depend_on = find_last_jobid_in_queue(p->jobid); /* We don't trust the last jobid in the queue (running or queued) * if it's not the last added job. In that case, let * the next control flow handle it as if it could not * do_depend on any still queued job. */ if (last_finished_jobid > p->depend_on) p->depend_on = -1; /* If it's queued still without result, let it know * its result to p when it finishes. */ if (p->depend_on != -1) { struct Job *depended_job; depended_job = findjob(p->depend_on); if (depended_job != 0) add_notify_errorlevel_to(depended_job, p->jobid); else warning("The jobid %i is queued to do_depend on the jobid %i" " suddenly non existant in the queue", p->jobid, p->depend_on); } else /* Otherwise take the finished job, or the last_errorlevel */ { if (m->u.newjob.depend_on == -1) { int ljobid = find_last_stored_jobid_finished(); p->depend_on = ljobid; /* If we have a newer result stored, use it */ /* NOTE: * Reading this now, I don't know how ljobid can be * greater than last_finished_jobid */ if (last_finished_jobid < ljobid) { struct Job *parent; parent = find_finished_job(ljobid); if (!parent) error("jobid %i suddenly disappeared from the finished list", ljobid); p->dependency_errorlevel = parent->result.errorlevel; } else p->dependency_errorlevel = last_errorlevel; } } } else { /* The user decided what's the job this new job depends on */ struct Job *depended_job; p->depend_on = m->u.newjob.depend_on; depended_job = findjob(p->depend_on); if (depended_job != 0) add_notify_errorlevel_to(depended_job, p->jobid); else { struct Job *parent; parent = find_finished_job(p->depend_on); if (parent) { p->dependency_errorlevel = parent->result.errorlevel; } else { /* We consider as if the job not found didn't finish well */ p->dependency_errorlevel = -1; } } } } pinfo_init(&p->info); pinfo_set_enqueue_time(&p->info); /* load the command */ p->command = malloc(m->u.newjob.command_size); if (p->command == 0) error("Cannot allocate memory in s_newjob command_size (%i)", m->u.newjob.command_size); res = recv_bytes(s, p->command, m->u.newjob.command_size); if (res == -1) error("wrong bytes received"); /* load the label */ p->label = 0; if (m->u.newjob.label_size > 0) { char *ptr; ptr = (char *) malloc(m->u.newjob.label_size); if (ptr == 0) error("Cannot allocate memory in s_newjob env_size(%i)", m->u.newjob.env_size); res = recv_bytes(s, ptr, m->u.newjob.label_size); if (res == -1) error("wrong bytes received"); p->label = ptr; } /* load the info */ if (m->u.newjob.env_size > 0) { char *ptr; ptr = (char *) malloc(m->u.newjob.env_size); if (ptr == 0) error("Cannot allocate memory in s_newjob env_size(%i)", m->u.newjob.env_size); res = recv_bytes(s, ptr, m->u.newjob.env_size); if (res == -1) error("wrong bytes received"); pinfo_addinfo(&p->info, m->u.newjob.env_size+100, "Environment:\n%s", ptr); free(ptr); } return p->jobid; } /* This assumes the jobid exists */ void s_removejob(int jobid) { struct Job *p; struct Job *newnext; if (firstjob->jobid == jobid) { struct Job *newfirst; /* First job is to be removed */ newfirst = firstjob->next; free(firstjob->command); free(firstjob->output_filename); pinfo_free(&firstjob->info); free(firstjob->label); free(firstjob); firstjob = newfirst; return; } p = firstjob; /* Not first job */ while (p->next != 0) { if (p->next->jobid == jobid) break; p = p->next; } if (p->next == 0) error("Job to be removed not found. jobid=%i", jobid); newnext = p->next->next; free(p->next->command); free(p->next); p->next = newnext; } /* -1 if no one should be run. */ int next_run_job() { struct Job *p; const int free_slots = max_slots - busy_slots; /* busy_slots may be bigger than the maximum slots, * if the user was running many jobs, and suddenly * trimmed the maximum slots down. */ if (free_slots <= 0) return -1; /* If there are no jobs to run... */ if (firstjob == 0) return -1; /* Look for a runnable task */ p = firstjob; while(p != 0) { if (p->state == QUEUED) { if (p->depend_on >= 0) { struct Job *do_depend_job = get_job(p->depend_on); /* We won't try to run any job do_depending on an unfinished * job */ if (do_depend_job != NULL && (do_depend_job->state == QUEUED || do_depend_job->state == RUNNING)) { /* Next try */ p = p->next; continue; } } if (free_slots >= p->num_slots) { busy_slots = busy_slots + p->num_slots; return p->jobid; } } p = p->next; } return -1; } /* Returns 1000 if no limit, The limit otherwise. */ static int get_max_finished_jobs() { char *limit; limit = getenv("TS_MAXFINISHED"); if (limit == NULL) return 1000; return abs(atoi(limit)); } /* Add the job to the finished queue. */ static void new_finished_job(struct Job *j) { struct Job *p; int count, max; max = get_max_finished_jobs(); count = 0; if (first_finished_job == 0 && count < max) { first_finished_job = j; first_finished_job->next = 0; return; } ++count; p = first_finished_job; while(p->next != 0) { p = p->next; ++count; } /* If too many jobs, wipe out the first */ if (count >= max) { struct Job *tmp; tmp = first_finished_job; first_finished_job = first_finished_job->next; free(tmp->command); free(tmp->output_filename); pinfo_free(&tmp->info); free(tmp->label); free(tmp); } p->next = j; p->next->next = 0; return; } static int job_is_in_state(int jobid, enum Jobstate state) { struct Job *p; p = findjob(jobid); if (p == 0) return 0; if (p->state == state) return 1; return 0; } int job_is_running(int jobid) { return job_is_in_state(jobid, RUNNING); } int job_is_holding_client(int jobid) { return job_is_in_state(jobid, HOLDING_CLIENT); } static int in_notify_list(int jobid) { struct Notify *n, *tmp; n = first_notify; while (n != 0) { tmp = n; n = n->next; if (tmp->jobid == jobid) return 1; } return 0; } void job_finished(const struct Result *result, int jobid) { struct Job *p; if (busy_slots <= 0) error("Wrong state in the server. busy_slots = %i instead of greater than 0", busy_slots); p = findjob(jobid); if (p == 0) error("on jobid %i finished, it doesn't exist", jobid); /* The job may be not only in running state, but also in other states, as * we call this to clean up the jobs list in case of the client closing the * connection. */ if (p->state == RUNNING) busy_slots = busy_slots - p->num_slots; /* Mark state */ if (result->skipped) p->state = SKIPPED; else p->state = FINISHED; p->result = *result; last_finished_jobid = p->jobid; notify_errorlevel(p); pinfo_set_end_time(&p->info); if (p->result.died_by_signal) pinfo_addinfo(&p->info, 100, "Exit status: killed by signal %i\n", p->result.signal); else pinfo_addinfo(&p->info, 100, "Exit status: died with exit code %i\n", p->result.errorlevel); /* Find the pointing node, to * update it removing the finished job. */ { struct Job **jpointer = 0; struct Job *newfirst = p->next; if (firstjob == p) jpointer = &firstjob; else { struct Job *p2; p2 = firstjob; while(p2 != 0) { if (p2->next == p) { jpointer = &(p2->next); break; } p2 = p2->next; } } /* Add it to the finished queue (maybe temporarily) */ if (p->should_keep_finished || in_notify_list(p->jobid)) new_finished_job(p); /* Remove it from the run queue */ if (jpointer == 0) error("Cannot remove a finished job from the " "queue list (jobid=%i)", p->jobid); *jpointer = newfirst; } } void s_clear_finished() { struct Job *p; if (first_finished_job == 0) return; p = first_finished_job; first_finished_job = 0; while (p != 0) { struct Job *tmp; tmp = p->next; free(p->command); free(p->output_filename); pinfo_free(&p->info); free(p->label); free(p); p = tmp; } } void s_process_runjob_ok(int jobid, char *oname, int pid) { struct Job *p; p = findjob(jobid); if (p == 0) error("Job %i already run not found on runjob_ok", jobid); if (p->state != RUNNING) error("Job %i not running, but %i on runjob_ok", jobid, p->state); p->pid = pid; p->output_filename = oname; pinfo_set_start_time(&p->info); } void s_send_runjob(int s, int jobid) { struct msg m; struct Job *p; p = findjob(jobid); if (p == 0) error("Job %i was expected to run", jobid); m.type = RUNJOB; /* TODO * We should make the dependencies update the jobids they're do_depending on. * Then, on finish, these could set the errorlevel to send to its dependency childs. * We cannot consider that the jobs will leave traces in the finished job list (-nf?) . */ m.u.last_errorlevel = p->dependency_errorlevel; send_msg(s, &m); } void s_job_info(int s, int jobid) { struct Job *p = 0; struct msg m; if (jobid == -1) { /* This means that we want the job info of the running task, or that * of the last job run */ if (busy_slots > 0) { p = firstjob; if (p == 0) error("Internal state WAITING, but job not run." "firstjob = %x", firstjob); } else { p = first_finished_job; if (p == 0) { send_list_line(s, "No jobs.\n"); return; } while(p->next != 0) p = p->next; } } else { p = firstjob; while (p != 0 && p->jobid != jobid) p = p->next; /* Look in finished jobs if needed */ if (p == 0) { p = first_finished_job; while (p != 0 && p->jobid != jobid) p = p->next; } } if (p == 0) { char tmp[50]; sprintf(tmp, "Job %i not finished or not running.\n", jobid); send_list_line(s, tmp); return; } m.type = INFO_DATA; send_msg(s, &m); pinfo_dump(&p->info, s); fd_nprintf(s, 100, "Command: "); if (p->depend_on != -1) fd_nprintf(s, 100, "[%i]&& ", p->depend_on); write(s, p->command, strlen(p->command)); fd_nprintf(s, 100, "\n"); fd_nprintf(s, 100, "Slots required: %i\n", p->num_slots); fd_nprintf(s, 100, "Enqueue time: %s", ctime(&p->info.enqueue_time.tv_sec)); if (p->state == RUNNING) { fd_nprintf(s, 100, "Start time: %s", ctime(&p->info.start_time.tv_sec)); fd_nprintf(s, 100, "Time running: %fs\n", pinfo_time_until_now(&p->info)); } else if (p->state == FINISHED) { fd_nprintf(s, 100, "Start time: %s", ctime(&p->info.start_time.tv_sec)); fd_nprintf(s, 100, "End time: %s", ctime(&p->info.end_time.tv_sec)); fd_nprintf(s, 100, "Time run: %fs\n", pinfo_time_run(&p->info)); } } void s_send_output(int s, int jobid) { struct Job *p = 0; struct msg m; if (jobid == -1) { /* This means that we want the output info of the running task, or that * of the last job run */ if (busy_slots > 0) { p = firstjob; if (p == 0) error("Internal state WAITING, but job not run." "firstjob = %x", firstjob); } else { p = first_finished_job; if (p == 0) { send_list_line(s, "No jobs.\n"); return; } while(p->next != 0) p = p->next; } } else { p = get_job(jobid); if (p != 0 && p->state != RUNNING && p->state != FINISHED && p->state != SKIPPED) p = 0; } if (p == 0) { char tmp[50]; if (jobid == -1) sprintf(tmp, "The last job has not finished or is not running.\n"); else sprintf(tmp, "Job %i not finished or not running.\n", jobid); send_list_line(s, tmp); return; } if (p->state == SKIPPED) { char tmp[50]; if (jobid == -1) sprintf(tmp, "The last job was skipped due to a dependency.\n"); else sprintf(tmp, "Job %i was skipped due to a dependency.\n", jobid); send_list_line(s, tmp); return; } m.type = ANSWER_OUTPUT; m.u.output.store_output = p->store_output; m.u.output.pid = p->pid; if (m.u.output.store_output && p->output_filename) m.u.output.ofilename_size = strlen(p->output_filename) + 1; else m.u.output.ofilename_size = 0; send_msg(s, &m); if (m.u.output.ofilename_size > 0) send_bytes(s, p->output_filename, m.u.output.ofilename_size); } void notify_errorlevel(struct Job *p) { int i; last_errorlevel = p->result.errorlevel; for(i = 0; i < p->notify_errorlevel_to_size; ++i) { struct Job *notified; notified = get_job(p->notify_errorlevel_to[i]); if (notified) { notified->dependency_errorlevel = p->result.errorlevel; } } } /* jobid is input/output. If the input is -1, it's changed to the jobid * removed */ int s_remove_job(int s, int *jobid) { struct Job *p = 0; struct msg m; struct Job *before_p = 0; if (*jobid == -1) { /* Find the last job added */ p = firstjob; if (p != 0) { while (p->next != 0) { before_p = p; p = p->next; } } else { /* last 'finished' */ p = first_finished_job; if (p) { while (p->next != 0) { before_p = p; p = p->next; } } } } else { p = firstjob; if (p != 0) { while (p->next != 0 && p->jobid != *jobid) { before_p = p; p = p->next; } } /* If not found, look in the 'finished' list */ if (p == 0 || p->jobid != *jobid) { p = first_finished_job; if (p != 0) { while (p->next != 0 && p->jobid != *jobid) { before_p = p; p = p->next; } if (p->jobid != *jobid) p = 0; } } } if (p == 0 || p->state == RUNNING || p == firstjob) { char tmp[50]; if (*jobid == -1) sprintf(tmp, "The last job cannot be removed.\n"); else sprintf(tmp, "The job %i cannot be removed.\n", *jobid); send_list_line(s, tmp); return 0; } /* Return the jobid found */ *jobid = p->jobid; /* Tricks for the check_notify_list */ p->state = FINISHED; p->result.errorlevel = -1; notify_errorlevel(p); /* Notify the clients in wait_job */ check_notify_list(m.u.jobid); /* Update the list pointers */ if (p == first_finished_job) first_finished_job = p->next; else before_p->next = p->next; free(p->notify_errorlevel_to); free(p->command); free(p->output_filename); pinfo_free(&p->info); free(p->label); free(p); m.type = REMOVEJOB_OK; send_msg(s, &m); return 1; } static void add_to_notify_list(int s, int jobid) { struct Notify *n; struct Notify *new; new = (struct Notify *) malloc(sizeof(*new)); new->socket = s; new->jobid = jobid; new->next = 0; n = first_notify; if (n == 0) { first_notify = new; return; } while(n->next != 0) n = n->next; n->next = new; } static void send_waitjob_ok(int s, int errorlevel) { struct msg m; m.type = WAITJOB_OK; m.u.result.errorlevel = errorlevel; send_msg(s, &m); } static struct Job * get_job(int jobid) { struct Job *j; j = findjob(jobid); if (j != NULL) return j; j = find_finished_job(jobid); if (j != NULL) return j; return 0; } /* Don't complain, if the socket doesn't exist */ void s_remove_notification(int s) { struct Notify *n; struct Notify *previous; n = first_notify; while (n != 0 && n->socket != s) n = n->next; if (n == 0 || n->socket != s) return; /* Remove the notification */ previous = first_notify; if (n == previous) { first_notify = n->next; free(n); return; } /* if not the first... */ while(previous->next != n) previous = previous->next; previous->next = n->next; free(n); } static void destroy_finished_job(struct Job *j) { if (j == first_finished_job) first_finished_job = j->next; else { struct Job *i; for(i = first_finished_job; i != 0; ++i) { if (i->next == j) { i->next = j->next; break; } } if (i == 0) { error("Cannot destroy the expected job %i", j->jobid); } } free(j->notify_errorlevel_to); free(j->command); free(j->output_filename); pinfo_free(&j->info); free(j->label); free(j); } /* This is called when a job finishes */ void check_notify_list(int jobid) { struct Notify *n, *tmp; struct Job *j; n = first_notify; while (n != 0) { tmp = n; n = n->next; if (tmp->jobid == jobid) { j = get_job(jobid); /* If the job finishes, notify the waiter */ if (j->state == FINISHED || j->state == SKIPPED) { send_waitjob_ok(tmp->socket, j->result.errorlevel); /* We want to get the next Nofity* before we remove * the actual 'n'. As s_remove_notification() simply * removes the element from the linked list, we can * safely follow on the list from n->next. */ s_remove_notification(tmp->socket); /* Remove the jobs that were temporarily in the finished list, * just for their notifiers. */ if (!in_notify_list(jobid) && !j->should_keep_finished) { destroy_finished_job(j); } } } } } void s_wait_job(int s, int jobid) { struct Job *p = 0; if (jobid == -1) { /* Find the last job added */ p = firstjob; if (p != 0) while (p->next != 0) p = p->next; /* Look in finished jobs if needed */ if (p == 0) { p = first_finished_job; if (p != 0) while (p->next != 0) p = p->next; } } else { p = firstjob; while (p != 0 && p->jobid != jobid) p = p->next; /* Look in finished jobs if needed */ if (p == 0) { p = first_finished_job; while (p != 0 && p->jobid != jobid) p = p->next; } } if (p == 0) { char tmp[50]; if (jobid == -1) sprintf(tmp, "The last job cannot be waited.\n"); else sprintf(tmp, "The job %i cannot be waited.\n", jobid); send_list_line(s, tmp); return; } if (p->state == FINISHED || p->state == SKIPPED) { send_waitjob_ok(s, p->result.errorlevel); } else add_to_notify_list(s, p->jobid); } void s_wait_running_job(int s, int jobid) { struct Job *p = 0; /* The job finding algorithm should be similar to that of * s_send_output, because this will be used by "-t" and "-c" */ if (jobid == -1) { /* This means that we want the output info of the running task, or that * of the last job run */ if (busy_slots > 0) { p = firstjob; if (p == 0) error("Internal state WAITING, but job not run." "firstjob = %x", firstjob); } else { p = first_finished_job; if (p == 0) { send_list_line(s, "No jobs.\n"); return; } while(p->next != 0) p = p->next; } } else { p = firstjob; while (p != 0 && p->jobid != jobid) p = p->next; /* Look in finished jobs if needed */ if (p == 0) { p = first_finished_job; while (p != 0 && p->jobid != jobid) p = p->next; } } if (p == 0) { char tmp[50]; if (jobid == -1) sprintf(tmp, "The last job cannot be waited.\n"); else sprintf(tmp, "The job %i cannot be waited.\n", jobid); send_list_line(s, tmp); return; } if (p->state == FINISHED || p->state == SKIPPED) { send_waitjob_ok(s, p->result.errorlevel); } else add_to_notify_list(s, p->jobid); } void s_set_max_slots(int new_max_slots) { if (new_max_slots > 0) max_slots = new_max_slots; else warning("Received new_max_slots=%i", new_max_slots); } void s_get_max_slots(int s) { struct msg m; /* Message */ m.type = GET_MAX_SLOTS_OK; m.u.max_slots = max_slots; send_msg(s, &m); } void s_move_urgent(int s, int jobid) { struct Job *p = 0; struct Job *tmp1; if (jobid == -1) { /* Find the last job added */ p = firstjob; if (p != 0) while (p->next != 0) p = p->next; } else { p = firstjob; while (p != 0 && p->jobid != jobid) p = p->next; } if (p == 0 || firstjob->next == 0) { char tmp[50]; if (jobid == -1) sprintf(tmp, "The last job cannot be urged.\n"); else sprintf(tmp, "The job %i cannot be urged.\n", jobid); send_list_line(s, tmp); return; } /* Interchange the pointers */ tmp1 = find_previous_job(p); tmp1->next = p->next; p->next = firstjob->next; firstjob->next = p; send_urgent_ok(s); } void s_swap_jobs(int s, int jobid1, int jobid2) { struct Job *p1, *p2; struct Job *prev1, *prev2; struct Job *tmp; p1 = findjob(jobid1); p2 = findjob(jobid2); if (p1 == 0 || p2 == 0 || p1 == firstjob || p2 == firstjob) { char prev[60]; sprintf(prev, "The jobs %i and %i cannot be swapped.\n", jobid1, jobid2); send_list_line(s, prev); return; } /* Interchange the pointers */ prev1 = find_previous_job(p1); prev2 = find_previous_job(p2); prev1->next = p2; prev2->next = p1; tmp = p1->next; p1->next = p2->next; p2->next = tmp; send_swap_jobs_ok(s); } static void send_state(int s, enum Jobstate state) { struct msg m; m.type = ANSWER_STATE; m.u.state = state; send_msg(s, &m); } void s_send_state(int s, int jobid) { struct Job *p = 0; if (jobid == -1) { /* Find the last job added */ p = firstjob; if (p != 0) while (p->next != 0) p = p->next; /* Look in finished jobs if needed */ if (p == 0) { p = first_finished_job; if (p != 0) while (p->next != 0) p = p->next; } } else { p = get_job(jobid); } if (p == 0) { char tmp[50]; if (jobid == -1) sprintf(tmp, "The last job cannot be stated.\n"); else sprintf(tmp, "The job %i cannot be stated.\n", jobid); send_list_line(s, tmp); return; } /* Interchange the pointers */ send_state(s, p->state); } static void dump_job_struct(FILE *out, const struct Job *p) { fprintf(out, " new_job\n"); fprintf(out, " jobid %i\n", p->jobid); fprintf(out, " command \"%s\"\n", p->command); fprintf(out, " state %s\n", jstate2string(p->state)); fprintf(out, " result.errorlevel %i\n", p->result.errorlevel); fprintf(out, " output_filename \"%s\"\n", p->output_filename ? p->output_filename : "NULL"); fprintf(out, " store_output %i\n", p->store_output); fprintf(out, " pid %i\n", p->pid); fprintf(out, " should_keep_finished %i\n", p->should_keep_finished); } void dump_jobs_struct(FILE *out) { const struct Job *p; fprintf(out, "New_jobs\n"); p = firstjob; while (p != 0) { dump_job_struct(out, p); p = p->next; } p = first_finished_job; while (p != 0) { dump_job_struct(out, p); p = p->next; } } static void dump_notify_struct(FILE *out, const struct Notify *n) { fprintf(out, " notify\n"); fprintf(out, " jobid %i\n", n->jobid); fprintf(out, " socket \"%i\"\n", n->socket); } void dump_notifies_struct(FILE *out) { const struct Notify *n; fprintf(out, "New_notifies\n"); n = first_notify; while (n != 0) { dump_notify_struct(out, n); n = n->next; } } void joblist_dump(int fd) { struct Job *p; char *buffer; buffer = joblistdump_headers(); write(fd,buffer, strlen(buffer)); free(buffer); /* We reuse the headers from the list */ buffer = joblist_headers(); write(fd, "# ", 2); write(fd, buffer, strlen(buffer)); /* Show Finished jobs */ p = first_finished_job; while(p != 0) { buffer = joblist_line(p); write(fd, "# ", 2); write(fd,buffer, strlen(buffer)); free(buffer); p = p->next; } write(fd, "\n", 1); /* Show Queued or Running jobs */ p = firstjob; while(p != 0) { buffer = joblistdump_torun(p); write(fd,buffer,strlen(buffer)); free(buffer); p = p->next; } } ts-0.7.5/list.c0000644000000000000000000001277312476424652011444 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include "main.h" /* From jobs.c */ extern int busy_slots; extern int max_slots; char * joblistdump_headers() { char * line; line = malloc(600); snprintf(line, 600, "#!/bin/sh\n# - task spooler (ts) job dump\n" "# This file has been created because a SIGTERM killed\n" "# your queue server.\n" "# The finished commands are listed first.\n" "# The commands running or to be run are stored as you would\n" "# probably run them. Take care - some quotes may have got" " broken\n\n"); return line; } char * joblist_headers() { char * line; line = malloc(100); snprintf(line, 100, "%-4s %-10s %-20s %-8s %-14s %s [run=%i/%i]\n", "ID", "State", "Output", "E-Level", "Times(r/u/s)", "Command", busy_slots, max_slots); return line; } static int max(int a, int b) { if (a > b) return a; return b; } static const char * ofilename_shown(const struct Job *p) { const char * output_filename; if (p->state == SKIPPED) { output_filename = "(no output)"; } else if (p->store_output) { if (p->state == QUEUED) { output_filename = "(file)"; } else { if (p->output_filename == 0) /* This may happen due to concurrency * problems */ output_filename = "(...)"; else output_filename = p->output_filename; } } else output_filename = "stdout"; return output_filename; } static char * print_noresult(const struct Job *p) { const char * jobstate; const char * output_filename; int maxlen; char * line; /* 18 chars should suffice for a string like "[int]&& " */ char dependstr[18] = ""; jobstate = jstate2string(p->state); output_filename = ofilename_shown(p); maxlen = 4 + 1 + 10 + 1 + max(20, strlen(output_filename)) + 1 + 8 + 1 + 14 + 1 + strlen(p->command) + 20; /* 20 is the margin for errors */ if (p->label) maxlen += 3 + strlen(p->label); if (p->do_depend) { maxlen += sizeof(dependstr); if (p->depend_on == -1) snprintf(dependstr, sizeof(dependstr), "&& "); else snprintf(dependstr, sizeof(dependstr), "[%i]&& ", p->depend_on); } line = (char *) malloc(maxlen); if (line == NULL) error("Malloc for %i failed.\n", maxlen); if (p->label) snprintf(line, maxlen, "%-4i %-10s %-20s %-8s %14s %s[%s]%s\n", p->jobid, jobstate, output_filename, "", "", dependstr, p->label, p->command); else snprintf(line, maxlen, "%-4i %-10s %-20s %-8s %14s %s%s\n", p->jobid, jobstate, output_filename, "", "", dependstr, p->command); return line; } static char * print_result(const struct Job *p) { const char * jobstate; int maxlen; char * line; const char * output_filename; /* 18 chars should suffice for a string like "[int]&& " */ char dependstr[18] = ""; jobstate = jstate2string(p->state); output_filename = ofilename_shown(p); maxlen = 4 + 1 + 10 + 1 + max(20, strlen(output_filename)) + 1 + 8 + 1 + 14 + 1 + strlen(p->command) + 20; /* 20 is the margin for errors */ if (p->label) maxlen += 3 + strlen(p->label); if (p->do_depend) { maxlen += sizeof(dependstr); if (p->depend_on == -1) snprintf(dependstr, sizeof(dependstr), "&& "); else snprintf(dependstr, sizeof(dependstr), "[%i]&& ", p->depend_on); } line = (char *) malloc(maxlen); if (line == NULL) error("Malloc for %i failed.\n", maxlen); if (p->label) snprintf(line, maxlen, "%-4i %-10s %-20s %-8i %0.2f/%0.2f/%0.2f %s[%s]" "%s\n", p->jobid, jobstate, output_filename, p->result.errorlevel, p->result.real_ms, p->result.user_ms, p->result.system_ms, dependstr, p->label, p->command); else snprintf(line, maxlen, "%-4i %-10s %-20s %-8i %0.2f/%0.2f/%0.2f %s%s\n", p->jobid, jobstate, output_filename, p->result.errorlevel, p->result.real_ms, p->result.user_ms, p->result.system_ms, dependstr, p->command); return line; } char * joblist_line(const struct Job *p) { char * line; if (p->state == FINISHED) line = print_result(p); else line = print_noresult(p); return line; } char * joblistdump_torun(const struct Job *p) { int maxlen; char * line; maxlen = 10 + strlen(p->command) + 20; /* 20 is the margin for errors */ line = (char *) malloc(maxlen); if (line == NULL) error("Malloc for %i failed.\n", maxlen); snprintf(line, maxlen, "ts %s\n", p->command); return line; } ts-0.7.5/mail.c0000644000000000000000000000647312476424652011413 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include #include #include /* Needed for any main.h inclusion */ #include "main.h" /* Returns the write pipe */ static int run_sendmail(const char *dest) { int pid; int p[2]; pipe(p); pid = fork(); switch(pid) { case 0: /* Child */ restore_sigmask(); close(0); close(1); close(2); close(p[1]); dup2(p[0], 0); execl("/usr/sbin/sendmail", "sendmail", "-oi", dest, NULL); error("run sendmail"); case -1: error("fork sendmail"); default: /* Parent */ close(p[0]); } return p[1]; } static void write_header(int fd, const char *dest, const char * command, int jobid, int errorlevel) { fd_nprintf(fd, 100, "From: Task Spooler \n"); fd_nprintf(fd, 500, "To: %s\n", dest); fd_nprintf(fd, 500, "Subject: the task %i finished with error %i. \n", jobid, errorlevel); fd_nprintf(fd, 500, "\nCommand: %s\n", command); fd_nprintf(fd, 500, "Output:\n"); } static void copy_output(int write_fd, const char *ofname) { int file_fd; char buffer[1000]; int read_bytes; int res; file_fd = open(ofname, O_RDONLY); if (file_fd == -1) error("mail: Cannot open the output file %s", ofname); do { read_bytes = read(file_fd, buffer, 1000); if (read_bytes > 0) { res = write(write_fd, buffer, read_bytes); if (res == -1) warning("Cannot write to the mail pipe %i", write_fd); } } while (read_bytes > 0); if (read_bytes == -1) warning("Cannot read the output file %s from %i", ofname, file_fd); } void hook_on_finish(int jobid, int errorlevel, const char *ofname, const char *command) { char *onfinish; int pid; char sjobid[20]; char serrorlevel[20]; int status; onfinish = getenv("TS_ONFINISH"); if (onfinish == NULL) return; pid = fork(); switch(pid) { case 0: /* Child */ restore_sigmask(); sprintf(sjobid, "%i", jobid); sprintf(serrorlevel, "%i", errorlevel); execlp(onfinish, onfinish, sjobid, serrorlevel, ofname, command, NULL); case -1: error("fork on finish"); default: /* Parent */ wait(&status); } } void send_mail(int jobid, int errorlevel, const char *ofname, const char *command) { char to[101]; char *user; char *env_to; int write_fd; int status; env_to = getenv("TS_MAILTO"); if (env_to == NULL || strlen(env_to) > 100) { user = getenv("USER"); if (user == NULL) user = "nobody"; strcpy(to, user); /*strcat(to, "@localhost");*/ } else strcpy(to, env_to); write_fd = run_sendmail(to); write_header(write_fd, to, command, jobid, errorlevel); copy_output(write_fd, ofname); close(write_fd); wait(&status); } ts-0.7.5/main.c0000644000000000000000000004263612476424652011416 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include "main.h" extern char *optarg; extern int optind, opterr, optopt; /* Globals */ struct Command_line command_line; int server_socket; /* Globals for the environment of getopt */ static char getopt_env[] = "POSIXLY_CORRECT=YES"; static char *old_getopt_env; static char version[] = "Task Spooler v0.7.5 - a task queue system for the unix user.\n" "Copyright (C) 2007-2013 Lluis Batlle i Rossell"; static void default_command_line() { command_line.request = c_LIST; command_line.need_server = 0; command_line.store_output = 1; command_line.should_go_background = 1; command_line.should_keep_finished = 1; command_line.gzip = 0; command_line.send_output_by_mail = 0; command_line.label = 0; command_line.do_depend = 0; command_line.depend_on = -1; /* -1 means depend on previous */ command_line.max_slots = 1; command_line.wait_enqueuing = 1; command_line.stderr_apart = 0; command_line.num_slots = 1; } void get_command(int index, int argc, char **argv) { command_line.command.array = &(argv[index]); command_line.command.num = argc - index; } static int get_two_jobs(const char *str, int *j1, int *j2) { char tmp[50]; char *tmp2; if(strlen(str) >= 50) return 0; strcpy(tmp, str); tmp2 = strchr(tmp , '-'); if (tmp2 == NULL) return 0; /* We change the '-' to '\0', so we have a delimiter, * and we can access the two strings for the ids */ *tmp2 = '\0'; /* Skip the '\0', and point tmp2 to the second id */ ++tmp2; *j1 = atoi(tmp); *j2 = atoi(tmp2); return 1; } void parse_opts(int argc, char **argv) { int c; int res; /* Parse options */ while(1) { c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:u:s:U:i:N:L:dS:D:"); if (c == -1) break; switch(c) { case 'K': command_line.request = c_KILL_SERVER; command_line.should_go_background = 0; break; case 'l': command_line.request = c_LIST; break; case 'h': command_line.request = c_SHOW_HELP; break; case 'd': command_line.do_depend = 1; command_line.depend_on = -1; break; case 'V': command_line.request = c_SHOW_VERSION; break; case 'C': command_line.request = c_CLEAR_FINISHED; break; case 'c': command_line.request = c_CAT; command_line.jobid = atoi(optarg); break; case 'o': command_line.request = c_SHOW_OUTPUT_FILE; command_line.jobid = atoi(optarg); break; case 'n': command_line.store_output = 0; break; case 'L': command_line.label = optarg; break; case 'g': command_line.gzip = 1; break; case 'f': command_line.should_go_background = 0; break; case 'm': command_line.send_output_by_mail = 1; break; case 't': command_line.request = c_TAIL; command_line.jobid = atoi(optarg); break; case 'p': command_line.request = c_SHOW_PID; command_line.jobid = atoi(optarg); break; case 'i': command_line.request = c_INFO; command_line.jobid = atoi(optarg); break; case 'N': command_line.num_slots = atoi(optarg); if (command_line.num_slots < 0) command_line.num_slots = 0; break; case 'r': command_line.request = c_REMOVEJOB; command_line.jobid = atoi(optarg); break; case 'w': command_line.request = c_WAITJOB; command_line.jobid = atoi(optarg); break; case 'u': command_line.request = c_URGENT; command_line.jobid = atoi(optarg); break; case 's': command_line.request = c_GET_STATE; command_line.jobid = atoi(optarg); break; case 'S': command_line.request = c_SET_MAX_SLOTS; command_line.max_slots = atoi(optarg); if (command_line.max_slots < 1) { fprintf(stderr, "You should set at minimum 1 slot.\n"); exit(-1); } break; case 'D': command_line.do_depend = 1; command_line.depend_on = atoi(optarg); break; case 'U': command_line.request = c_SWAP_JOBS; res = get_two_jobs(optarg, &command_line.jobid, &command_line.jobid2); if (!res) { fprintf(stderr, "Wrong for -U.\n"); exit(-1); } if (command_line.jobid == command_line.jobid2) { fprintf(stderr, "Wrong for -U. " "Use different ids.\n"); exit(-1); } break; case 'B': /* I picked 'B' quite at random among the letters left */ command_line.wait_enqueuing = 0; break; case 'E': command_line.stderr_apart = 1; break; case ':': switch(optopt) { case 't': command_line.request = c_TAIL; command_line.jobid = -1; /* This means the 'last' job */ break; case 'c': command_line.request = c_CAT; command_line.jobid = -1; /* This means the 'last' job */ break; case 'o': command_line.request = c_SHOW_OUTPUT_FILE; command_line.jobid = -1; /* This means the 'last' job */ break; case 'p': command_line.request = c_SHOW_PID; command_line.jobid = -1; /* This means the 'last' job */ break; case 'i': command_line.request = c_INFO; command_line.jobid = -1; /* This means the 'last' job */ break; case 'r': command_line.request = c_REMOVEJOB; command_line.jobid = -1; /* This means the 'last' added job */ break; case 'w': command_line.request = c_WAITJOB; command_line.jobid = -1; /* This means the 'last' added job */ break; case 'u': command_line.request = c_URGENT; command_line.jobid = -1; /* This means the 'last' added job */ break; case 's': command_line.request = c_GET_STATE; command_line.jobid = -1; /* This means the 'last' added job */ break; case 'S': command_line.request = c_GET_MAX_SLOTS; break; default: fprintf(stderr, "Option %c missing argument.\n", optopt); exit(-1); } break; case '?': fprintf(stderr, "Wrong option %c.\n", optopt); exit(-1); } } command_line.command.num = 0; /* if the request is still the default option... * (the default values should be centralized) */ if (optind < argc && command_line.request == c_LIST) { command_line.request = c_QUEUE; get_command(optind, argc, argv); } if (command_line.request != c_SHOW_HELP && command_line.request != c_SHOW_VERSION) command_line.need_server = 1; if ( ! command_line.store_output && ! command_line.should_go_background ) command_line.should_keep_finished = 0; if ( command_line.send_output_by_mail && ((! command_line.store_output) || command_line.gzip) ) { fprintf(stderr, "For e-mail, you should store the output (not through gzip)\n"); exit(-1); } } static void fill_first_3_handles() { int tmp_pipe1[2]; int tmp_pipe2[2]; /* This will fill handles 0 and 1 */ pipe(tmp_pipe1); /* This will fill handles 2 and 3 */ pipe(tmp_pipe2); close(tmp_pipe2[1]); } static void go_background() { int pid; pid = fork(); switch(pid) { case -1: error("fork failed"); break; case 0: close(0); close(1); close(2); /* This is a weird thing. But we will later want to * allocate special files to the 0, 1 or 2 fds. It's * almost impossible, if other important things got * allocated here. */ fill_first_3_handles(); setsid(); break; default: exit(0); } } static void print_help(const char *cmd) { printf("usage: %s [action] [-ngfmdE] [-L ] [-D ] [cmd...]\n", cmd); printf("Env vars:\n"); printf(" TS_SOCKET the path to the unix socket used by the ts command.\n"); printf(" TS_MAILTO where to mail the result (on -m). Local user by default.\n"); printf(" TS_MAXFINISHED maximum finished jobs in the queue.\n"); printf(" TS_MAXCONN maximum number of ts connections at once.\n"); printf(" TS_ONFINISH binary called on job end (passes jobid, error, outfile, command).\n"); printf(" TS_ENV command called on enqueue. Its output determines the job information.\n"); printf(" TS_SAVELIST filename which will store the list, if the server dies.\n"); printf(" TS_SLOTS amount of jobs which can run at once, read on server start.\n"); printf(" TMPDIR directory where to place the output files and the default socket.\n"); printf("Actions:\n"); printf(" -K kill the task spooler server\n"); printf(" -C clear the list of finished jobs\n"); printf(" -l show the job list (default action)\n"); printf(" -S [num] get/set the number of max simultaneous jobs of the server.\n"); printf(" -t [id] \"tail -n 10 -f\" the output of the job. Last run if not specified.\n"); printf(" -c [id] like -t, but shows all the lines. Last run if not specified.\n"); printf(" -p [id] show the pid of the job. Last run if not specified.\n"); printf(" -o [id] show the output file. Of last job run, if not specified.\n"); printf(" -i [id] show job information. Of last job run, if not specified.\n"); printf(" -s [id] show the job state. Of the last added, if not specified.\n"); printf(" -r [id] remove a job. The last added, if not specified.\n"); printf(" -w [id] wait for a job. The last added, if not specified.\n"); printf(" -u [id] put that job first. The last added, if not specified.\n"); printf(" -U swap two jobs in the queue.\n"); printf(" -B in case of full queue on the server, quit (2) instead of waiting.\n"); printf(" -h show this help\n"); printf(" -V show the program version\n"); printf("Options adding jobs:\n"); printf(" -n don't store the output of the command.\n"); printf(" -E Keep stderr apart, in a name like the output file, but adding '.e'.\n"); printf(" -g gzip the stored output (if not -n).\n"); printf(" -f don't fork into background.\n"); printf(" -m send the output by e-mail (uses sendmail).\n"); printf(" -d the job will be run only if the job before ends well\n"); printf(" -D the job will be run only if the job of given id ends well.\n"); printf(" -L name this task with a label, to be distinguished on listing.\n"); printf(" -N number of slots required by the job (1 default).\n"); } static void print_version() { puts(version); } static void set_getopt_env() { old_getopt_env = getenv("POSIXLY_CORRECT"); putenv(getopt_env); } static void unset_getopt_env() { if (old_getopt_env == NULL) { /* Wipe the string from the environment */ putenv("POSIXLY_CORRECT"); } else sprintf(getopt_env, "POSIXLY_CORRECT=%s", old_getopt_env); } int main(int argc, char **argv) { int errorlevel = 0; process_type = CLIENT; set_getopt_env(); /* This is needed in a gnu system, so getopt works well */ default_command_line(); parse_opts(argc, argv); unset_getopt_env(); /* This will be inherited by the server, if it's run */ ignore_sigpipe(); if (command_line.need_server) { ensure_server_up(); c_check_version(); } switch(command_line.request) { case c_SHOW_VERSION: print_version(argv[0]); break; case c_SHOW_HELP: print_help(argv[0]); break; case c_QUEUE: if (command_line.command.num <= 0) error("Tried to queue a void command. parameters: %i", command_line.command.num); if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_new_job(); command_line.jobid = c_wait_newjob_ok(); if (command_line.store_output) { printf("%i\n", command_line.jobid); fflush(stdout); } if (command_line.should_go_background) { go_background(); c_wait_server_commands(); } else { errorlevel = c_wait_server_commands(); } break; case c_LIST: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_list_jobs(); c_wait_server_lines(); break; case c_KILL_SERVER: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_shutdown_server(); break; case c_CLEAR_FINISHED: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_clear_finished(); break; case c_TAIL: if (!command_line.need_server) error("The command %i needs the server", command_line.request); errorlevel = c_tail(); /* This will not return! */ break; case c_CAT: if (!command_line.need_server) error("The command %i needs the server", command_line.request); errorlevel = c_cat(); /* This will not return! */ break; case c_SHOW_OUTPUT_FILE: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_show_output_file(); break; case c_SHOW_PID: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_show_pid(); break; case c_INFO: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_show_info(); break; case c_REMOVEJOB: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_remove_job(); break; case c_WAITJOB: if (!command_line.need_server) error("The command %i needs the server", command_line.request); errorlevel = c_wait_job(); break; case c_URGENT: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_move_urgent(); break; case c_SET_MAX_SLOTS: c_send_max_slots(command_line.max_slots); break; case c_GET_MAX_SLOTS: c_get_max_slots(); break; case c_SWAP_JOBS: if (!command_line.need_server) error("The command %i needs the server", command_line.request); c_swap_jobs(); break; case c_GET_STATE: if (!command_line.need_server) error("The command %i needs the server", command_line.request); /* This will also print the state into stdout */ c_get_state(); break; } if (command_line.need_server) { close(server_socket); } return errorlevel; } ts-0.7.5/main.h0000644000000000000000000001603212476424652011412 0ustar 00000000000000enum { CMD_LEN=500, PROTOCOL_VERSION=730 }; enum msg_types { KILL_SERVER, NEWJOB, NEWJOB_OK, RUNJOB, RUNJOB_OK, ENDJOB, LIST, LIST_LINE, CLEAR_FINISHED, ASK_OUTPUT, ANSWER_OUTPUT, REMOVEJOB, REMOVEJOB_OK, WAITJOB, WAIT_RUNNING_JOB, WAITJOB_OK, URGENT, URGENT_OK, GET_STATE, ANSWER_STATE, SWAP_JOBS, SWAP_JOBS_OK, INFO, INFO_DATA, SET_MAX_SLOTS, GET_MAX_SLOTS, GET_MAX_SLOTS_OK, GET_VERSION, VERSION, NEWJOB_NOK }; enum Request { c_QUEUE, c_TAIL, c_KILL_SERVER, c_LIST, c_CLEAR_FINISHED, c_SHOW_HELP, c_SHOW_VERSION, c_CAT, c_SHOW_OUTPUT_FILE, c_SHOW_PID, c_REMOVEJOB, c_WAITJOB, c_URGENT, c_GET_STATE, c_SWAP_JOBS, c_INFO, c_SET_MAX_SLOTS, c_GET_MAX_SLOTS }; struct Command_line { enum Request request; int need_server; int store_output; int stderr_apart; int should_go_background; int should_keep_finished; int send_output_by_mail; int gzip; int do_depend; int depend_on; /* -1 means depend on previous */ int max_slots; /* How many jobs to run at once */ int jobid; /* When queuing a job, main.c will fill it automatically from the server answer to NEWJOB */ int jobid2; int wait_enqueuing; struct { char **array; int num; } command; char *label; int num_slots; /* Slots for the job to use. Default 1 */ }; enum Process_type { CLIENT, SERVER }; extern struct Command_line command_line; extern int server_socket; extern enum Process_type process_type; extern int server_socket; /* Used in the client */ struct msg; enum Jobstate { QUEUED, RUNNING, FINISHED, SKIPPED, HOLDING_CLIENT }; struct msg { enum msg_types type; union { struct { int command_size; int store_output; int should_keep_finished; int label_size; int env_size; int do_depend; int depend_on; /* -1 means depend on previous */ int wait_enqueuing; int num_slots; } newjob; struct { int ofilename_size; int store_output; int pid; } output; int jobid; struct Result { int errorlevel; int died_by_signal; int signal; float user_ms; float system_ms; float real_ms; int skipped; } result; int size; enum Jobstate state; struct { int jobid1; int jobid2; } swap; int last_errorlevel; int max_slots; int version; } u; }; struct Procinfo { char *ptr; int nchars; int allocchars; struct timeval enqueue_time; struct timeval start_time; struct timeval end_time; }; struct Job { struct Job *next; int jobid; char *command; enum Jobstate state; struct Result result; /* Defined in msg.h */ char *output_filename; int store_output; int pid; int should_keep_finished; int do_depend; int depend_on; int *notify_errorlevel_to; int notify_errorlevel_to_size; int dependency_errorlevel; char *label; struct Procinfo info; int num_slots; }; enum ExitCodes { EXITCODE_OK = 0, EXITCODE_UNKNOWN_ERROR = -1, EXITCODE_QUEUE_FULL = 2 }; /* client.c */ void c_new_job(); void c_list_jobs(); void c_shutdown_server(); void c_wait_server_lines(); void c_clear_finished(); int c_wait_server_commands(); void c_send_runjob_ok(const char *ofname, int pid); int c_tail(); int c_cat(); void c_show_output_file(); void c_remove_job(); void c_show_pid(); int c_wait_job(); int c_wait_running_job(); int c_wait_job_recv(); void c_move_urgent(); int c_wait_newjob_ok(); void c_get_state(); void c_swap_jobs(); void c_show_info(); char *build_command_string(); void c_send_max_slots(int max_slots); void c_get_max_slots(); void c_check_version(); /* jobs.c */ void s_list(int s); int s_newjob(int s, struct msg *m); void s_removejob(int jobid); void job_finished(const struct Result *result, int jobid); int next_run_job(); void s_mark_job_running(int jobid); void s_clear_finished(); void s_process_runjob_ok(int jobid, char *oname, int pid); void s_send_output(int socket, int jobid); int s_remove_job(int s, int *jobid); void s_remove_notification(int s); void check_notify_list(int jobid); void s_wait_job(int s, int jobid); void s_wait_running_job(int s, int jobid); void s_move_urgent(int s, int jobid); void s_send_state(int s, int jobid); void s_swap_jobs(int s, int jobid1, int jobid2); void dump_jobs_struct(FILE *out); void dump_notifies_struct(FILE *out); void joblist_dump(int fd); const char * jstate2string(enum Jobstate s); void s_job_info(int s, int jobid); void s_send_runjob(int s, int jobid); void s_set_max_slots(int new_max_slots); void s_get_max_slots(int s); int job_is_running(int jobid); int job_is_holding_client(int jobid); int wake_hold_client(); /* server.c */ void server_main(int notify_fd, char *_path); void dump_conns_struct(FILE *out); /* server_start.c */ int try_connect(int s); void wait_server_up(); int ensure_server_up(); void notify_parent(int fd); void create_socket_path(char **path); /* execute.c */ int run_job(); /* client_run.c */ void c_run_tail(const char *filename); void c_run_cat(const char *filename); /* mail.c */ void send_mail(int jobid, int errorlevel, const char *ofname, const char *command); void hook_on_finish(int jobid, int errorlevel, const char *ofname, const char *command); /* error.c */ void error(const char *str, ...); void warning(const char *str, ...); /* signals.c */ void ignore_sigpipe(); void restore_sigmask(); void block_sigint(); void unblock_sigint_and_install_handler(); /* msg.c */ void send_bytes(const int fd, const char *data, int bytes); int recv_bytes(const int fd, char *data, int bytes); void send_msg(const int fd, const struct msg *m); int recv_msg(const int fd, struct msg *m); /* msgdump.c */ void msgdump(FILE *, const struct msg *m); /* error.c */ void error_msg(const struct msg *m, const char *str, ...); void warning_msg(const struct msg *m, const char *str, ...); /* list.c */ char * joblist_headers(); char * joblist_line(const struct Job *p); char * joblistdump_torun(const struct Job *p); char * joblistdump_headers(); /* print.c */ int fd_nprintf(int fd, int maxsize, const char *fmt, ...); /* info.c */ void pinfo_dump(const struct Procinfo *p, int fd); void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...); void pinfo_free(struct Procinfo *p); int pinfo_size(const struct Procinfo *p); void pinfo_set_enqueue_time(struct Procinfo *p); void pinfo_set_start_time(struct Procinfo *p); void pinfo_set_end_time(struct Procinfo *p); float pinfo_time_until_now(const struct Procinfo *p); float pinfo_time_run(const struct Procinfo *p); void pinfo_init(struct Procinfo *p); /* env.c */ char * get_environment(); /* tail.c */ int tail_file(const char *fname, int last_lines); ts-0.7.5/makedeb0000755000000000000000000000051012476424652011625 0ustar 00000000000000#!/bin/sh # This should create a debian package. First try. Never done before! version=0.5.4 make install PREFIX=deb/usr cd deb # data.tar.gz tar c --owner root --group root -v -z -f pkg/data.tar.gz usr # control.tar.gz find usr/ -type f | xargs md5sum > pkg/DEBIAN/md5sums dpkg -b pkg mv pkg.deb ts_${version}_i386.deb ts-0.7.5/msg.c0000644000000000000000000000347012476424652011251 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include "main.h" void send_bytes(const int fd, const char *data, int bytes) { int res; int offset = 0; while(1) { res = send(fd, data + offset, bytes, 0); if(res == -1) { warning("Sending %i bytes to %i.", bytes, fd); break; } if(res == bytes) break; offset += res; bytes -= res; } } int recv_bytes(const int fd, char *data, int bytes) { int res; int offset = 0; while(1) { res = recv(fd, data + offset, bytes, 0); if(res == -1) { warning("Receiving %i bytes from %i.", bytes, fd); break; } if(res == bytes) break; offset += res; bytes -= res; } return res; } void send_msg(const int fd, const struct msg *m) { int res; if (0) msgdump(stderr, m); res = send(fd, m, sizeof(*m), 0); if(res == -1 || res != sizeof(*m)) warning_msg(m, "Sending a message to %i, sent %i bytes, should " "send %i.", fd, res, sizeof(*m)); } int recv_msg(const int fd, struct msg *m) { int res; res = recv(fd, m, sizeof(*m), 0); if(res == -1) warning_msg(m, "Receiving a message from %i.", fd); if (res == sizeof(*m) && 0) msgdump(stderr, m); if (res != sizeof(*m) && res > 0) warning_msg(m, "Receiving a message from %i, received %i bytes, " "should have received %i.", fd, res, sizeof(*m)); return res; } ts-0.7.5/msgdump.c0000644000000000000000000000327412476424652012141 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include "main.h" void msgdump(FILE *f, const struct msg *m) { fprintf(f, "msgdump:\n"); switch(m->type) { case KILL_SERVER: fprintf(f, " KILL SERVER\n"); break; case NEWJOB: fprintf(f, " NEWJOB\n"); fprintf(f, " Commandsize: %i\n", m->u.newjob.command_size); break; case NEWJOB_OK: fprintf(f, " NEWJOB_OK\n"); fprintf(f, " JobID: '%i'\n", m->u.jobid); break; case RUNJOB: fprintf(f, " RUNJOB\n"); break; case RUNJOB_OK: fprintf(f, " RUNJOB_OK\n"); fprintf(f, " Outputsize: %i\n", m->u.output.ofilename_size); fprintf(f, " pid: %i\n", m->u.output.pid); break; case ENDJOB: fprintf(f, " ENDJOB\n"); break; case LIST: fprintf(f, " LIST\n"); break; case LIST_LINE: fprintf(f, " LIST_LINE\n"); fprintf(f, " Linesize: %i\n", m->u.size); break; case ASK_OUTPUT: fprintf(f, " ASK_OUTPUT\n"); fprintf(f, " Jobid: %i\n", m->u.jobid); break; case ANSWER_OUTPUT: fprintf(f, " ANSWER_OUTPUT\n"); fprintf(f, " Outputsize: %i\n", m->u.output.ofilename_size); fprintf(f, " PID: %i\n", m->u.output.pid); break; default: fprintf(f, " Unknown message: %i\n", m->type); } } ts-0.7.5/mymail.sh0000755000000000000000000000003612476424652012141 0ustar 00000000000000#!/bin/bash cat > prova.mail ts-0.7.5/print.c0000644000000000000000000000200712476424652011612 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include "main.h" /* maxsize: max buffer size, with '\0' */ int fd_nprintf(int fd, int maxsize, const char *fmt, ...) { va_list ap; char *out; int size; int rest; va_start(ap, fmt); out = (char *) malloc(maxsize * sizeof(char)); if (out == 0) { warning("Not enough memory in fd_nprintf()"); return -1; } size = vsnprintf(out, maxsize, fmt, ap); rest = size; /* We don't want the last null character */ while (rest > 0) { int res; res = write(fd, out, rest); if (res == -1) { warning("Cannot write more chars in pinfo_dump"); break; } rest -= res; } free(out); return size; } ts-0.7.5/server.c0000644000000000000000000003315012476424652011767 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2013 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #ifdef linux #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "main.h" enum { MAXCONN=1000 }; enum Break { BREAK, NOBREAK, CLOSE }; /* Prototypes */ static void server_loop(int ls); static enum Break client_read(int index); static void end_server(int ls); static void s_newjob_ok(int index); static void s_newjob_nok(int index); static void s_runjob(int jobid, int index); static void clean_after_client_disappeared(int socket, int index); struct Client_conn { int socket; int hasjob; int jobid; }; /* Globals */ static struct Client_conn client_cs[MAXCONN]; static int nconnections; static char *path; static int max_descriptors; /* in jobs.c */ extern int max_jobs; static void s_send_version(int s) { struct msg m; m.type = VERSION; m.u.version = PROTOCOL_VERSION; send_msg(s, &m); } static void sigterm_handler(int n) { const char *dumpfilename; int fd; /* Dump the job list if we should to */ dumpfilename = getenv("TS_SAVELIST"); if (dumpfilename != NULL) { fd = open(dumpfilename, O_WRONLY | O_APPEND | O_CREAT, 0600); if (fd != -1) { joblist_dump(fd); close(fd); } else warning("The TS_SAVELIST file \"%s\" cannot be opened", dumpfilename); } /* path will be initialized for sure, before installing the handler */ unlink(path); exit(1); } static void set_default_maxslots() { char *str; str = getenv("TS_SLOTS"); if (str != NULL) { int slots; slots = abs(atoi(str)); s_set_max_slots(slots); } } static void install_sigterm_handler() { struct sigaction act; act.sa_handler = sigterm_handler; /* Reset the mask */ memset(&act.sa_mask,0,sizeof(act.sa_mask)); act.sa_flags = 0; sigaction(SIGTERM, &act, NULL); } static int get_max_descriptors() { const int MARGIN = 5; /* stdin, stderr, listen socket, and whatever */ int max; struct rlimit rlim; int res; const char *str; max = MAXCONN; str = getenv("TS_MAXCONN"); if (str != NULL) { int user_maxconn; user_maxconn = abs(atoi(str)); if (max > user_maxconn) max = user_maxconn; } if (max > FD_SETSIZE) max = FD_SETSIZE - MARGIN; /* I'd like to use OPEN_MAX or NR_OPEN, but I don't know if any * of them is POSIX compliant */ res = getrlimit(RLIMIT_NOFILE, &rlim); if (res != 0) warning("getrlimit for open files"); else { if (max > rlim.rlim_cur) max = rlim.rlim_cur - MARGIN; } if (max < 1) error("Too few opened descriptors available"); return max; } void server_main(int notify_fd, char *_path) { int ls; struct sockaddr_un addr; int res; char *dirpath; process_type = SERVER; max_descriptors = get_max_descriptors(); /* Arbitrary limit, that will block the enqueuing, but should allow space * for usual ts queries */ max_jobs = max_descriptors - 5; path = _path; /* Move the server to the socket directory */ dirpath = malloc(strlen(path)+1); strcpy(dirpath, path); chdir(dirname(dirpath)); free(dirpath); nconnections = 0; ls = socket(AF_UNIX, SOCK_STREAM, 0); if(ls == -1) error("cannot create the listen socket in the server"); addr.sun_family = AF_UNIX; strcpy(addr.sun_path, path); res = bind(ls, (struct sockaddr *) &addr, sizeof(addr)); if (res == -1) error("Error binding."); res = listen(ls, 0); if (res == -1) error("Error listening."); install_sigterm_handler(); set_default_maxslots(); notify_parent(notify_fd); server_loop(ls); } static int get_conn_of_jobid(int jobid) { int i; for(i=0; i< nconnections; ++i) if (client_cs[i].hasjob && client_cs[i].jobid == jobid) return i; return -1; } static void server_loop(int ls) { fd_set readset; int i; int maxfd; int keep_loop = 1; int newjob; while (keep_loop) { FD_ZERO(&readset); maxfd = 0; /* If we can accept more connections, go on. * Otherwise, the system block them (no accept will be done). */ if (nconnections < max_descriptors) { FD_SET(ls,&readset); maxfd = ls; } for(i=0; i< nconnections; ++i) { FD_SET(client_cs[i].socket, &readset); if (client_cs[i].socket > maxfd) maxfd = client_cs[i].socket; } select(maxfd + 1, &readset, NULL, NULL, NULL); if (FD_ISSET(ls,&readset)) { int cs; cs = accept(ls, NULL, NULL); if (cs == -1) error("Accepting from %i", ls); client_cs[nconnections].hasjob = 0; client_cs[nconnections].socket = cs; ++nconnections; } for(i=0; i< nconnections; ++i) if (FD_ISSET(client_cs[i].socket, &readset)) { enum Break b; b = client_read(i); /* Check if we should break */ if (b == CLOSE) { warning("Closing"); /* On unknown message, we close the client, or it may hang waiting for an answer */ clean_after_client_disappeared(client_cs[i].socket, i); } else if (b == BREAK) keep_loop = 0; } /* This will return firstjob->jobid or -1 */ newjob = next_run_job(); if (newjob != -1) { int conn, awaken_job; conn = get_conn_of_jobid(newjob); /* This next marks the firstjob state to RUNNING */ s_mark_job_running(newjob); s_runjob(newjob, conn); while ((awaken_job = wake_hold_client()) != -1) { int wake_conn = get_conn_of_jobid(awaken_job); if (wake_conn == -1) error("The job awaken does not have a connection open"); s_newjob_ok(wake_conn); } } } end_server(ls); } static void end_server(int ls) { close(ls); unlink(path); /* This comes from the parent, in the fork after server_main. * This is the last use of path in this process.*/ free(path); } static void remove_connection(int index) { int i; if(client_cs[index].hasjob) { s_removejob(client_cs[index].jobid); } for(i=index; i<(nconnections-1); ++i) { memcpy(&client_cs[i], &client_cs[i+1], sizeof(client_cs[0])); } nconnections--; } static void clean_after_client_disappeared(int socket, int index) { /* Act as if the job ended. */ int jobid = client_cs[index].jobid; if (client_cs[index].hasjob) { struct Result r; r.errorlevel = -1; r.died_by_signal = 1; r.signal = SIGKILL; r.user_ms = 0; r.system_ms = 0; r.real_ms = 0; r.skipped = 0; warning("JobID %i quit while running.", jobid); job_finished(&r, jobid); /* For the dependencies */ check_notify_list(jobid); /* We don't want this connection to do anything * more related to the jobid, secially on remove_connection * when we receive the EOC. */ client_cs[index].hasjob = 0; } else /* If it doesn't have a running job, * it may well be a notification */ s_remove_notification(socket); close(socket); remove_connection(index); } static enum Break client_read(int index) { struct msg m; int s; int res; s = client_cs[index].socket; /* Read the message */ res = recv_msg(s, &m); if (res == -1) { warning("client recv failed"); clean_after_client_disappeared(s, index); return NOBREAK; } else if (res == 0) { clean_after_client_disappeared(s, index); return NOBREAK; } /* Process message */ switch(m.type) { case KILL_SERVER: return BREAK; /* break in the parent*/ break; case NEWJOB: client_cs[index].jobid = s_newjob(s, &m); client_cs[index].hasjob = 1; if (!job_is_holding_client(client_cs[index].jobid)) s_newjob_ok(index); else if (!m.u.newjob.wait_enqueuing) { s_newjob_nok(index); clean_after_client_disappeared(s, index); } break; case RUNJOB_OK: { char *buffer = 0; if (m.u.output.store_output) { /* Receive the output filename */ buffer = (char *) malloc(m.u.output.ofilename_size); res = recv_bytes(s, buffer, m.u.output.ofilename_size); if (res != m.u.output.ofilename_size) error("Reading the ofilename"); } s_process_runjob_ok(client_cs[index].jobid, buffer, m.u.output.pid); } break; case LIST: s_list(s); /* We must actively close, meaning End of Lines */ close(s); remove_connection(index); break; case INFO: s_job_info(s, m.u.jobid); close(s); remove_connection(index); break; case ENDJOB: job_finished(&m.u.result, client_cs[index].jobid); /* For the dependencies */ check_notify_list(client_cs[index].jobid); /* We don't want this connection to do anything * more related to the jobid, secially on remove_connection * when we receive the EOC. */ client_cs[index].hasjob = 0; break; case CLEAR_FINISHED: s_clear_finished(); break; case ASK_OUTPUT: s_send_output(s, m.u.jobid); break; case REMOVEJOB: { int went_ok; /* Will update the jobid. If it's -1, will set the jobid found */ went_ok = s_remove_job(s, &m.u.jobid); if (went_ok) { int i; for(i = 0; i < nconnections; ++i) { if (client_cs[i].hasjob && client_cs[i].jobid == m.u.jobid) { close(client_cs[i].socket); /* So remove_connection doesn't call s_removejob again */ client_cs[i].hasjob = 0; /* We don't try to remove any notification related to * 'i', because it will be for sure a ts client for a job */ remove_connection(i); } } } } break; case WAITJOB: s_wait_job(s, m.u.jobid); break; case WAIT_RUNNING_JOB: s_wait_running_job(s, m.u.jobid); break; case URGENT: s_move_urgent(s, m.u.jobid); break; case SET_MAX_SLOTS: s_set_max_slots(m.u.max_slots); break; case GET_MAX_SLOTS: s_get_max_slots(s); break; case SWAP_JOBS: s_swap_jobs(s, m.u.swap.jobid1, m.u.swap.jobid2); break; case GET_STATE: s_send_state(s, m.u.jobid); break; case GET_VERSION: s_send_version(s); break; default: /* Command not supported */ /* On unknown message, we close the client, or it may hang waiting for an answer */ warning("Unknown message: %i", m.type); return CLOSE; } return NOBREAK; /* normal */ } static void s_runjob(int jobid, int index) { int s; if (!client_cs[index].hasjob) error("Run job of the client %i which doesn't have any job", index); s = client_cs[index].socket; s_send_runjob(s, jobid); } static void s_newjob_ok(int index) { int s; struct msg m; if (!client_cs[index].hasjob) error("Run job of the client %i which doesn't have any job", index); s = client_cs[index].socket; m.type = NEWJOB_OK; m.u.jobid = client_cs[index].jobid; send_msg(s, &m); } static void s_newjob_nok(int index) { int s; struct msg m; if (!client_cs[index].hasjob) error("Run job of the client %i which doesn't have any job", index); s = client_cs[index].socket; m.type = NEWJOB_NOK; send_msg(s, &m); } static void dump_conn_struct(FILE *out, const struct Client_conn *p) { fprintf(out, " new_conn\n"); fprintf(out, " socket %i\n", p->socket); fprintf(out, " hasjob \"%i\"\n", p->hasjob); fprintf(out, " jobid %i\n", p->jobid); } void dump_conns_struct(FILE *out) { int i; fprintf(out, "New_conns"); for(i=0; i < nconnections; ++i) { dump_conn_struct(out, &client_cs[i]); } } ts-0.7.5/server_start.c0000644000000000000000000000767312476424652013217 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include #include #include #include #include "main.h" extern int server_socket; static char *socket_path; static int should_check_owner = 0; static int fork_server(); void create_socket_path(char **path) { char *tmpdir; char userid[20]; int size; /* As a priority, TS_SOCKET mandates over the path creation */ *path = getenv("TS_SOCKET"); if (*path != 0) { /* We need this in our memory, for forks and future 'free'. */ size = strlen(*path) + 1; *path = (char *) malloc(size); strcpy(*path, getenv("TS_SOCKET")); /* We don't want to check ownership of the socket here, * as the user may have thought of some shared queue */ should_check_owner = 0; return; } /* ... if the $TS_SOCKET doesn't exist ... */ /* Create the path */ tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) tmpdir = "/tmp"; sprintf(userid, "%u", (unsigned int) getuid()); /* Calculate the size */ size = strlen(tmpdir) + strlen("/socket-ts.") + strlen(userid) + 1; /* Freed after preparing the socket address */ *path = (char *) malloc(size); sprintf(*path, "%s/socket-ts.%s", tmpdir, userid); should_check_owner = 1; } int try_connect(int s) { struct sockaddr_un addr; int res; addr.sun_family = AF_UNIX; strcpy(addr.sun_path, socket_path); res = connect(s, (struct sockaddr *) &addr, sizeof(addr)); return res; } static void try_check_ownership() { int res; struct stat socketstat; if (!should_check_owner) return; res = stat(socket_path, &socketstat); if (res != 0) error("Cannot state the socket %s.", socket_path); if (socketstat.st_uid != getuid()) error("The uid %i does not own the socket %s.", getuid(), socket_path); } void wait_server_up(int fd) { char a; read(fd, &a, 1); close(fd); } /* Returns the fd where to wait for the parent notification */ static int fork_server() { int pid; int p[2]; /* !!! stdin/stdout */ pipe(p); pid = fork(); switch (pid) { case 0: /* Child */ close(p[0]); close(server_socket); /* Close all std handles for the server */ close(0); close(1); close(2); setsid(); server_main(p[1], socket_path); exit(0); break; case -1: /* Error */ return -1; default: /* Parent */ close(p[1]); } /* Return the read fd */ return p[0]; } void notify_parent(int fd) { char a = 'a'; write(fd, &a, 1); close(fd); } int ensure_server_up() { int res; int notify_fd; server_socket = socket(AF_UNIX, SOCK_STREAM, 0); if (server_socket == -1) error("getting the server socket"); create_socket_path(&socket_path); res = try_connect(server_socket); /* Good connection */ if (res == 0) { try_check_ownership(); return 1; } /* If error other than "No one listens on the other end"... */ if (!(errno == ENOENT || errno == ECONNREFUSED)) error("c: cannot connect to the server"); if (errno == ECONNREFUSED) unlink(socket_path); /* Try starting the server */ notify_fd = fork_server(); wait_server_up(notify_fd); res = try_connect(server_socket); /* The second time didn't work. Abort. */ if (res == -1) { fprintf(stderr, "The server didn't come up.\n"); exit(-1); } free(socket_path); /* Good connection on the second time */ return 1; } ts-0.7.5/setenv0000644000000000000000000000004412476424652011540 0ustar 00000000000000export BUG_PROJECT=$PWD/buglist.bug ts-0.7.5/signals.c0000644000000000000000000000306212476424652012120 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include /* for NULL */ #include /* for NULL */ #include "main.h" /* Some externs refer to this variable */ static sigset_t normal_sigmask; /* as extern in execute.c */ int signals_child_pid; /* 0, not set. otherwise, set. */ void ignore_sigpipe() { sigset_t set; sigemptyset(&set); sigaddset(&set, SIGPIPE); sigprocmask(SIG_BLOCK, &set, &normal_sigmask); } void restore_sigmask() { sigprocmask(SIG_SETMASK, &normal_sigmask, NULL); } void sigint_handler(int s) { if (signals_child_pid) { kill(signals_child_pid, SIGINT); } else { /* ts client killed by SIGINT */ exit(1); } } void block_sigint() { sigset_t set; sigemptyset(&set); sigaddset(&set, SIGINT); /* ignore_sigpipe() will always be called first, and * only that sets the normal_sigmask. */ sigprocmask(SIG_BLOCK, &set, 0); } void unblock_sigint_and_install_handler() { sigset_t set; struct sigaction act; /* Install the handler */ act.sa_handler = sigint_handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGINT, &act, 0); /* Unblock the signal */ sigemptyset(&set); sigaddset(&set, SIGINT); /* ignore_sigpipe() will always be called first, and * only that sets the normal_sigmask. */ sigprocmask(SIG_UNBLOCK, &set, 0); } ts-0.7.5/tail.c0000644000000000000000000001153012476424652011410 0ustar 00000000000000/* Task Spooler - a task queue system for the unix user Copyright (C) 2007-2009 Lluís Batlle i Rossell Please find the license in the provided COPYING file. */ #include #include #include #include #include #include #include #include #include #include /* Dep de main.h */ #include "main.h" enum { BSIZE=1024 }; static int min(int a, int b) { if (a < b) return a; return b; } static int max(int a, int b) { if (a > b) return a; return b; } static void tail_error(const char *str) { fprintf(stderr, "%s", str); fprintf(stderr, ". errno: %i (%s)\n", errno, strerror(errno)); exit(-1); } static void seek_at_last_lines(int fd, int lines) { char buf[BSIZE]; int lines_found = 0; int last_lseek = BSIZE; int last_read = 0; /* Only to catch not doing any loop */ int move_offset; int i = -1; /* Only to catch not doing any loop */ last_lseek = lseek(fd, 0, SEEK_END); do { int next_read; next_read = min(last_lseek, BSIZE); /* we should end looping if last_lseek == 0 * This means we already read all the file. */ if (next_read <= 0) break; /* last_lseek will be -1 at the beginning of the file, * if we wanted to go farer than it. */ last_lseek = lseek(fd, -next_read, SEEK_CUR); if (last_lseek == -1) last_lseek = lseek(fd, 0, SEEK_SET); last_read = read(fd, buf, next_read); if (last_read == -1) { if (errno == EINTR) continue; tail_error("Error reading"); } for(i = last_read-1; i >= 0; --i) { if (buf[i] == '\n') { ++lines_found; if (lines_found > lines) /* We will use 'i' to calculate where to * put the file cursor, before return. */ break; } } /* Go back the read bytes */ last_lseek = lseek(fd, -last_read, SEEK_CUR); } while(lines_found < lines); /* Calculate the position */ move_offset = i+1; lseek(fd, move_offset, SEEK_CUR); } static void set_non_blocking(int fd) { long arg; arg = O_RDONLY | O_NONBLOCK; fcntl(fd, F_SETFL, arg); } /* if last_lines == -1, go on from the start of the file */ int tail_file(const char *fname, int last_lines) { int fd; int res; int waiting_end = 1; int end_res = 0; int endfile_reached = 0; int could_write = 1; fd_set readset, errorset; fd = open(fname, O_RDONLY); if (fd == -1) tail_error("Error: cannot open the output file"); if (last_lines >= 0) seek_at_last_lines(fd, last_lines); /* we don't want the next read calls to block. */ set_non_blocking(fd); do { char buf[BSIZE]; int maxfd; FD_ZERO(&readset); maxfd = -1; if (!endfile_reached) { FD_SET(fd, &readset); maxfd = fd; } if (waiting_end) { FD_SET(server_socket, &readset); maxfd = max(maxfd, server_socket); } FD_ZERO(&errorset); FD_SET(1, &errorset); maxfd = max(maxfd, server_socket); /* If we don't have fd's to wait for, let's sleep */ if (maxfd == -1) { usleep(1 /* sec */* 1000000); } else { /* Otherwise, do a normal select */ struct timeval tv = {1 /*sec*/, 0 }; res = select(maxfd + 1, &readset, 0, &errorset, &tv); } if (FD_ISSET(server_socket, &readset)) { end_res = c_wait_job_recv(); waiting_end = 0; } /* We always read when select awakes */ res = read(fd, buf, BSIZE); if (res == -1) { if (errno == EINTR || errno == EAGAIN) { res = 1; /* Hack for the while condition */ continue; } tail_error("Error reading"); } if (res == 0) endfile_reached = 1; else endfile_reached = 0; if (!FD_ISSET(1, &errorset)) { while(res > 0) { int wres; wres = write(1, buf, res); /* Maybe the listener doesn't want to receive more */ if (wres < 0) { could_write = 0; break; } res -= wres; } } else { could_write = 0; break; } } while((!endfile_reached || waiting_end) && could_write); close(fd); return end_res; } ts-0.7.5/testbench.sh0000755000000000000000000000416512476424652012637 0ustar 00000000000000#!/bin/bash # Some simple tasks ./ts -K ./ts ls ./ts -n ls > /dev/null ./ts -f ls ./ts -nf ls > /dev/null ./ts ls ./ts cat ./ts -w LINES=`./ts -l | grep finished | wc -l` if [ $LINES -ne 5 ]; then echo "Error in simple tasks." exit 1 fi ./ts -K # Check errorlevel 1 ./ts -f ls if [ $? -ne 0 ]; then echo "Error in errorlevel 1." exit 1 fi # Check errorlevel 2 ./ts -f patata if [ $? -eq 0 ]; then echo "Error in errorlevel 2." exit 1 fi # Check errorlevel 3 ./ts patata if [ $? -ne 0 ]; then echo "Error in errorlevel 3." exit 1 fi # Check errorlevel 4 ./ts ls ./ts -w if [ $? -ne 0 ]; then echo "Error in errorlevel 4." exit 1 fi # Check errorlevel 5 ./ts patata ./ts -w if [ $? -eq 0 ]; then echo "Error in errorlevel 5." exit 1 fi ./ts -K # Check urgency ./ts sleep 1 ./ts ls ./ts patata ./ts -w if [ $? -eq 0 ]; then echo "Error in urgency 1." exit 1 fi ./ts sleep 1 ./ts ls ./ts patata ./ts -u ./ts -w if [ $? -ne 0 ]; then echo "Error in urgency 2." exit 1 fi ./ts -K ./ts sleep 1 ./ts ls ./ts patata ./ts -u 2 ./ts -w if [ $? -ne 0 ]; then echo "Error in urgency 3." exit 1 fi # Test remove job ./ts -K ./ts sleep 1 && ./ts ls 1 && ./ts ls 2 && ./ts -r 1 && ./ts -r && ./ts sleep 1 && ./ts -n ls > /dev/null && ./ts -n ls 2 > /dev/null && ./ts -r && ./ts -w if [ $? -ne 0 ]; then echo "Error in remove job." exit 1 fi ./ts -K # Test not adding the job to finished. ./ts ls ./ts -w LINES=`./ts -l | grep finished | wc -l` if [ $LINES -ne 1 ]; then echo "Error in not adding the job to finished." exit 1 fi ./ts -nf ls > /dev/null LINES=`./ts -l | grep finished | wc -l` if [ $LINES -ne 1 ]; then echo "Error in not adding the job to finished." exit 1 fi ./ts -K # Test clearing the finished jobs ./ts ls ./ts ls ./ts ls ./ts -nf ls > /dev/null ./ts -C LINES=`./ts -l | wc -l` if [ $LINES -ne 1 ]; then echo "Error clearing the finished jobs." exit 1 fi ./ts -K # Test clearing the finished jobs # We start the daemon ./ts > /dev/null J1=`./ts sleep 1` J2=`./ts sleep 2` J3=`./ts sleep 3` ./ts -U $J2-$J3 if [ $? -ne 0 ]; then echo "Error clearing the finished jobs." exit 1 fi ./ts -K ts-0.7.5/ts.10000644000000000000000000002362212476424652011030 0ustar 00000000000000.\" Copyright Lluís Batlle i Rossell .\" .\" This file may be copied under the conditions described .\" in the LDP GENERAL PUBLIC LICENSE, Version 1, September 1998 .\" that should have been distributed together with this file. .\" .\" Note: I took the gnu 'ls' man page as an example. .TH TS 1 2015-03 "Task Spooler 0.7.5" .SH NAME ts \- task spooler. A simple unix batch system .SH SYNOPSIS .BI "ts [" actions "] [" options "] [" command... ] .sp Actions: .BI "[\-KClhV] .BI "[\-t ["id ]] .BI "[\-c ["id ]] .BI "[\-p ["id ]] .BI "[\-o ["id ]] .BI "[\-s ["id ]] .BI "[\-r ["id ]] .BI "[\-w ["id ]] .BI "[\-u ["id ]] .BI "[\-i ["id ]] .BI "[\-U <"id - id >] .BI "[\-S ["num ]] .sp Options: .BI "[\-nfgmd]" .BI "[\-L <"label >] .BI "[\-D <"id >] .SH DESCRIPTION .B ts will run by default a per user unix task queue. The user can add commands to the queue, watch that queue at any moment, and look at the task results (actually, standard output and exit error). .SH SIMPLE USE Calling .B ts with a command will add that command to the queue, and calling it without commands or parameters will show the task list. .SH COMMAND OPTIONS When adding a job to ts, we can specify how it will be run and how will the results be collected: .TP .B "\-n" Do not store the standard output/error in a file at .B $TMPDIR - let it use the file descriptors decided by the calling process. If it is not used, the .B jobid for the new task will be outputed to stdout. .TP .B "\-g" Pass the output through gzip (only if .B \-n ). Note that the output files will not have a .gz extension. .TP .B "\-f" Don not put the task into background. Wait the queue and the command run without getting detached of the terminal. The exit code will be that of the command, and if used together with \-n, no result will be stored in the queue. .TP .B "\-m" Mail the results of the command (output and exit code) to .B $TS_MAILTO , or to the .B $USER using .B /usr/sbin/sendmail. Look at .B ENVIRONMENT. .TP .B "\-L