-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) {
- xlog_warn("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) {
- if (fchown(pidfd, st.st_uid, st.st_gid) < 0) {
- xlog(L_ERROR, "Unable to change owner of %s: %d (%s)",
- SM_DIR, strerror (errno));
- }
- }
- setgroups(0, NULL);
- if (setgid(st.st_gid) == -1
- || setuid(st.st_uid) == -1) {
- xlog(L_ERROR, "Fail to drop privileges");
- exit(1);
- }
-}
-