Mercurial > masqmail
comparison src/masqmail.c @ 421:f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk
we do well to have the lock files there.) Added the new configure option
--with-lockdir to change that location. Nontheless, if we run_as_user,
then lock files are always stored in the spool dir directly.
Instead of installing the lockdir and piddir at installation time, we
create them on startup time now if they are missing. This is necessary
if lockdir or piddir are a tmpfs.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 30 May 2012 09:38:38 +0200 |
parents | d209b4846f2b |
children | a19e47ebbb33 |
comparison
equal
deleted
inserted
replaced
420:09da6e72cd30 | 421:f37384470855 |
---|---|
102 return cp; | 102 return cp; |
103 } | 103 } |
104 return NULL; | 104 return NULL; |
105 } | 105 } |
106 | 106 |
107 /* | |
108 ** Create any missing directory in pathname `dir'. (Like `mkdir -p'.) | |
109 ** The code is taken from nmh. | |
110 */ | |
111 gboolean | |
112 makedir_rec(char *dir, int perms) | |
113 { | |
114 char path[PATH_MAX]; | |
115 char *cp, *c; | |
116 int had_an_error = 0; | |
117 | |
118 c = strncpy(path, dir, sizeof(path)); | |
119 | |
120 while (!had_an_error && (c = strchr(c+1, '/'))) { | |
121 *c = '\0'; | |
122 /* Create an outer directory. */ | |
123 if (mkdir(path, perms) == -1 && errno != EEXIST) { | |
124 fprintf(stderr, "unable to create `%s': %s\n", | |
125 path, strerror(errno)); | |
126 had_an_error = 1; | |
127 } | |
128 *c = '/'; | |
129 } | |
130 | |
131 /* | |
132 ** Create the innermost nested subdirectory of the | |
133 ** path we're being asked to create. | |
134 */ | |
135 if (!had_an_error && mkdir(dir, perms)==-1 && errno != EEXIST) { | |
136 fprintf(stderr, "unable to create `%s': %s\n", | |
137 dir, strerror(errno)); | |
138 had_an_error = 1; | |
139 } | |
140 | |
141 return (had_an_error) ? 0 : 1; | |
142 } | |
143 | |
107 gboolean | 144 gboolean |
108 write_pidfile(gchar *name) | 145 write_pidfile(gchar *name) |
109 { | 146 { |
110 FILE *fptr; | 147 FILE *fptr; |
111 | 148 |
144 exit(1); | 181 exit(1); |
145 } | 182 } |
146 } | 183 } |
147 | 184 |
148 signal(SIGTERM, sigterm_handler); | 185 signal(SIGTERM, sigterm_handler); |
186 makedir_rec(PID_DIR, 0755); | |
149 write_pidfile(PID_DIR "/masqmail.pid"); | 187 write_pidfile(PID_DIR "/masqmail.pid"); |
150 | 188 |
151 conf.do_verbose = FALSE; | 189 conf.do_verbose = FALSE; |
152 | 190 |
153 /* | 191 /* |
653 ** | 691 ** |
654 ** So it is possible for a user to run his own daemon without | 692 ** So it is possible for a user to run his own daemon without |
655 ** breaking security. | 693 ** breaking security. |
656 */ | 694 */ |
657 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { | 695 if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { |
696 logwrite(LOG_NOTICE, "Changing to run_as_user.\n"); | |
658 conf.run_as_user = TRUE; | 697 conf.run_as_user = TRUE; |
659 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); | 698 set_euidgid(conf.orig_uid, conf.orig_gid, NULL, NULL); |
660 if (setgid(conf.orig_gid)) { | 699 if (setgid(conf.orig_gid)) { |
661 logwrite(LOG_ALERT, "could not set gid to %d: %s\n", | 700 logwrite(LOG_ALERT, "could not set gid to %d: %s\n", |
662 conf.orig_gid, strerror(errno)); | 701 conf.orig_gid, strerror(errno)); |
713 strerror(errno)); | 752 strerror(errno)); |
714 exit(1); | 753 exit(1); |
715 } | 754 } |
716 } | 755 } |
717 | 756 |
757 if (conf.run_as_user) { | |
758 logwrite(LOG_NOTICE, "Using spool directory `%s' for " | |
759 "lock files.\n", conf.spool_dir); | |
760 conf.lock_dir = conf.spool_dir; | |
761 } else { | |
762 int olduid, oldgid; | |
763 | |
764 set_euidgid(conf.mail_uid, conf.mail_gid, &olduid, &oldgid); | |
765 makedir_rec(conf.lock_dir, 0775); | |
766 set_euidgid(olduid, oldgid, NULL, NULL); | |
767 } | |
768 | |
718 if (!logopen()) { | 769 if (!logopen()) { |
719 fprintf(stderr, "could not open log file\n"); | 770 fprintf(stderr, "could not open log file\n"); |
720 exit(1); | 771 exit(1); |
721 } | 772 } |
722 | 773 |