summaryrefslogtreecommitdiff
path: root/lib/daemon.c
Commit message (Collapse)AuthorAgeFilesLines
* bridge: allow OVS to interact with controller through sockets outside run dirAnsis Atteka2016-06-271-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently Open vSwitch is unable to create or connect to Unix Domain Sockets outside designated 'run' directory, because of fear of potential remote exploits where a hacked remote OVSDB manager would tell Open vSwitch to connect to a unix domain socket owned by other daemon on the same hypervisor. This patch allows to disable this behavior by changing /etc/default/openvswitch (Ubuntu) or /etc/sysconfig/openvswitch (RHEL) file to: ... OVS_CTL_OPTS=--no-self-confinement ... Note, that it is better to stick with default behavior, unless: 1. You have Open vSwitch running under SELinux or AppArmor that would prevent OVS from messing with sockets owned by other daemons; OR 2. You are sure that relying on OpenFlow handshake is enough to prevent OVS to adversely interact with those other daemons running on the same hypervisor; OR 3. You don't have much worries of remote exploits in the first place, because perhaps OVSDB manager is running on the same host as OVS. The initial use-case for this patch is to allow to connect to OpenFlow controller that has its socket outside OVS run directory. However, in the future it could be generalized to allow to disable self-confinement for other things like DPDK vhost-user sockets or anything else that is specifiable in OVSDB with full path. Signed-off-by: Ansis Atteka <aatteka@ovn.org> Acked-by: Jesse Gross <jesse@kernel.org> VMware-BZ: #1525857
* lib/daemon: support --user option for all OVS daemonAndy Zhou2015-09-301-1/+1
| | | | | | | | | | OVS daemons can now support --user option to run as a non-root user with less privileges. See the manpage patch for more descriptions. Signed-off-by: Andy Zhou <azhou@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib: Move vlog.h to <openvswitch/vlog.h>Thomas Graf2014-12-151-1/+3
| | | | | | | | A new function vlog_insert_module() is introduced to avoid using list_insert() from the vlog.h header. Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* daemon: Move some common code to daemon.cGurucharan Shetty2014-04-241-0/+31
| | | | | | | | We have some common code between daemon-unix.c and daemon-windows.c. Move them to daemon.c Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* daemon: Close standard file descriptors after detach for windows.Gurucharan Shetty2014-04-241-0/+89
| | | | | | | | | | | | | | In the unit tests, we check for some logs stored in stderr. In case of windows, unit tests fail because the child writes additional information into stderr because it does not have it closed. This commit closes standard file descriptors for windows too. Because the functions related to closing file descriptors is common for both windows and unix, add it to the common daemonization file daemon.c Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* daemon: Rename daemon.c as daemon-unix.cGurucharan Shetty2014-04-241-758/+0
| | | | | | | | An upcoming commit re-introduces daemon.c to have common functions across daemon-unix.c and daemon-windows.c Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* utils: Introduce xsleep for RCU quiescent statePravin2014-03-211-1/+1
| | | | | Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* socket-util: Move get_null_fd() to daemon.c.Gurucharan Shetty2014-02-211-0/+20
| | | | | | | | | | get_null_fd() is only called from daemon.c. It does not need thread safety features anymore as it is called either through daemonize_start() or indirectly through daemonize_complete() once. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* daemon-windows: Ability to handle windows service calls.Gurucharan Shetty2014-02-041-0/+19
| | | | | | | | | | | | | | | | | | | | | | | The following code does not add any users yet. The visioned workflow that this piece of code should work with is: * Create a windows service through a startup script with a tool like 'sc' ex: sc create ovsdb-server binpath= "C:\openvswitch\usr\sbin\ovsdb-server.exe -vconsole:off -vsyslog:off -vfile:info --remote=ptcp:6632:127.0.0.1 --log-file --service-monitor --service" * Start the service from the startup script. ex: sc start ovsdb-server * Terminate the service during shutdown process. ex: sc stop ovsdb-server * Abrupt termination will restart the service. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* daemon: Cleanup some functions.Gurucharan Shetty2014-01-241-39/+6
| | | | | | | | Some functions are unused and some functions can be declared as static. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* Rename NOT_REACHED to OVS_NOT_REACHEDHarold Lim2013-12-171-1/+1
| | | | | | | | This allows other libraries to use util.h that has already defined NOT_REACHED. Signed-off-by: Harold Lim <haroldl@vmware.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: Precisely document signals that cause the monitor to restart.Ben Pfaff2013-11-021-0/+2
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Joe Stringer <joestringer@nicira.com>
* timeval: Remove CACHE_TIME scheme.Alex Wang2013-09-041-1/+0
| | | | | | | | | | | | | | This commit removes the CACHE_TIME scheme from timeval module. This is for eliminating the lock contention over the read/write lock of the cached time. To get the time, the thread now will directly do the system call 'clock_gettime()'. As a side effect, timer can only be warpped after timer is stopped by 'appctl time/stop' command. Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* worker: Delete library.Ben Pfaff2013-07-121-0/+2
| | | | | | It had no remaining users. Signed-off-by: Ben Pfaff <blp@nicira.com>
* util: Make subprogram_name thread-specific.Ben Pfaff2013-07-121-2/+2
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* Replace all uses of strerror() by ovs_strerror(), for thread safety.Ben Pfaff2013-06-281-15/+16
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* ovs-thread: Add support for various thread-related assertions.Ben Pfaff2013-06-281-7/+5
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* worker: Prevent worker from being responsible for pidfile deletion.Gurucharan Shetty2013-04-291-2/+25
| | | | | | | | | | | | | | | | | | | Currently we are creating the worker process after creation of the pidfile. This means that the responsibility of deleting the pidfile after process termination rests with the worker process. When we restart openvswitch using the startup scripts, we SIGTERM the main process and once it is cleaned up, we start ovs-vswitchd again. This results in a race condition. The new ovs-vswitchd will create a pidfile because it is unlocked. But, if the old worker process exits after the start of new ovs-vswitchd, it will simply delete the pidfile underneath the new ovs-vswitchd. This will eventually result in multiple ovs-vswitchd daemons. This patch gives the responsibility of deleting the pidfile to the main process. Bug #16669. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
* Replace most uses of assert by ovs_assert.Ben Pfaff2013-01-161-2/+3
| | | | | | | | This is a straight search-and-replace, except that I also removed #include <assert.h> from each file where there were no assert calls left. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* daemon: Start monitor process, not daemon process, in new session.Ben Pfaff2012-12-131-1/+2
| | | | | | | | | | | | | | | | | | | | | | To keep control+C and other signals in the initiating session from killing the monitor process, we need to put the monitor process into its own session. However, until this point, we've only done that for the daemon processes that the monitor started, which means that control+C would kill the monitor but not the daemons that it launched. I don't know of a benefit to putting the monitor and daemon processes in different sessions, as opposed to one new session for both of them, so this change does the latter. daemonize_post_detach() is called from one additional context where we'd want to be in a new session, the worker_start() function, but that function is documented as to be called after daemonize_start(), in which case we will (after this commit) already have called setsid(), so no additional change is required there. Bug #14280. Reported-by: Gordon Good <ggood@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: Avoid the link() syscall.Ethan Jackson2012-11-191-32/+38
| | | | | | | | | | make_pidfile() depends on the link() system call to atomically create pidfiles when multiple daemons are started concurrently. However, this system call isn't available on ESX so an alternative strategy is necessary. Fortunately, the approach this patch takes is cleaner than the original code. Signed-off-by: Ethan Jackson <ethan@nicira.com>
* lib: Move addition of program_name to proctitle_setEd Maste2012-10-111-3/+2
| | | | | Signed-off-by: Ed Maste <emaste@adaranet.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: Factor out code into new function daemonize_post_detach().Ben Pfaff2012-07-181-5/+22
| | | | | | This code will have another user in an upcoming commit. Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: Factor out code into new function fork_and_wait_for_startup().Ben Pfaff2012-07-181-6/+27
| | | | | | This function will be useful in an upcoming commit. Signed-off-by: Ben Pfaff <blp@nicira.com>
* util: Introduce "subprogram_name" to identify subprocesses and threads.Ben Pfaff2012-07-181-6/+3
| | | | | | | | This will be more useful later when we introduces "worker" subprocesses. I don't have any current plans to introduce threading, but I can't think of a disadvantage to wording this in a general manner. Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: Add comment.Ben Pfaff2012-05-141-0/+11
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* Global replace of Nicira Networks.Raju Subramanian2012-05-021-1/+1
| | | | | | | | Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc. Feature #10593 Signed-off-by: Raju Subramanian <rsubramanian@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: New function daemon_save_fd() to preserve fds across detach.Ben Pfaff2012-02-021-6/+30
| | | | | | This eliminates a kluge that was duplicated in three different daemons. Signed-off-by: Ben Pfaff <blp@nicira.com>
* daemon: Better log when fork child dies early from signals.Ben Pfaff2011-11-281-9/+14
| | | | | | | | | | | | | | | On one machine, "/etc/init.d/openvswitch-switch start" failed to start with: ovs-vswitchd: fork child failed to signal startup (Success) Starting ovs-vswitchd ... failed! "strace" revealed that the fork child was actually segfaulting, but the message output didn't indicate that in any way. This commit fixes the log message (but not the segfault itself). Reported-by: Michael Hu <mhu@nicira.com> Bug #8457.
* vlog: Add a new log level "off".Ben Pfaff2011-08-011-1/+1
| | | | | | | Until now, "emer" has effectively been "off" because no messages were ever logged at "emer" level. Justin points out that it is useful to use "emer" for messages that indicate a fatal error. This commit makes that change and adds a new "off" level to really turn off all logging to a facility.
* daemon: Disable logging to console after detaching.Ben Pfaff2011-06-161-0/+3
| | | | | When we detach, we replace stderr by /dev/null, so there's no point in logging to the console after that. Just turn it off.
* daemon: Reduce log level of "pid file is stale" message.Ben Pfaff2011-04-191-1/+1
| | | | | | This message will appear repeatedly when ovs-vswitchd is running, if there is any stale pidfile in /var/run/openvswitch, because ovs-vswitchd reads all of the pidfiles in that directory periodically to update statistics.
* daemon: Avoid races on pidfile creation.Ben Pfaff2011-04-041-99/+158
| | | | | | | | | | | | | | | | | | Until now, if two copies of one OVS daemon started up at the same time, then due to races in pidfile creation it was possible for both of them to start successfully, instead of just one. This was made worse when a previous copy of the daemon had died abruptly, leaving a stale pidfile. This commit implements a new pidfile creation and removal protocol that I believe closes these races. Now, a pidfile is asserted with "link" instead of "rename", which prevents the race on creation, and a stale pidfile may only be deleted by a process after it has taken a lock on it. This may solve mysterious problems seen occasionally on vswitch restart. I'm still puzzled by these problems, however, because I don't see anything in our tests cases that would actually cause two copies of a daemon to start at the same time, which as far as I can see is a necessary precondition for the problem.
* daemon: Integrate checking for an existing pidfile into daemonize_start().Ben Pfaff2011-04-041-4/+5
| | | | | | | | | | | | Until now, it has been the responsibility of an individual daemon to call die_if_already_running() at an appropriate time. A long time ago, this had to happen *before* daemonizing, because once the process daemonized itself there was no way to report failure to the process that originally started the daemon. With the introduction of daemonize_start(), this is now possible, but we haven't been taking advantage of it. Therefore, this commit integrates the die_if_already_running() call into daemonize_start() and deletes the calls to it from individual daemons.
* daemon: Tolerate EINTR in fork_and_wait_for_startup().Ben Pfaff2011-04-041-1/+2
| | | | | It seems possible that a signal coming in at the wrong time could confuse this code. It's always best to loop on EINTR.
* Log anything that could prevent a daemon from starting.Ben Pfaff2011-04-041-7/+6
| | | | | If a daemon doesn't start, we need to know why. Being able to consistently consult the log to find out is helpful.
* daemon: Avoid redundant code in already_running().Ben Pfaff2011-03-291-30/+29
| | | | | This function substantially duplicated read_pidfile(), so reuse that code instead.
* daemon: Write "already running" message to log also.Ben Pfaff2011-03-291-0/+2
| | | | | Otherwise it's hard to diagnose later if the daemon failed to start because it thinks that it is already running.
* daemon: Fix leak of string in make_pidfile().Justin Pettit2011-02-221-1/+1
| | | | Coverity #10724
* ovs-vswitchd: Complete daemonization only after initial configuration.Ben Pfaff2011-02-071-1/+5
| | | | | | | Otherwise when we add support for saving and restoring configuration of internal devices around kernel module unload and reload, there's no easy way for the "restore" code to tell when all the interfaces should be set up and ready for configuration.
* daemon: Suppress valgrind warnings from read_pidfile().Ben Pfaff2011-02-031-1/+2
| | | | | | | The version of valgrind I have in my test VMs doesn't know what F_GETLK does, so it complains that l_pid is uninitialized even though fcntl sets it. Initializing it ourselves before calling the function avoids a series of false-positive warnings about use of uninitialized data.
* Make installation directories overridable at runtime.Ben Pfaff2010-11-291-3/+3
| | | | | | | | | This makes it possible to run tests that need access to installation directories, such as the rundir, without having access to the actual installation directories (/var/run is generally not world-writable), by setting environment variables. This is not a good way to do things in general--usually it would be better to choose the correct directories at configure time--so for now this is undocumented.
* vlog: Make client supply semicolon for VLOG_DEFINE_THIS_MODULE.Ben Pfaff2010-10-291-1/+1
| | | | | It's kind of odd for VLOG_DEFINE_THIS_MODULE to supply its own semicolon, so this commit switches to the more common form.
* daemon: Don't call a normal exit from the monitor a "crash".Ben Pfaff2010-10-271-7/+9
| | | | | | | | | | When the monitored child is killed with SIGTERM, the monitoring process currently logs a message like "1 crashes: pid 12345 died, killed by signal 15 (Terminated), exiting". This counts the SIGTERM as a crash, even though it's intentional. This commit changes the log message to omit the "%d crashes" part on normal termination.
* lib: Remove warnings in daemon.cEthan Jackson2010-10-141-0/+1
| | | | | On some platforms compilation of daemon.c results in implicit declaration of function fstat and stat warnings.
* daemon: Fix behavior of read_pidfile() for our own pidfile.Ben Pfaff2010-09-231-0/+25
| | | | | | | | Opening a file descriptor and then closing it always discards any locks held on the underlying file, even if the file is still open as another file descriptor. This meant that calling read_pidfile() on the process's own pidfile would discard the lock and make other OVS processes think that the process had died. This commit fixes the problem.
* daemon: Report number of crashes on monitor process command line.Ben Pfaff2010-09-231-1/+4
|
* treewide: Remove trailing whitespaceJoe Perches2010-08-301-1/+1
| | | | | | Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Simon Horman <horms@verge.net.au> Signed-off-by: Jesse Gross <jesse@nicira.com>
* daemon: Improve comments.Ben Pfaff2010-08-251-7/+8
| | | | | | | Elsewhere we put the name of command-line options that control global variables in the comment, so do so here as well. Also fix a comment typo.
* daemon: Make sure that vlog is initialized when a process daemonizes.Ben Pfaff2010-08-121-0/+4
| | | | | | | | | | | If a process daemonizes itself, then it should be possible to control that process's log levels with "ovs-appctl vlog/set" and related commands. The vlog_init() function registers those commands. But vlog_init() doesn't normally get called until the first log message is issued. This can take a while, especially for ovs-controller, where I first noticed the problem. This commit fixes the problem by calling vlog_init() from daemonize_start(), which always gets called as a process daemonizes.