- if (pidfd >= 0)
- ftruncate(pidfd, 0);
-}
-
-static void drop_privs(void)
-{
- struct stat st;
-
- if (stat(SM_DIR, &st) == -1 &&
- stat(DIR_BASE, &st) == -1) {
- st.st_uid = 0;
- st.st_gid = 0;
- }
-
- if (st.st_uid == 0) {
- note(N_WARNING, "statd running as root. chown %s to choose different user\n",
- SM_DIR);
- return;
- }
- /* better chown the pid file before dropping, as if it
- * if over nfs we might loose access
- */
- if (pidfd >= 0)
- fchown(pidfd, st.st_uid, st.st_gid);
-
- setgroups(0, NULL);
- if (setgid(st.st_gid) == -1
- || setuid(st.st_uid) == -1) {
- note(N_ERROR, "Fail to drop privileges");
- exit(1);
+ if (pidfd >= 0) {
+ if (ftruncate(pidfd, 0) < 0) {
+ xlog_warn("truncating pid file failed: errno %d (%m)\n",
+ errno);
+ }