+ /* we are either child or didn't vfork at all */
+#ifdef INETD_BUILTINS_ENABLED
+ if (sep->se_builtin) {
+ if (pid) { /* "pid" is -1: we did vfork */
+ close(sep->se_fd); /* listening socket */
+ logmode = LOGMODE_NONE; /* make xwrite etc silent */
+ }
+ restore_sigmask(&omask);
+ if (sep->se_socktype == SOCK_STREAM)
+ sep->se_builtin->bi_stream_fn(ctrl, sep);
+ else
+ sep->se_builtin->bi_dgram_fn(ctrl, sep);
+ if (pid) /* we did vfork */
+ _exit(EXIT_FAILURE);
+ maybe_close(accepted_fd);
+ continue; /* -> check next fd in fd set */
+ }
+#endif
+ /* child */
+ setsid();
+ /* "nowait" udp */
+ if (new_udp_fd >= 0) {
+ len_and_sockaddr *lsa = xzalloc_lsa(sep->se_family);
+ /* peek at the packet and remember peer addr */
+ int r = recvfrom(ctrl, NULL, 0, MSG_PEEK|MSG_DONTWAIT,
+ &lsa->u.sa, &lsa->len);
+ if (r < 0)
+ goto do_exit1;
+ /* make this socket "connected" to peer addr:
+ * only packets from this peer will be recv'ed,
+ * and bare write()/send() will work on it */
+ connect(ctrl, &lsa->u.sa, lsa->len);
+ free(lsa);
+ }
+ /* prepare env and exec program */
+ pwd = getpwnam(sep->se_user);
+ if (pwd == NULL) {
+ bb_error_msg("%s: no such %s", sep->se_user, "user");
+ goto do_exit1;
+ }
+ if (sep->se_group && (grp = getgrnam(sep->se_group)) == NULL) {
+ bb_error_msg("%s: no such %s", sep->se_group, "group");
+ goto do_exit1;
+ }
+ if (real_uid != 0 && real_uid != pwd->pw_uid) {
+ /* a user running private inetd */
+ bb_error_msg("non-root must run services as himself");
+ goto do_exit1;
+ }
+ if (pwd->pw_uid) {
+ if (sep->se_group)
+ pwd->pw_gid = grp->gr_gid;
+ /* initgroups, setgid, setuid: */
+ change_identity(pwd);
+ } else if (sep->se_group) {
+ xsetgid(grp->gr_gid);
+ setgroups(1, &grp->gr_gid);
+ }
+ if (rlim_ofile.rlim_cur != rlim_ofile_cur)
+ if (setrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0)
+ bb_perror_msg("setrlimit");