2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-28 12:58:00 +00:00

16 Commits

Author SHA1 Message Date
Ben Pfaff
44074babd0 daemon-unix: With --monitor, only close standard fds if --detach also used.
Daemons generally should close the standard fds because they don't want to
hold open an SSH session, etc. that is attached to a tty.  But --monitor
without --detach does not daemonize, so do not close fds in that case.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
2017-10-06 20:52:24 -07:00
Ben Pfaff
71f21279f6 Eliminate most shadowing for local variable names.
Shadowing is when a variable with a given name in an inner scope hides a
different variable with the same name in a surrounding scope.  This is
generally undesirable because it can confuse programmers.  This commit
eliminates most of it.

Found with -Wshadow=local in GCC 7.  The repo is not really ready to enable
this option by default because of a few cases that are harder to fix, and
harmless, such as nested use of CMAP_FOR_EACH.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
2017-08-02 15:03:35 -07:00
Huanle Han
8ee4583645 vlog: reopen log file in monitor process
ovs daemon process will reopen file after every log rotate.
However, it doesn't happen to monitor process. That is to say,
fd of log file in monitor proces always point to oldest disk file,
which is deleted after log rotate. Once daemon process restarts
from a crash, it inherits parent's fds, including the deleted log file.

This commit reopens log file in monitor process everytime it
wakes up from waitpid.

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-08-02 11:42:54 -07:00
Christian Ehrhardt
eaf2aa9e23 daemon-unix: Properly handle missing users or groups.
From the manpages of getgrnam_r (getpwnam_r is similar):
"If no matching group record was found, these functions return 0 and
store NULL in *result."

The code checked only against errors, but non existing users didn't set
e != 0 therefore the code could try to set arbitrary uid/gid values.

Fixes: e91b927d lib/daemon: support --user option for all OVS daemon
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-05-16 14:11:03 -07:00
YAMAMOTO Takashi
6a54bae196 daemon_switch_user: Improve portablility
NetBSD doesn't have [gs]etres[ug]id.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2015-11-26 18:37:05 +09:00
Andy Zhou
de929213d1 vlog: Only compile vlog_change_owner on Unix platform
uid_t and gid_t are not defined for Windows platform.

Signed-off-by: Andy Zhou <azhou@nicira.com>
2015-11-11 18:54:10 -08:00
Andy Zhou
3de44dd188 vlog: change log file owner when switching user
vlog log file can be created when parsing --log-file option, before
switching user, in case the --user option is also specified. While this
does not directly cause errors for the running daemons, it can
leave the log files on the disk as created under the "root" user.
This patch fix the log file ownership to the user specified with --user.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ansis Atteka <aatteka@nicira.com>
2015-11-11 18:05:54 -08:00
Andy Zhou
6069edb0ea lib: simplify daemon_become_new_user__()
A global variable 'switch_user' was used to make sure
we switch process's current user only once. This logic is now
simplified by testing for uid directly; if switch process has
taken place, the current uid will be not be zero.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ansis Atteka <aatteka@nicira.com>
2015-11-11 18:05:44 -08:00
Russell Bryant
6e6271d2f5 Fix build when HAVE_LIBCAPNG is not defined.
The function daemon_become_new_user_linux was conditionally defined but
then used in code unconditionally.  If HAVE_LIBCAPNG is not defined, the
function would never be called, but it still must exist.

Adjust the #if guard around the function to be around the body of the
function instead of outside of its definition to ensure the function is
always defined, even if empty.

This issue was introduced in e91b927d8966bfcb9768225392324dde4fd7d7f6.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2015-10-01 08:48:50 -07:00
Andy Zhou
e91b927d89 lib/daemon: support --user option for all OVS daemon
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>
2015-09-30 20:43:46 -07:00
Russell Bryant
5f38375100 command-line: add ovs_cmdl_ prefix
The coding style guidelines include the following:

  - Pick a unique name prefix (ending with an underscore) for each
    module, and apply that prefix to all of that module's externally
    visible names.  Names of macro parameters, struct and union members,
    and parameters in function prototypes are not considered externally
    visible for this purpose.

This patch adds the new prefix to the externally visible names.  This
makes it a bit more obvious what code is coming from common command
line handling code.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2015-03-16 13:42:52 -07:00
Thomas Graf
e6211adce4 lib: Move vlog.h to <openvswitch/vlog.h>
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>
2014-12-15 14:15:19 +01:00
Ansis Atteka
b925336a36 daemon: restart child process if it died before signaling its readiness
The child process (the one being monitored) could die before it was able
to call fork_notify_startup() function.  If such situation arises, then
parent process (the one monitoring child process) would also terminate
with a fatal log message:

...|EMER|fork child died before signaling startup (killed (...))

This patch changes that behavior by always restarting child process
if it was able to start up at least once in the past.  However, if
child was not able to start up even once, then the monitor process
would still terminate, because that would most likely indicate a
persistent programming or system error.

To reproduce use following script:

while : ; do kill -SIGSEGV `cat /var/run/openvswitch/ovs-vswitchd.pid`; done

Signed-Off-By: Ansis Atteka <aatteka@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
VMware-BZ: 1273550
2014-07-10 10:29:45 -07:00
Gurucharan Shetty
3834bcf2bf daemon: Move some common code to daemon.c
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>
2014-04-24 14:43:50 -07:00
Gurucharan Shetty
d6bc33f37a daemon: Close standard file descriptors after detach for windows.
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>
2014-04-24 14:43:37 -07:00
Gurucharan Shetty
a91dc4447b daemon: Rename daemon.c as daemon-unix.c
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>
2014-04-24 14:42:46 -07:00