Re: [systemd-devel] Why do we must use the close_all_fds(3) function in some files?

2014-06-20 Thread Lennart Poettering
On Tue, 17.06.14 07:59, Geunsik Lim (geunsik@gmail.com) wrote:

 
 It seems that a goal of close_all_fds() is garbage collector to guarantee
 available file descriptors  for new fopen() system call.
 Nowadays, the modern computer system is multi-process/multi-thread scheme
 more than single-process/multi-thread.
 Does systemd have to care the number of open file size? Actually, Is this
 function need for safety net?

Yes, because 1024 is the default limit per process and that is very
small. Also, file descriptors are reference to resources, most
importantly files but also devices, file locks, and other objects. If we
keep them open, these resources stay busy, and possibly unavailable to
others.

 For example,
 invain@u1204lgs:/opt/git-systemd$ ulimit  -n
 1024
 
 If Systemd does not execute the close_all_fds() functions,
 What will be happened in real environment?

Depends on the system and what you do. It's just a matter of
cleanliness, and it's pretty much for free anyway as the thing basically
becomes a NOP if no fd is open.

 On the other hand, if systemd have to  not close more than two file
 descriptors(e.g. 5, 17, 19) for some case to release Linux distribution
 based on Systemd, can we use close_all_fds(except, ***)? In this case, Do
 we have to specify  withclose_all_fds(except, 3 + 19)?

I cannot parse this, sorry...

I am really not sure why you want to get rid of close_all_fds()?

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Why do we must use the close_all_fds(3) function in some files?

2014-06-16 Thread Geunsik Lim
Hi all,

Recently, i checked that there are  some of the close_all_fds functions
as follows
Why we Systemd run this functions? Whey this functions need Systemd's
management?

invain@u1204lgs:/sandbox/tizentvfolder/systemd$ grep -R close_all_fds ./*
./src/nspawn.c:close_all_fds(NULL, 0);
./src/util.c:int close_all_fds(const int except[], unsigned n_except) {
./src/util.c:close_all_fds(NULL, 0);
./src/main.c:close_all_fds(NULL, 0);
./src/spawn-agent.c:close_all_fds(NULL, 0);
./src/execute.c:err = close_all_fds(socket_fd = 0 ?
socket_fd : fds,
./src/execute.c:err = close_all_fds(fds, n_fds);
./src/util.h:int close_all_fds(const int except[], unsigned n_except);


Thanks reading.



Best regards,
Geunsik Lim, Samsung Electronics
http://leemgs.fedorapeople.org

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Why do we must use the close_all_fds(3) function in some files?

2014-06-16 Thread David Herrmann
Hi

On Mon, Jun 16, 2014 at 2:32 PM, Geunsik Lim geunsik@gmail.com wrote:
 Hi all,

 Recently, i checked that there are  some of the close_all_fds functions as
 follows
 Why we Systemd run this functions? Whey this functions need Systemd's
 management?

 invain@u1204lgs:/sandbox/tizentvfolder/systemd$ grep -R close_all_fds ./*
 ./src/nspawn.c:close_all_fds(NULL, 0);
 ./src/util.c:int close_all_fds(const int except[], unsigned n_except) {
 ./src/util.c:close_all_fds(NULL, 0);
 ./src/main.c:close_all_fds(NULL, 0);
 ./src/spawn-agent.c:close_all_fds(NULL, 0);
 ./src/execute.c:err = close_all_fds(socket_fd = 0 ?
 socket_fd : fds,
 ./src/execute.c:err = close_all_fds(fds, n_fds);
 ./src/util.h:int close_all_fds(const int except[], unsigned n_except);

I didn't look for all occurrences, but usually this function is a
safety net: We set O_CLOEXEC on all FDs, therefore, on execve() they
get closed. However, in case we missed this somewhere, close_all_fds()
destroys those FDs for us. Furthermore, it also destroys any global
fds (stdin/stdout/...) in case we don't want to leak them into our
child.

Thanks
David
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Why do we must use the close_all_fds(3) function in some files?

2014-06-16 Thread Lennart Poettering
On Mon, 16.06.14 14:44, David Herrmann (dh.herrm...@gmail.com) wrote:

 
 Hi
 
 On Mon, Jun 16, 2014 at 2:32 PM, Geunsik Lim geunsik@gmail.com wrote:
  Hi all,
 
  Recently, i checked that there are  some of the close_all_fds functions as
  follows
  Why we Systemd run this functions? Whey this functions need Systemd's
  management?
 
  invain@u1204lgs:/sandbox/tizentvfolder/systemd$ grep -R close_all_fds ./*
  ./src/nspawn.c:close_all_fds(NULL, 0);
  ./src/util.c:int close_all_fds(const int except[], unsigned n_except) {
  ./src/util.c:close_all_fds(NULL, 0);
  ./src/main.c:close_all_fds(NULL, 0);
  ./src/spawn-agent.c:close_all_fds(NULL, 0);
  ./src/execute.c:err = close_all_fds(socket_fd = 0 ?
  socket_fd : fds,
  ./src/execute.c:err = close_all_fds(fds, n_fds);
  ./src/util.h:int close_all_fds(const int except[], unsigned n_except);
 
 I didn't look for all occurrences, but usually this function is a
 safety net: We set O_CLOEXEC on all FDs, therefore, on execve() they
 get closed. However, in case we missed this somewhere, close_all_fds()
 destroys those FDs for us. Furthermore, it also destroys any global
 fds (stdin/stdout/...) in case we don't want to leak them into our
 child.

Actually the three stdio fds (0, 1, 2) are explicitly excluded from what
close_all_fds() does.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Why do we must use the close_all_fds(3) function in some files?

2014-06-16 Thread Lennart Poettering
On Mon, 16.06.14 21:32, Geunsik Lim (geunsik@gmail.com) wrote:

 Hi all,
 
 Recently, i checked that there are  some of the close_all_fds functions
 as follows
 Why we Systemd run this functions? Whey this functions need Systemd's
 management?
 
 invain@u1204lgs:/sandbox/tizentvfolder/systemd$ grep -R close_all_fds ./*
 ./src/nspawn.c:close_all_fds(NULL, 0);
 ./src/util.c:int close_all_fds(const int except[], unsigned n_except) {
 ./src/util.c:close_all_fds(NULL, 0);
 ./src/main.c:close_all_fds(NULL, 0);
 ./src/spawn-agent.c:close_all_fds(NULL, 0);
 ./src/execute.c:err = close_all_fds(socket_fd = 0 ?
 socket_fd : fds,
 ./src/execute.c:err = close_all_fds(fds, n_fds);
 ./src/util.h:int close_all_fds(const int except[], unsigned n_except);

David is right, this is really just a safety net, and particularly
useful when one of our tools is invoked from arbitrary code that might
not be written cleanly.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Why do we must use the close_all_fds(3) function in some files?

2014-06-16 Thread Geunsik Lim
On Tue, Jun 17, 2014 at 12:24 AM, Lennart Poettering lenn...@poettering.net
 wrote:

 On Mon, 16.06.14 21:32, Geunsik Lim (geunsik@gmail.com) wrote:

  Hi all,
 
  Recently, i checked that there are  some of the close_all_fds functions
  as follows
  Why we Systemd run this functions? Whey this functions need Systemd's
  management?
 
  invain@u1204lgs:/sandbox/tizentvfolder/systemd$ grep -R close_all_fds
 ./*
  ./src/nspawn.c:close_all_fds(NULL, 0);
  ./src/util.c:int close_all_fds(const int except[], unsigned n_except) {
  ./src/util.c:close_all_fds(NULL, 0);
  ./src/main.c:close_all_fds(NULL, 0);
  ./src/spawn-agent.c:close_all_fds(NULL, 0);
  ./src/execute.c:err = close_all_fds(socket_fd = 0 ?
  socket_fd : fds,
  ./src/execute.c:err = close_all_fds(fds, n_fds);
  ./src/util.h:int close_all_fds(const int except[], unsigned n_except);

 David is right, this is really just a safety net, and particularly
 useful when one of our tools is invoked from arbitrary code that might
 not be written cleanly.


It seems that a goal of close_all_fds() is garbage collector to guarantee
available file descriptors  for new fopen() system call.
Nowadays, the modern computer system is multi-process/multi-thread scheme
more than single-process/multi-thread.
Does systemd have to care the number of open file size? Actually, Is this
function need for safety net?
For example,
invain@u1204lgs:/opt/git-systemd$ ulimit  -n
1024

If Systemd does not execute the close_all_fds() functions,
What will be happened in real environment?

On the other hand, if systemd have to  not close more than two file
descriptors(e.g. 5, 17, 19) for some case to release Linux distribution
based on Systemd, can we use close_all_fds(except, ***)? In this case, Do
we have to specify  withclose_all_fds(except, 3 + 19)?

Thanks,



 Lennart

 --
 Lennart Poettering, Red Hat




-- 

Best regards,
Geunsik Lim, Samsung Electronics
http://leemgs.fedorapeople.org

To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel