summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 53f8e80..bc96fb5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,3 +1,27 @@
+/* $Id$ */
+
+/***
+ This file is part of ivam2.
+
+ ivam2 is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ ivam2 is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ivam2; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <signal.h>
#include <assert.h>
#include <string.h>
@@ -5,6 +29,7 @@
#include <grp.h>
#include <pwd.h>
#include <sys/types.h>
+#include <stdlib.h>
#include <libdaemon/dlog.h>
#include <libdaemon/dfork.h>
@@ -23,7 +48,7 @@ const char *appname = NULL;
uid_t target_uid = 0;
gid_t target_gid = 0;
-#define DEFAULT_MSNTABLE "../conf/msntab"
+#define DEFAULT_MSNTABLE PKGSYSCONFDIR"/msntab"
#define IVAM_USER "ivam"
#define IVAM_GROUP "ivam"
@@ -51,6 +76,8 @@ static void *oop_dump_cb(oop_source *source, int sig, void *user) {
static int change_uid_gid(void) {
+ struct passwd *pw;
+
if (args.no_drop_root_flag)
return 0;
@@ -69,6 +96,16 @@ static int change_uid_gid(void) {
return -1;
}
+ if ((pw = getpwuid(target_uid))) {
+ setenv("USER", pw->pw_name, 1);
+ setenv("LOGNAME", pw->pw_name, 1);
+ setenv("HOME", pw->pw_dir, 1);
+ } else {
+ unsetenv("USER");
+ unsetenv("LOGNAME");
+ unsetenv("HOME");
+ }
+
daemon_log(LOG_INFO, "Successfully dropped root privileges.");
return 0;
@@ -110,6 +147,8 @@ int main_loop(void) {
if (get_target_uid_gid() < 0)
goto finish;
+
+ setenv("PATH", BINDIR":/usr/sbin:/usr/bin:/sbin:/bin/:/usr/local/sbin:/usr/local/bin", 1);
if (!(sys = oop_sys_new())) {
daemon_log(LOG_ERR, "Failed to create system source.");
@@ -193,11 +232,20 @@ int main(int argc, char*argv[]) {
int ret;
if ((ret = daemon_pid_file_kill_wait(SIGINT, 5)) < 0)
- daemon_log(LOG_WARNING, "Failed to kill daemon.");
+ daemon_log(LOG_WARNING, "Failed to kill daemon: %s", strerror(errno));
return ret < 0 ? 1 : 0;
}
+ if (args.reload_flag || args.info_flag) {
+ int ret;
+
+ if ((ret = daemon_pid_file_kill(args.reload_flag ? SIGHUP : SIGUSR1)) < 0)
+ daemon_log(LOG_WARNING, "Failed to kill daemon: %s", strerror(errno));
+
+ return ret < 0 ? 1 : 0;
+ }
+
if (args.check_flag) {
if ((pid = daemon_pid_file_is_running()) >= 0)
daemon_log(LOG_INFO, "Daemon running on PID %u.", pid);