JavaTCPFork/.git
8 years agoFrom sig handler just call safe functions. master origin/HEAD origin/master
Gustavo Martin Morcuende [Wed, 16 Dec 2015 00:26:10 +0000 (01:26 +0100)]
From sig handler just call safe functions.

As long as you don't do what R.. user says in the comments below the answer you must
use only safe functions.

http://stackoverflow.com/questions/8833394/can-exit-fail-to-terminate-process/8833602#8833602

8 years agodo not repeat close when EINTR
Gustavo Martin Morcuende [Tue, 25 Aug 2015 05:32:59 +0000 (07:32 +0200)]
do not repeat close when EINTR

See: Returning EINTR from close() - http://lwn.net/Articles/576478/
     Linus Torvalds - http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html

9 years agoComments about inherited signal dispositions.
Gustavo Martin Morcuende [Sun, 22 Jun 2014 11:59:37 +0000 (13:59 +0200)]
Comments about inherited signal dispositions.

10 years agofixed error in create_args function
gu.martinm@gmail.com [Mon, 17 Mar 2014 09:26:48 +0000 (10:26 +0100)]
fixed error in create_args function

10 years agofixed #1. Using execvp instead of system.
gu.martinm@gmail.com [Sun, 16 Mar 2014 23:20:46 +0000 (00:20 +0100)]
fixed #1. Using execvp instead of system.

10 years agoWorking on issues: #1 #3. issue1 origin/issue1
gu.martinm@gmail.com [Mon, 10 Mar 2014 02:52:03 +0000 (03:52 +0100)]
Working on issues: #1 #3.

No more shared memory, execv/execl solution.
UTF-8 always between client and server (avoiding issues with strtok)

10 years agoAvoid SIGPIPE and polite kill child process.
gu.martinm@gmail.com [Sun, 23 Feb 2014 16:25:12 +0000 (17:25 +0100)]
Avoid SIGPIPE and polite kill child process.

SIGPIPE when using send method and remote side closed connection.

Portable alternatives: sighandler for SIGPIPE or block/ignore SIGPIPE. In some situations we
may not ignore SIGPIPE (if we are writing some API we may not just swallow SIGPIPE) because of that
depending o the situation we could ignore or block SIGPIPE.
There is SIGPIPE JUST when using send/write (no with read/recv) and remote side closed connection.

10 years agoWait for client to close connection: improvement (I hope)
gu.martinm@gmail.com [Mon, 3 Feb 2014 23:54:46 +0000 (00:54 +0100)]
Wait for client to close connection: improvement (I hope)

10 years agoAvoid TIME_WAIT state, server side: wait for client to close connection.
gu.martinm@gmail.com [Sun, 2 Feb 2014 20:49:14 +0000 (21:49 +0100)]
Avoid TIME_WAIT state, server side: wait for client to close connection.

See:
http://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable
http://www.serverframework.com/asynchronousevents/2011/01/time-wait-and-its-design-implications-for-protocols-and-scalable-servers.html
http://stackoverflow.com/questions/3757289/tcp-option-so-linger-zero-when-its-required

By the way, never use SO_LINGER. The application level protocol should be implemented
in such way that allows the client side to find out when server side ended up sending
data and in this way the client is able to close the connectiond and server side does not
finish with sockets in TIME_WAIT state.

10 years agoI do not think daemonize function is needed.
gu.martinm@gmail.com [Sun, 17 Nov 2013 17:32:51 +0000 (18:32 +0100)]
I do not think daemonize function is needed.

Remove it once I get time and just use setsid function.

10 years agoDoubts about setsid. TODO some day.
Gustavo Martin Morcuende [Thu, 29 Aug 2013 00:51:49 +0000 (02:51 +0200)]
Doubts about setsid. TODO some day.

10 years agoHow to launch daemon (improvement)
Gustavo Martin Morcuende [Thu, 29 Aug 2013 00:49:18 +0000 (02:49 +0200)]
How to launch daemon (improvement)

11 years agoMultiple minor changes:
gumartinm [Sun, 20 Jan 2013 21:28:54 +0000 (22:28 +0100)]
Multiple minor changes:

1. Return -1 from main function as error code.
2. Close useless file descriptors in child process.
3. Improving some comments and error messages.
4. Errors from poll function.

11 years agoEXIT_SUCCESS & EXIT_FAILURE constants / _exit
gumartinm [Sun, 23 Dec 2012 19:15:17 +0000 (20:15 +0100)]
EXIT_SUCCESS & EXIT_FAILURE constants / _exit

About _exit: I do not think I really need to use _exit but anyway it seems to me like it does not hurt me so... Let's do it in the right way!!!

From: http://www.unixguide.net/unix/programming/1.1.3.shtml / http://stupefydeveloper.blogspot.com.es/2009/01/c-to-exit-or-to-exit.html

There are a few differences between exit() and _exit()
that become significant when fork(), and especially
vfork(), is used.

The basic difference between exit() and _exit() is that
the former performs clean-up related to user-mode constructs in the
library, and calls user-supplied cleanup functions, whereas the latter
performs only the kernel cleanup for the process.

In the child branch of a fork(), it is normally incorrect to use
exit(), because that can lead to stdio buffers being flushed
twice, and temporary files being unexpectedly removed. In C++ code the
situation is worse, because destructors for static objects may be run
incorrectly. (There are some unusual cases, like daemons, where the
parent should call _exit() rather than the child; the
basic rule, applicable in the overwhelming majority of cases, is that
exit() should be called only once for each entry into
main.)

In the child branch of a vfork(), the use of exit() is
even more dangerous, since it will affect the state of the parent
process.

11 years agoFixed error in sizeof for unsigned char.
gumartinm [Sun, 23 Dec 2012 18:48:37 +0000 (19:48 +0100)]
Fixed error in sizeof for unsigned char.

11 years agoRight type for storing return code from fork
gumartinm [Tue, 18 Dec 2012 05:30:04 +0000 (06:30 +0100)]
Right type for storing return code from fork

11 years agoUnblock SIGCHLD signal in child process.
gumartinm [Tue, 18 Dec 2012 05:25:48 +0000 (06:25 +0100)]
Unblock SIGCHLD signal in child process.

11 years agoExit from custom SIGINT handler. The right way.
gumartinm [Tue, 18 Dec 2012 04:50:42 +0000 (05:50 +0100)]
Exit from custom SIGINT handler. The right way.

As seen on: http://www.cons.org/cracauer/sigint.html

11 years agoBlocking SIGCHLD with pthread_sigmask
gumartinm [Tue, 18 Dec 2012 03:46:18 +0000 (04:46 +0100)]
Blocking SIGCHLD with pthread_sigmask

11 years agoImproving the set signal_handler code
gumartinm [Tue, 18 Dec 2012 01:40:45 +0000 (02:40 +0100)]
Improving the set signal_handler code

11 years agoUsing right type for data bytes:
gumartinm [Mon, 17 Dec 2012 20:29:33 +0000 (21:29 +0100)]
Using right type for data bytes:

* char:
It is the type that makes up C strings like "abcde"
It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through inequalities - although if you limit yourself to ASCII (0-127) you're just about safe.

* signed char:
Gives you at least the -128 to 127 range.

* unsigned char:
Gives you at least the 0 to 255 range.

There is this warning: pointer targets in passing argument 1 of â€˜system’ differ in signedness
I guess, it does not hurt me.

11 years agoCheck shell has not set up an initial action
gumartinm [Mon, 17 Dec 2012 19:33:22 +0000 (20:33 +0100)]
Check shell has not set up an initial action

12 years agoThe daemon process sends to the Java client in case of any error the value -1.
gumartinm [Sun, 18 Mar 2012 11:57:11 +0000 (12:57 +0100)]
The daemon process sends to the Java client in case of any error the value -1.
In this way, the Java client's code always will receive a return status from the daemon process
and just in case of any error it receives an error status.

12 years agoXML parser removed. We begin to use my own protocol.
gumartinm [Sun, 4 Mar 2012 20:45:23 +0000 (21:45 +0100)]
XML parser removed. We begin to use my own protocol.
Next step: Java NIO for the Java client code.

12 years agoComment with questions about packing, serializing and alginment
gumartinm [Sun, 26 Feb 2012 23:40:33 +0000 (00:40 +0100)]
Comment with questions about packing, serializing and alginment

12 years agoMore steps in my JavaTCPForkDaemon.
gumartinm [Sun, 26 Feb 2012 22:03:01 +0000 (23:03 +0100)]
More steps in my JavaTCPForkDaemon.
I must concatenate the protocold header and the payload.
Should I use writev?

12 years agoSome code improvements.
gumartinm [Mon, 6 Feb 2012 00:33:35 +0000 (01:33 +0100)]
Some code improvements.
First steps with the new way to send the stdout, stderr and return status code
to the client program. Thinking about a typedef struct, but I am wasting bytes
using this way. Is it worth wasting bytes?

12 years agoRemoving some useless white spaces....
gumartinm [Tue, 31 Jan 2012 06:17:45 +0000 (07:17 +0100)]
Removing some useless white spaces....
Sorry for this commit...

12 years agoNothing important,
gumartinm [Tue, 31 Jan 2012 05:47:23 +0000 (06:47 +0100)]
Nothing important,
just another english grammar mistake in javafor.c

12 years agoClening up code, and errors control.
gumartinm [Mon, 30 Jan 2012 22:47:56 +0000 (23:47 +0100)]
Clening up code, and errors control.
TODO: stop using XML, I am going to use my own protocol for
sending stdout, stderr and return status code in this way
I will avoid the shared memory and the code complexity.
Besides it should reduce the memory usage.
Next weekend more.

12 years agoNew nice method to read data from socket.
gumartinm [Sun, 29 Jan 2012 23:44:01 +0000 (00:44 +0100)]
New nice method to read data from socket.
Some useless comments just left to remind me what I am going to do the next week.
Just is left to improve the fork_system function (IMHO)

12 years agoSome minor changes in REAME files
gumartinm [Sun, 29 Jan 2012 16:07:40 +0000 (17:07 +0100)]
Some minor changes in REAME files

12 years agoGrammar mistake in README file :/
gumartinm [Sun, 29 Jan 2012 16:03:23 +0000 (17:03 +0100)]
Grammar mistake in README file :/

12 years agoRemoving executable file
gumartinm [Sun, 29 Jan 2012 16:01:27 +0000 (17:01 +0100)]
Removing executable file

12 years agofirst commit
gumartinm [Sun, 29 Jan 2012 16:00:44 +0000 (17:00 +0100)]
first commit