diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-05-24 12:45:25 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-05-24 13:50:39 +0300 |
commit | 6dd0ec08db301984b8f8f9082f28006d5915c183 (patch) | |
tree | e916ad37fbd3cbcaf85103667f28e0d47f3c2e45 /src/socket.c | |
parent | 2a646ee7cbbcb6f4bbd8f38bb3c1e1418550f3fc (diff) | |
download | pies-6dd0ec08db301984b8f8f9082f28006d5915c183.tar.gz pies-6dd0ec08db301984b8f8f9082f28006d5915c183.tar.bz2 |
Initial implementation of "startup" components.
These are components that are run at program startup. Starting
other components is delayed until all startup components terminate.
This is similar to SysV "bootwait" components.
Upon termination, startup components are removed from the configuration.
They are not renewed upon configuratuion reload.
* src/comp.c (comp_array_remove): Remove from the depmap as well.
(component_ref_decr): Use comp_array_remove for active components
and plain component_free for inactive ones.
(component_build_depmap): Use comp_array_remove.
(component_config_commit): Special handling for pies_comp_startup
components.
* src/pies.c (modetab): New component modes: "startup" and "shutdown".
(main): Run program_init_startup.
* src/pies.h (pies_comp_mode): New modes: pies_comp_startup and
pies_comp_shutdown.
(program_init_startup): New proto.
* src/progman.c (progman_waiting_p): Return 1 if a startup component
is still running.
(program_init_startup): New function.
(progman_cleanup): Handle pies_comp_startup termination.
* src/socket.c (switch_eids): Avoid unnecessary calls to setegid
and seteuid.
* tests/atlocal.in (auxdir): New variable.
* tests/mailer: Move to tests/aux/
* tests/respawn: Move to tests/aux/
* tests/retcode: Move to tests/aux/
* tests/aux/startup: New auxiliary program.
* tests/redirect.at: Start components from $auxdir.
* tests/respawn.at: Likewise.
* tests/ret-exec.at: Likewise.
* tests/ret-notify.at: Likewise.
* tests/startup.at: New file.
* tests/testsuite.at: Include startup.at
* tests/Makefile.am: Add new tests.
Diffstat (limited to 'src/socket.c')
-rw-r--r-- | src/socket.c | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/socket.c b/src/socket.c index aa01543..40c7aa7 100644 --- a/src/socket.c +++ b/src/socket.c @@ -25,9 +25,12 @@ switch_eids (uid_t *puid, gid_t *pgid, mode_t *pumask) mode_t omask = umask (*pumask); - - if (setegid (*pgid)) - logmsg (LOG_ERR, _("cannot switch to EGID %lu: %s"), - (unsigned long) *pgid, strerror (errno)); - if (seteuid (*puid)) - logmsg (LOG_ERR, _("cannot switch to EUID %lu: %s"), - (unsigned long) *puid, strerror (errno)); + + if ((*puid && *puid != ouid) || (*pgid && *pgid != ogid)) + { + if (setegid (*pgid)) + logmsg (LOG_ERR, _("cannot switch to EGID %lu: %s"), + (unsigned long) *pgid, strerror (errno)); + if (seteuid (*puid)) + logmsg (LOG_ERR, _("cannot switch to EUID %lu: %s"), + (unsigned long) *puid, strerror (errno)); + } *puid = ouid; @@ -53,3 +56,3 @@ create_socket (struct pies_url *url, int socket_type, int switch_back; - + if (strcmp (url->scheme, "unix") == 0 @@ -60,3 +63,3 @@ create_socket (struct pies_url *url, int socket_type, const char *group = NULL; - + user = url->user; @@ -101,3 +104,3 @@ create_socket (struct pies_url *url, int socket_type, } - + if (user) @@ -113,3 +116,3 @@ create_socket (struct pies_url *url, int socket_type, } - + if (group) @@ -124,3 +127,3 @@ create_socket (struct pies_url *url, int socket_type, } - + if (strlen (url->path) > sizeof addr.s_un.sun_path) @@ -161,3 +164,3 @@ create_socket (struct pies_url *url, int socket_type, short port = url->port; - + uid = 0; @@ -168,3 +171,3 @@ create_socket (struct pies_url *url, int socket_type, socklen = sizeof (addr.s_in); - + if (!host) @@ -187,3 +190,3 @@ create_socket (struct pies_url *url, int socket_type, break; - + default: @@ -200,3 +203,3 @@ create_socket (struct pies_url *url, int socket_type, } - + fd = socket (addr.sa.sa_family, socket_type, url->proto); @@ -252,3 +255,3 @@ pass_fd0 (int fd, int payload) # endif /* ! CMSG_SPACE */ - + char control[CMSG_SPACE (sizeof (int))]; @@ -292,3 +295,3 @@ pass_fd (const char *socket_name, int fd, unsigned maxtime) struct sockaddr_un addr; - + if (strlen (socket_name) > sizeof addr.sun_path) @@ -300,3 +303,3 @@ pass_fd (const char *socket_name, int fd, unsigned maxtime) strcpy (addr.sun_path, socket_name); - + for (;;) @@ -364,3 +367,3 @@ pass_fd (const char *socket_name, int fd, unsigned maxtime) struct timeval tv; - + FD_ZERO (&fds); @@ -432,3 +435,3 @@ calc_fd_max (void) void * -register_socket (int fd, +register_socket (int fd, socket_handler_t rd, @@ -456,3 +459,3 @@ register_socket (int fd, } - + si_tail = sip; @@ -495,3 +498,3 @@ delete_sockinst (struct sockinst *sp) fd_max = -1; - + if (sp->prev) @@ -574,3 +577,3 @@ pies_pause (void) return; - + if (fd_max == -1) @@ -583,3 +586,3 @@ pies_pause (void) fd_set exset = fdset[PIES_EVT_EX]; - + int rc = select (fd_max + 1, &rdset, &wrset, &exset, NULL); @@ -639,2 +642 @@ pies_pause (void) } - |